diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow/gapic_version.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow/gapic_version.py index 2d5ed6f35b7a..360a0d13ebdd 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow/gapic_version.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.27.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/gapic_version.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/gapic_version.py index 2d5ed6f35b7a..360a0d13ebdd 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/gapic_version.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.27.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/async_client.py index fa6d17ba28d7..6b872782b735 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -64,8 +64,12 @@ class AgentsAsyncClient: _client: AgentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = AgentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AgentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = AgentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = AgentsClient._DEFAULT_UNIVERSE agent_path = staticmethod(AgentsClient.agent_path) parse_agent_path = staticmethod(AgentsClient.parse_agent_path) @@ -162,6 +166,25 @@ def transport(self) -> AgentsTransport: """ 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(AgentsClient).get_transport_class, type(AgentsClient) ) @@ -174,7 +197,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the agents client. + """Instantiates the agents async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -185,23 +208,38 @@ def __init__( transport (Union[str, ~.AgentsTransport]): 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. @@ -313,6 +351,9 @@ async def sample_get_agent(): 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, @@ -434,6 +475,9 @@ async def sample_set_agent(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -527,6 +571,9 @@ async def sample_delete_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. await rpc( request, @@ -636,6 +683,9 @@ async def sample_search_agents(): 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, @@ -775,6 +825,9 @@ async def sample_train_agent(): 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, @@ -902,6 +955,9 @@ async def sample_export_agent(): 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, @@ -1033,6 +1089,9 @@ async def sample_import_agent(): 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, @@ -1162,6 +1221,9 @@ async def sample_restore_agent(): 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, @@ -1252,6 +1314,9 @@ async def sample_get_validation_result(): 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, @@ -1306,6 +1371,9 @@ async def list_operations( 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, @@ -1360,6 +1428,9 @@ async def get_operation( 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, @@ -1417,6 +1488,9 @@ async def cancel_operation( 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, @@ -1468,6 +1542,9 @@ async def get_location( 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, @@ -1522,6 +1599,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/client.py index bdab0f9ec9e4..321b5a712989 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -132,11 +133,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -280,7 +285,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 @@ -310,6 +315,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") @@ -343,6 +353,175 @@ 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 + + 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 + + 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 = AgentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = AgentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = AgentsClient._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 = AgentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = AgentsClient._DEFAULT_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 AgentsClient._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, *, @@ -362,22 +541,32 @@ def __init__( transport (Union[str, AgentsTransport]): 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. @@ -388,17 +577,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, + ) = AgentsClient._read_environment_variables() + self._client_cert_source = AgentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = AgentsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -407,20 +613,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, AgentsTransport): + transport_provided = isinstance(transport, AgentsTransport) + if transport_provided: # transport is a AgentsTransport 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(AgentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or AgentsClient._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( @@ -430,17 +646,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 get_agent( @@ -543,6 +759,9 @@ def sample_get_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -664,6 +883,9 @@ def sample_set_agent(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -757,6 +979,9 @@ def sample_delete_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -866,6 +1091,9 @@ def sample_search_agents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1005,6 +1233,9 @@ def sample_train_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1132,6 +1363,9 @@ def sample_export_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1264,6 +1498,9 @@ def sample_import_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1394,6 +1631,9 @@ def sample_restore_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1485,6 +1725,9 @@ def sample_get_validation_result(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1552,6 +1795,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1606,6 +1852,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1663,6 +1912,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1714,6 +1966,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1768,6 +2023,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py index 49342ddf03d7..89148293234d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/base.py @@ -64,7 +64,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -127,6 +127,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-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py index 8242d2b7955b..b97ac06e9b51 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py index d0612ab639b5..ab0a00386011 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/rest.py index c871ec25b41d..ccca56cf7619 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/agents/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -478,7 +478,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py index c54da1b27146..47a47e033c37 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -62,8 +62,12 @@ class AnswerRecordsAsyncClient: _client: AnswerRecordsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = AnswerRecordsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = AnswerRecordsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = AnswerRecordsClient._DEFAULT_UNIVERSE answer_record_path = staticmethod(AnswerRecordsClient.answer_record_path) parse_answer_record_path = staticmethod( @@ -176,6 +180,25 @@ def transport(self) -> AnswerRecordsTransport: """ 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(AnswerRecordsClient).get_transport_class, type(AnswerRecordsClient) ) @@ -188,7 +211,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the answer records client. + """Instantiates the answer records async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -199,23 +222,38 @@ def __init__( transport (Union[str, ~.AnswerRecordsTransport]): 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. @@ -324,6 +362,9 @@ async def sample_list_answer_records(): 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, @@ -478,6 +519,9 @@ async def sample_update_answer_record(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -532,6 +576,9 @@ async def list_operations( 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, @@ -586,6 +633,9 @@ async def get_operation( 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, @@ -643,6 +693,9 @@ async def cancel_operation( 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, @@ -694,6 +747,9 @@ async def get_location( 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, @@ -748,6 +804,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py index 8adeab5dc5e8..422f14a83a2c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -130,11 +131,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -321,7 +326,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 @@ -351,6 +356,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") @@ -384,6 +394,175 @@ 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 + + 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 + + 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 = AnswerRecordsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = AnswerRecordsClient._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 = AnswerRecordsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = AnswerRecordsClient._DEFAULT_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 AnswerRecordsClient._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, *, @@ -403,22 +582,32 @@ def __init__( transport (Union[str, AnswerRecordsTransport]): 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. @@ -429,17 +618,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, + ) = AnswerRecordsClient._read_environment_variables() + self._client_cert_source = AnswerRecordsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = AnswerRecordsClient._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" @@ -448,20 +654,33 @@ 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, AnswerRecordsTransport): + transport_provided = isinstance(transport, AnswerRecordsTransport) + if transport_provided: # transport is a AnswerRecordsTransport 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(AnswerRecordsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or AnswerRecordsClient._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( @@ -471,17 +690,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_answer_records( @@ -581,6 +800,9 @@ def sample_list_answer_records(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -735,6 +957,9 @@ def sample_update_answer_record(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -802,6 +1027,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -856,6 +1084,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -913,6 +1144,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -964,6 +1198,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1018,6 +1255,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py index 567375ca8929..6090a3875d11 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py index 8bce13e2ebe7..2145de133ba2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py index c856bb7b7a27..7d00d344fc60 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/rest.py index 083fdc447b92..8723454607f7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/answer_records/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -289,7 +289,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/contexts/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/async_client.py index 2b0be2cca7fa..e3fa98dd5494 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -61,8 +61,12 @@ class ContextsAsyncClient: _client: ContextsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ContextsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ContextsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ContextsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ContextsClient._DEFAULT_UNIVERSE context_path = staticmethod(ContextsClient.context_path) parse_context_path = staticmethod(ContextsClient.parse_context_path) @@ -161,6 +165,25 @@ def transport(self) -> ContextsTransport: """ 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(ContextsClient).get_transport_class, type(ContextsClient) ) @@ -173,7 +196,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the contexts client. + """Instantiates the contexts async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -184,23 +207,38 @@ def __init__( transport (Union[str, ~.ContextsTransport]): 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. @@ -312,6 +350,9 @@ async def sample_list_contexts(): 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, @@ -445,6 +486,9 @@ async def sample_get_context(): 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, @@ -583,6 +627,9 @@ async def sample_create_context(): 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, @@ -715,6 +762,9 @@ async def sample_update_context(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -813,6 +863,9 @@ async def sample_delete_context(): 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, @@ -908,6 +961,9 @@ async def sample_delete_all_contexts(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. await rpc( request, @@ -959,6 +1015,9 @@ async def list_operations( 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, @@ -1013,6 +1072,9 @@ async def get_operation( 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, @@ -1070,6 +1132,9 @@ async def cancel_operation( 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, @@ -1121,6 +1186,9 @@ async def get_location( 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, @@ -1175,6 +1243,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/client.py index 9bf9639178bb..309dd6309322 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -129,11 +130,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -284,7 +289,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 @@ -314,6 +319,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") @@ -347,6 +357,175 @@ 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 + + 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 + + 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 = ContextsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ContextsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ContextsClient._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 = ContextsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ContextsClient._DEFAULT_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 ContextsClient._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, *, @@ -366,22 +545,32 @@ def __init__( transport (Union[str, ContextsTransport]): 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. @@ -392,17 +581,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, + ) = ContextsClient._read_environment_variables() + self._client_cert_source = ContextsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ContextsClient._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" @@ -411,20 +617,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, ContextsTransport): + transport_provided = isinstance(transport, ContextsTransport) + if transport_provided: # transport is a ContextsTransport 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(ContextsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or ContextsClient._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( @@ -434,17 +650,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_contexts( @@ -547,6 +763,9 @@ def sample_list_contexts(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -680,6 +899,9 @@ def sample_get_context(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -818,6 +1040,9 @@ def sample_create_context(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -950,6 +1175,9 @@ def sample_update_context(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1048,6 +1276,9 @@ def sample_delete_context(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1143,6 +1374,9 @@ def sample_delete_all_contexts(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1207,6 +1441,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1261,6 +1498,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1318,6 +1558,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1369,6 +1612,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1423,6 +1669,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py index eb271db4add7..514df8d7c62f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py index 0eafc427f0fa..aabb18b3e162 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py index 66076a7b1f89..ab235ce12c46 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/rest.py index f98172a29f1f..9f22f7a28f4c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/contexts/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -371,7 +371,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/async_client.py index 91f3a41b2549..aedd61efb86b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -69,8 +69,12 @@ class ConversationDatasetsAsyncClient: _client: ConversationDatasetsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ConversationDatasetsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationDatasetsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ConversationDatasetsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ConversationDatasetsClient._DEFAULT_UNIVERSE conversation_dataset_path = staticmethod( ConversationDatasetsClient.conversation_dataset_path @@ -181,6 +185,25 @@ def transport(self) -> ConversationDatasetsTransport: """ 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(ConversationDatasetsClient).get_transport_class, type(ConversationDatasetsClient), @@ -194,7 +217,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the conversation datasets client. + """Instantiates the conversation datasets async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -205,23 +228,38 @@ def __init__( transport (Union[str, ~.ConversationDatasetsTransport]): 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. @@ -362,6 +400,9 @@ async def sample_create_conversation_dataset(): 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, @@ -479,6 +520,9 @@ async def sample_get_conversation_dataset(): 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, @@ -589,6 +633,9 @@ async def sample_list_conversation_datasets(): 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, @@ -726,6 +773,9 @@ async def sample_delete_conversation_dataset(): 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, @@ -839,6 +889,9 @@ async def sample_import_conversation_data(): 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, @@ -901,6 +954,9 @@ async def list_operations( 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, @@ -955,6 +1011,9 @@ async def get_operation( 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, @@ -1012,6 +1071,9 @@ async def cancel_operation( 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, @@ -1063,6 +1125,9 @@ async def get_location( 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, @@ -1117,6 +1182,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/client.py index b2ff04e84bc8..cd04599684bb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -139,11 +140,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -294,7 +299,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 @@ -324,6 +329,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") @@ -357,6 +367,175 @@ 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 + + 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 + + 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 = ConversationDatasetsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ConversationDatasetsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ConversationDatasetsClient._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 = ConversationDatasetsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ConversationDatasetsClient._DEFAULT_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 ConversationDatasetsClient._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, *, @@ -376,22 +555,32 @@ def __init__( transport (Union[str, ConversationDatasetsTransport]): 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. @@ -402,17 +591,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, + ) = ConversationDatasetsClient._read_environment_variables() + self._client_cert_source = ConversationDatasetsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ConversationDatasetsClient._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" @@ -421,20 +627,33 @@ 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, ConversationDatasetsTransport): + transport_provided = isinstance(transport, ConversationDatasetsTransport) + if transport_provided: # transport is a ConversationDatasetsTransport 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(ConversationDatasetsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or ConversationDatasetsClient._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( @@ -444,17 +663,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 create_conversation_dataset( @@ -590,6 +809,9 @@ def sample_create_conversation_dataset(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -707,6 +929,9 @@ def sample_get_conversation_dataset(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -821,6 +1046,9 @@ def sample_list_conversation_datasets(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -962,6 +1190,9 @@ def sample_delete_conversation_dataset(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1076,6 +1307,9 @@ def sample_import_conversation_data(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1151,6 +1385,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1205,6 +1442,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1262,6 +1502,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1313,6 +1556,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1367,6 +1613,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/base.py index fa85157a1d68..4ab065836b50 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/base.py @@ -64,7 +64,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -127,6 +127,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-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc.py index 176c0c790abb..53c77108202f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc.py @@ -71,7 +71,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc_asyncio.py index 6999104a9cb5..0b1c44008d21 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/grpc_asyncio.py @@ -116,7 +116,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/rest.py index a9705e2b9840..00f933838df5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_datasets/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -403,7 +403,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/async_client.py index a09c770b82dc..2995eda5713d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -65,8 +65,12 @@ class ConversationModelsAsyncClient: _client: ConversationModelsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ConversationModelsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationModelsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ConversationModelsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ConversationModelsClient._DEFAULT_UNIVERSE conversation_dataset_path = staticmethod( ConversationModelsClient.conversation_dataset_path @@ -191,6 +195,25 @@ def transport(self) -> ConversationModelsTransport: """ 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(ConversationModelsClient).get_transport_class, type(ConversationModelsClient), @@ -204,7 +227,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the conversation models client. + """Instantiates the conversation models async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -215,23 +238,38 @@ def __init__( transport (Union[str, ~.ConversationModelsTransport]): 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. @@ -367,6 +405,9 @@ async def sample_create_conversation_model(): 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, @@ -477,6 +518,9 @@ async def sample_get_conversation_model(): 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, @@ -585,6 +629,9 @@ async def sample_list_conversation_models(): 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, @@ -722,6 +769,9 @@ async def sample_delete_conversation_model(): 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, @@ -839,6 +889,9 @@ async def sample_deploy_conversation_model(): 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, @@ -957,6 +1010,9 @@ async def sample_undeploy_conversation_model(): 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, @@ -1070,6 +1126,9 @@ async def sample_get_conversation_model_evaluation(): 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, @@ -1178,6 +1237,9 @@ async def sample_list_conversation_model_evaluations(): 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, @@ -1310,6 +1372,9 @@ async def sample_create_conversation_model_evaluation(): 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, @@ -1372,6 +1437,9 @@ async def list_operations( 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, @@ -1426,6 +1494,9 @@ async def get_operation( 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, @@ -1483,6 +1554,9 @@ async def cancel_operation( 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, @@ -1534,6 +1608,9 @@ async def get_location( 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, @@ -1588,6 +1665,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/client.py index 7fbdffb42c35..4d8e09740d56 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -135,11 +136,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -356,7 +361,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 @@ -386,6 +391,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") @@ -419,6 +429,175 @@ 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 + + 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 + + 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 = ConversationModelsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ConversationModelsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ConversationModelsClient._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 = ConversationModelsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ConversationModelsClient._DEFAULT_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 ConversationModelsClient._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, *, @@ -438,22 +617,32 @@ def __init__( transport (Union[str, ConversationModelsTransport]): 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. @@ -464,17 +653,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, + ) = ConversationModelsClient._read_environment_variables() + self._client_cert_source = ConversationModelsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ConversationModelsClient._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" @@ -483,20 +689,33 @@ 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, ConversationModelsTransport): + transport_provided = isinstance(transport, ConversationModelsTransport) + if transport_provided: # transport is a ConversationModelsTransport 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(ConversationModelsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or ConversationModelsClient._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( @@ -506,17 +725,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 create_conversation_model( @@ -647,6 +866,9 @@ def sample_create_conversation_model(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -757,6 +979,9 @@ def sample_get_conversation_model(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -865,6 +1090,9 @@ def sample_list_conversation_models(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1004,6 +1232,9 @@ def sample_delete_conversation_model(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1124,6 +1355,9 @@ def sample_deploy_conversation_model(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1245,6 +1479,9 @@ def sample_undeploy_conversation_model(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1362,6 +1599,9 @@ def sample_get_conversation_model_evaluation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1476,6 +1716,9 @@ def sample_list_conversation_model_evaluations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1614,6 +1857,9 @@ def sample_create_conversation_model_evaluation(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1689,6 +1935,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1743,6 +1992,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1800,6 +2052,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1851,6 +2106,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1905,6 +2163,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/base.py index 8abcfc359a26..7c69a27fcaa3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/base.py @@ -64,7 +64,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -127,6 +127,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-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc.py index b041f03d03c4..7bac36ca4ae5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc_asyncio.py index 282be69d00c0..d2630060aa44 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/rest.py index 9a452a84b056..6cff76473733 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_models/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -534,7 +534,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py index 7d9b37180325..520932e6d008 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -69,8 +69,12 @@ class ConversationProfilesAsyncClient: _client: ConversationProfilesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ConversationProfilesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ConversationProfilesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ConversationProfilesClient._DEFAULT_UNIVERSE agent_path = staticmethod(ConversationProfilesClient.agent_path) parse_agent_path = staticmethod(ConversationProfilesClient.parse_agent_path) @@ -201,6 +205,25 @@ def transport(self) -> ConversationProfilesTransport: """ 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(ConversationProfilesClient).get_transport_class, type(ConversationProfilesClient), @@ -214,7 +237,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the conversation profiles client. + """Instantiates the conversation profiles async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -225,23 +248,38 @@ def __init__( transport (Union[str, ~.ConversationProfilesTransport]): 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. @@ -352,6 +390,9 @@ async def sample_list_conversation_profiles(): 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, @@ -466,6 +507,9 @@ async def sample_get_conversation_profile(): 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, @@ -593,6 +637,9 @@ async def sample_create_conversation_profile(): 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, @@ -720,6 +767,9 @@ async def sample_update_conversation_profile(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -819,6 +869,9 @@ async def sample_delete_conversation_profile(): 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, @@ -976,6 +1029,9 @@ async def sample_set_suggestion_feature_config(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1137,6 +1193,9 @@ async def sample_clear_suggestion_feature_config(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1199,6 +1258,9 @@ async def list_operations( 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, @@ -1253,6 +1315,9 @@ async def get_operation( 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, @@ -1310,6 +1375,9 @@ async def cancel_operation( 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, @@ -1361,6 +1429,9 @@ async def get_location( 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, @@ -1415,6 +1486,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/client.py index dd07bd0ebaca..e67b273d2713 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -139,11 +140,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -392,7 +397,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 @@ -422,6 +427,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") @@ -455,6 +465,175 @@ 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 + + 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 + + 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 = ConversationProfilesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ConversationProfilesClient._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 = ConversationProfilesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ConversationProfilesClient._DEFAULT_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 ConversationProfilesClient._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, *, @@ -474,22 +653,32 @@ def __init__( transport (Union[str, ConversationProfilesTransport]): 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. @@ -500,17 +689,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = ConversationProfilesClient._read_environment_variables() + self._client_cert_source = ConversationProfilesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ConversationProfilesClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -519,20 +725,33 @@ 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, ConversationProfilesTransport): + transport_provided = isinstance(transport, ConversationProfilesTransport) + if transport_provided: # transport is a ConversationProfilesTransport 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(ConversationProfilesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or ConversationProfilesClient._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( @@ -542,17 +761,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_conversation_profiles( @@ -658,6 +877,9 @@ def sample_list_conversation_profiles(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -772,6 +994,9 @@ def sample_get_conversation_profile(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -903,6 +1128,9 @@ def sample_create_conversation_profile(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1034,6 +1262,9 @@ def sample_update_conversation_profile(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1137,6 +1368,9 @@ def sample_delete_conversation_profile(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1300,6 +1534,9 @@ def sample_set_suggestion_feature_config(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1467,6 +1704,9 @@ def sample_clear_suggestion_feature_config(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1542,6 +1782,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1596,6 +1839,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1653,6 +1899,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1704,6 +1953,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1758,6 +2010,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py index 35edda8539b0..d071f96801d1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/base.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -128,6 +128,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-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py index 447c51cf273b..8cbb81b410af 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc.py @@ -70,7 +70,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py index 2248ad9dc6fb..6de2056cddf7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/grpc_asyncio.py @@ -115,7 +115,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/rest.py index 1801219da16f..f699b29418da 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversation_profiles/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -456,7 +456,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py index 2c6128ebf063..d93cd4734156 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -63,8 +63,12 @@ class ConversationsAsyncClient: _client: ConversationsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ConversationsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ConversationsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ConversationsClient._DEFAULT_UNIVERSE agent_path = staticmethod(ConversationsClient.agent_path) parse_agent_path = staticmethod(ConversationsClient.parse_agent_path) @@ -201,6 +205,25 @@ def transport(self) -> ConversationsTransport: """ 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(ConversationsClient).get_transport_class, type(ConversationsClient) ) @@ -213,7 +236,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the conversations client. + """Instantiates the conversations async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -224,23 +247,38 @@ def __init__( transport (Union[str, ~.ConversationsTransport]): 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. @@ -383,6 +421,9 @@ async def sample_create_conversation(): 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, @@ -491,6 +532,9 @@ async def sample_list_conversations(): 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, @@ -607,6 +651,9 @@ async def sample_get_conversation(): 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, @@ -717,6 +764,9 @@ async def sample_complete_conversation(): 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, @@ -828,6 +878,9 @@ async def sample_list_messages(): 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, @@ -946,6 +999,9 @@ async def sample_suggest_conversation_summary(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1044,6 +1100,9 @@ async def sample_generate_stateless_summary(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1130,6 +1189,9 @@ async def sample_search_knowledge(): 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, @@ -1184,6 +1246,9 @@ async def list_operations( 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, @@ -1238,6 +1303,9 @@ async def get_operation( 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, @@ -1295,6 +1363,9 @@ async def cancel_operation( 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, @@ -1346,6 +1417,9 @@ async def get_location( 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, @@ -1400,6 +1474,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py index 9129a02a69c4..9a95a7f56b53 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -131,11 +132,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -446,7 +451,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 @@ -476,6 +481,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") @@ -509,6 +519,175 @@ 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 + + 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 + + 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 = ConversationsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ConversationsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ConversationsClient._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 = ConversationsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ConversationsClient._DEFAULT_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 ConversationsClient._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, *, @@ -528,22 +707,32 @@ def __init__( transport (Union[str, ConversationsTransport]): 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. @@ -554,17 +743,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, + ) = ConversationsClient._read_environment_variables() + self._client_cert_source = ConversationsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = ConversationsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -573,20 +779,33 @@ 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, ConversationsTransport): + transport_provided = isinstance(transport, ConversationsTransport) + if transport_provided: # transport is a ConversationsTransport 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(ConversationsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or ConversationsClient._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( @@ -596,17 +815,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 create_conversation( @@ -740,6 +959,9 @@ def sample_create_conversation(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -848,6 +1070,9 @@ def sample_list_conversations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -964,6 +1189,9 @@ def sample_get_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1074,6 +1302,9 @@ def sample_complete_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1185,6 +1416,9 @@ def sample_list_messages(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1305,6 +1539,9 @@ def sample_suggest_conversation_summary(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1406,6 +1643,9 @@ def sample_generate_stateless_summary(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1493,6 +1733,9 @@ def sample_search_knowledge(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1560,6 +1803,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1614,6 +1860,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1671,6 +1920,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1722,6 +1974,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1776,6 +2031,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py index d56dfa3842fe..5628e62c9e95 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py index 55e3d76b727b..94a108bab11c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py index a6be82fd6b66..ac0d3427df8a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/rest.py index 98d636adc965..a073edcfd161 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/conversations/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -477,7 +477,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/documents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/async_client.py index 789afbf77824..851bdaeff0cf 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -65,8 +65,12 @@ class DocumentsAsyncClient: _client: DocumentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DocumentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DocumentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DocumentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DocumentsClient._DEFAULT_UNIVERSE document_path = staticmethod(DocumentsClient.document_path) parse_document_path = staticmethod(DocumentsClient.parse_document_path) @@ -167,6 +171,25 @@ def transport(self) -> DocumentsTransport: """ 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(DocumentsClient).get_transport_class, type(DocumentsClient) ) @@ -179,7 +202,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the documents client. + """Instantiates the documents async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -190,23 +213,38 @@ def __init__( transport (Union[str, ~.DocumentsTransport]): 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. @@ -315,6 +353,9 @@ async def sample_list_documents(): 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, @@ -433,6 +474,9 @@ async def sample_get_document(): 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, @@ -573,6 +617,9 @@ async def sample_create_document(): 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, @@ -688,6 +735,9 @@ async def sample_import_documents(): 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, @@ -822,6 +872,9 @@ async def sample_delete_document(): 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, @@ -971,6 +1024,9 @@ async def sample_update_document(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1124,6 +1180,9 @@ async def sample_reload_document(): 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, @@ -1235,6 +1294,9 @@ async def sample_export_document(): 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, @@ -1297,6 +1359,9 @@ async def list_operations( 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, @@ -1351,6 +1416,9 @@ async def get_operation( 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, @@ -1408,6 +1476,9 @@ async def cancel_operation( 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, @@ -1459,6 +1530,9 @@ async def get_location( 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, @@ -1513,6 +1587,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/client.py index 032dc42ab570..ee550fa407e2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -133,11 +134,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -288,7 +293,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 @@ -318,6 +323,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") @@ -351,6 +361,175 @@ 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 + + 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 + + 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 = DocumentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DocumentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DocumentsClient._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 = DocumentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DocumentsClient._DEFAULT_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 DocumentsClient._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, *, @@ -370,22 +549,32 @@ def __init__( transport (Union[str, DocumentsTransport]): 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. @@ -396,17 +585,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = DocumentsClient._read_environment_variables() + self._client_cert_source = DocumentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = DocumentsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -415,20 +621,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, DocumentsTransport): + transport_provided = isinstance(transport, DocumentsTransport) + if transport_provided: # transport is a DocumentsTransport 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(DocumentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or DocumentsClient._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( @@ -438,17 +654,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_documents( @@ -548,6 +764,9 @@ def sample_list_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -666,6 +885,9 @@ def sample_get_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -806,6 +1028,9 @@ def sample_create_document(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -922,6 +1147,9 @@ def sample_import_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1056,6 +1284,9 @@ def sample_delete_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1205,6 +1436,9 @@ def sample_update_document(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1358,6 +1592,9 @@ def sample_reload_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1470,6 +1707,9 @@ def sample_export_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1545,6 +1785,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1599,6 +1842,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1656,6 +1902,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1707,6 +1956,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1761,6 +2013,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py index 51a5efda5c63..2b2b37d07c48 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py index 5c76d4ca8b8f..289cf0bf3204 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py index 3683ca94a721..e5cb8bc272da 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/rest.py index b1af105e3d5d..88cd1eefadee 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/documents/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -477,7 +477,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/entity_types/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/async_client.py index 56918d1fc1ba..11a14cb5a23a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -65,8 +65,12 @@ class EntityTypesAsyncClient: _client: EntityTypesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EntityTypesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EntityTypesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = EntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = EntityTypesClient._DEFAULT_UNIVERSE entity_type_path = staticmethod(EntityTypesClient.entity_type_path) parse_entity_type_path = staticmethod(EntityTypesClient.parse_entity_type_path) @@ -169,6 +173,25 @@ def transport(self) -> EntityTypesTransport: """ 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(EntityTypesClient).get_transport_class, type(EntityTypesClient) ) @@ -181,7 +204,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the entity types client. + """Instantiates the entity types async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -192,23 +215,38 @@ def __init__( transport (Union[str, ~.EntityTypesTransport]): 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. @@ -329,6 +367,9 @@ async def sample_list_entity_types(): 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, @@ -466,6 +507,9 @@ async def sample_get_entity_type(): 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, @@ -611,6 +655,9 @@ async def sample_create_entity_type(): 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, @@ -747,6 +794,9 @@ async def sample_update_entity_type(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -844,6 +894,9 @@ async def sample_delete_entity_type(): 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, @@ -944,6 +997,9 @@ async def sample_batch_update_entity_types(): 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, @@ -1095,6 +1151,9 @@ async def sample_batch_delete_entity_types(): 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, @@ -1260,6 +1319,9 @@ async def sample_batch_create_entities(): 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, @@ -1429,6 +1491,9 @@ async def sample_batch_update_entities(): 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, @@ -1593,6 +1658,9 @@ async def sample_batch_delete_entities(): 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, @@ -1655,6 +1723,9 @@ async def list_operations( 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, @@ -1709,6 +1780,9 @@ async def get_operation( 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, @@ -1766,6 +1840,9 @@ async def cancel_operation( 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, @@ -1817,6 +1894,9 @@ async def get_location( 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, @@ -1871,6 +1951,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/client.py index 95cdd9bdfd37..8d1891f0ca9e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -133,11 +134,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -285,7 +290,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 @@ -315,6 +320,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") @@ -348,6 +358,175 @@ 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 + + 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 + + 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 = EntityTypesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EntityTypesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = EntityTypesClient._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 = EntityTypesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = EntityTypesClient._DEFAULT_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 EntityTypesClient._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, *, @@ -367,22 +546,32 @@ def __init__( transport (Union[str, EntityTypesTransport]): 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. @@ -393,17 +582,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, + ) = EntityTypesClient._read_environment_variables() + self._client_cert_source = EntityTypesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = EntityTypesClient._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" @@ -412,20 +618,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, EntityTypesTransport): + transport_provided = isinstance(transport, EntityTypesTransport) + if transport_provided: # transport is a EntityTypesTransport 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(EntityTypesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or EntityTypesClient._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( @@ -435,17 +651,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_entity_types( @@ -557,6 +773,9 @@ def sample_list_entity_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -694,6 +913,9 @@ def sample_get_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -839,6 +1061,9 @@ def sample_create_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -975,6 +1200,9 @@ def sample_update_entity_type(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1072,6 +1300,9 @@ def sample_delete_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1175,6 +1406,9 @@ def sample_batch_update_entity_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1328,6 +1562,9 @@ def sample_batch_delete_entity_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1493,6 +1730,9 @@ def sample_batch_create_entities(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1662,6 +1902,9 @@ def sample_batch_update_entities(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1826,6 +2069,9 @@ def sample_batch_delete_entities(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1901,6 +2147,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1955,6 +2204,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2012,6 +2264,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -2063,6 +2318,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2117,6 +2375,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py index 0210cc690820..132c12cfdd58 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py index 077d0542864a..97956245118b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py index 16af7fb06a4d..c4f9c23a39d8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/rest.py index ff3e814f44b9..0dfd93ef4399 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/entity_types/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -529,7 +529,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/environments/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/async_client.py index a68eb6e7d18d..a2e1faabb480 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -61,8 +61,12 @@ class EnvironmentsAsyncClient: _client: EnvironmentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EnvironmentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = EnvironmentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = EnvironmentsClient._DEFAULT_UNIVERSE environment_path = staticmethod(EnvironmentsClient.environment_path) parse_environment_path = staticmethod(EnvironmentsClient.parse_environment_path) @@ -169,6 +173,25 @@ def transport(self) -> EnvironmentsTransport: """ 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(EnvironmentsClient).get_transport_class, type(EnvironmentsClient) ) @@ -181,7 +204,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the environments client. + """Instantiates the environments async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -192,23 +215,38 @@ def __init__( transport (Union[str, ~.EnvironmentsTransport]): 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. @@ -319,6 +357,9 @@ async def sample_list_environments(): 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, @@ -427,6 +468,9 @@ async def sample_get_environment(): 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, @@ -527,6 +571,9 @@ async def sample_create_environment(): 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, @@ -640,6 +687,9 @@ async def sample_update_environment(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -711,6 +761,9 @@ async def sample_delete_environment(): 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, @@ -792,6 +845,9 @@ async def sample_get_environment_history(): 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, @@ -855,6 +911,9 @@ async def list_operations( 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, @@ -909,6 +968,9 @@ async def get_operation( 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, @@ -966,6 +1028,9 @@ async def cancel_operation( 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, @@ -1017,6 +1082,9 @@ async def get_location( 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, @@ -1071,6 +1139,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/client.py index 839546cc18bf..84888bc0144a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -129,11 +130,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -315,7 +320,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 @@ -345,6 +350,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") @@ -378,6 +388,175 @@ 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 + + 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 + + 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 = EnvironmentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = EnvironmentsClient._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 = EnvironmentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = EnvironmentsClient._DEFAULT_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 EnvironmentsClient._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, *, @@ -397,22 +576,32 @@ def __init__( transport (Union[str, EnvironmentsTransport]): 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. @@ -423,17 +612,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, + ) = EnvironmentsClient._read_environment_variables() + self._client_cert_source = EnvironmentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = EnvironmentsClient._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" @@ -442,20 +648,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, EnvironmentsTransport): + transport_provided = isinstance(transport, EnvironmentsTransport) + if transport_provided: # transport is a EnvironmentsTransport 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(EnvironmentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or EnvironmentsClient._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( @@ -465,17 +681,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_environments( @@ -577,6 +793,9 @@ def sample_list_environments(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -686,6 +905,9 @@ def sample_get_environment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -787,6 +1009,9 @@ def sample_create_environment(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -901,6 +1126,9 @@ def sample_update_environment(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -973,6 +1201,9 @@ def sample_delete_environment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1055,6 +1286,9 @@ def sample_get_environment_history(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1131,6 +1365,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1185,6 +1422,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1242,6 +1482,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1293,6 +1536,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1347,6 +1593,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py index a7b6c46b8e5e..ab74829c2cd9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py index 867439daf1c0..ea50df43ca64 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py index 12544a4e1a39..85ef4d879af9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/rest.py index feca27da6618..10452bcec2a3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/environments/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -398,7 +398,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/async_client.py index 0367d130163d..7c8d3100d281 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -61,8 +61,12 @@ class FulfillmentsAsyncClient: _client: FulfillmentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = FulfillmentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = FulfillmentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = FulfillmentsClient._DEFAULT_UNIVERSE fulfillment_path = staticmethod(FulfillmentsClient.fulfillment_path) parse_fulfillment_path = staticmethod(FulfillmentsClient.parse_fulfillment_path) @@ -165,6 +169,25 @@ def transport(self) -> FulfillmentsTransport: """ 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(FulfillmentsClient).get_transport_class, type(FulfillmentsClient) ) @@ -177,7 +200,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the fulfillments client. + """Instantiates the fulfillments async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -188,23 +211,38 @@ def __init__( transport (Union[str, ~.FulfillmentsTransport]): 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. @@ -317,6 +355,9 @@ async def sample_get_fulfillment(): 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, @@ -444,6 +485,9 @@ async def sample_update_fulfillment(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -498,6 +542,9 @@ async def list_operations( 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, @@ -552,6 +599,9 @@ async def get_operation( 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, @@ -609,6 +659,9 @@ async def cancel_operation( 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, @@ -660,6 +713,9 @@ async def get_location( 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, @@ -714,6 +770,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/client.py index 1fdfe8249e35..42a155bcf37e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -129,11 +130,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -277,7 +282,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 @@ -307,6 +312,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") @@ -340,6 +350,175 @@ 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 + + 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 + + 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 = FulfillmentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = FulfillmentsClient._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 = FulfillmentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = FulfillmentsClient._DEFAULT_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 FulfillmentsClient._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, *, @@ -359,22 +538,32 @@ def __init__( transport (Union[str, FulfillmentsTransport]): 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. @@ -385,17 +574,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, + ) = FulfillmentsClient._read_environment_variables() + self._client_cert_source = FulfillmentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = FulfillmentsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -404,20 +610,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, FulfillmentsTransport): + transport_provided = isinstance(transport, FulfillmentsTransport) + if transport_provided: # transport is a FulfillmentsTransport 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(FulfillmentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or FulfillmentsClient._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( @@ -427,17 +643,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 get_fulfillment( @@ -541,6 +757,9 @@ def sample_get_fulfillment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -668,6 +887,9 @@ def sample_update_fulfillment(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -735,6 +957,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -789,6 +1014,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -846,6 +1074,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -897,6 +1128,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -951,6 +1185,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py index 782a4941f3a3..650c7561755c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc.py index 0fa0b191b4cc..93a46bcf5dc9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py index d529b171a458..86c93417f8cb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/rest.py index 36e43561436f..c2cdd664ce8f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/fulfillments/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -289,7 +289,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/intents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/async_client.py index 8310aa378c64..09cd122fbc7c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -65,8 +65,12 @@ class IntentsAsyncClient: _client: IntentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = IntentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = IntentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = IntentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = IntentsClient._DEFAULT_UNIVERSE context_path = staticmethod(IntentsClient.context_path) parse_context_path = staticmethod(IntentsClient.parse_context_path) @@ -167,6 +171,25 @@ def transport(self) -> IntentsTransport: """ 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(IntentsClient).get_transport_class, type(IntentsClient) ) @@ -179,7 +202,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the intents client. + """Instantiates the intents async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -190,23 +213,38 @@ def __init__( transport (Union[str, ~.IntentsTransport]): 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. @@ -336,6 +374,9 @@ async def sample_list_intents(): 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, @@ -469,6 +510,9 @@ async def sample_get_intent(): 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, @@ -609,6 +653,9 @@ async def sample_create_intent(): 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, @@ -750,6 +797,9 @@ async def sample_update_intent(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -850,6 +900,9 @@ async def sample_delete_intent(): 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, @@ -993,6 +1046,9 @@ async def sample_batch_update_intents(): 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, @@ -1145,6 +1201,9 @@ async def sample_batch_delete_intents(): 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, @@ -1207,6 +1266,9 @@ async def list_operations( 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, @@ -1261,6 +1323,9 @@ async def get_operation( 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, @@ -1318,6 +1383,9 @@ async def cancel_operation( 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, @@ -1369,6 +1437,9 @@ async def get_location( 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, @@ -1423,6 +1494,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/client.py index 907719f2d53e..9c24bc07da46 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -133,11 +134,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -305,7 +310,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 @@ -335,6 +340,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") @@ -368,6 +378,175 @@ 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 + + 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 + + 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 = IntentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = IntentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = IntentsClient._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 = IntentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = IntentsClient._DEFAULT_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 IntentsClient._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, *, @@ -387,22 +566,32 @@ def __init__( transport (Union[str, IntentsTransport]): 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. @@ -413,17 +602,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = IntentsClient._read_environment_variables() + self._client_cert_source = IntentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = IntentsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -432,20 +638,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, IntentsTransport): + transport_provided = isinstance(transport, IntentsTransport) + if transport_provided: # transport is a IntentsTransport 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(IntentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or IntentsClient._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( @@ -455,17 +671,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_intents( @@ -586,6 +802,9 @@ def sample_list_intents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -719,6 +938,9 @@ def sample_get_intent(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -859,6 +1081,9 @@ def sample_create_intent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1000,6 +1225,9 @@ def sample_update_intent(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1100,6 +1328,9 @@ def sample_delete_intent(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1243,6 +1474,9 @@ def sample_batch_update_intents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1395,6 +1629,9 @@ def sample_batch_delete_intents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1470,6 +1707,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1524,6 +1764,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1581,6 +1824,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1632,6 +1878,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1686,6 +1935,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py index ddcc683fff57..8643b9e0ecb4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py index f015a2382078..560a4d61b316 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py index 61821291d1d1..4db9e42ba95f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/rest.py index 7dc907c5d3b4..dd78b6fe46a7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/intents/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -423,7 +423,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py index a23973117d22..6708c9ac9315 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -62,8 +62,12 @@ class KnowledgeBasesAsyncClient: _client: KnowledgeBasesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = KnowledgeBasesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = KnowledgeBasesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = KnowledgeBasesClient._DEFAULT_UNIVERSE knowledge_base_path = staticmethod(KnowledgeBasesClient.knowledge_base_path) parse_knowledge_base_path = staticmethod( @@ -172,6 +176,25 @@ def transport(self) -> KnowledgeBasesTransport: """ 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(KnowledgeBasesClient).get_transport_class, type(KnowledgeBasesClient) ) @@ -184,7 +207,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the knowledge bases client. + """Instantiates the knowledge bases async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -195,23 +218,38 @@ def __init__( transport (Union[str, ~.KnowledgeBasesTransport]): 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. @@ -320,6 +358,9 @@ async def sample_list_knowledge_bases(): 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, @@ -442,6 +483,9 @@ async def sample_get_knowledge_base(): 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, @@ -571,6 +615,9 @@ async def sample_create_knowledge_base(): 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, @@ -667,6 +714,9 @@ async def sample_delete_knowledge_base(): 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, @@ -794,6 +844,9 @@ async def sample_update_knowledge_base(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -848,6 +901,9 @@ async def list_operations( 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, @@ -902,6 +958,9 @@ async def get_operation( 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, @@ -959,6 +1018,9 @@ async def cancel_operation( 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, @@ -1010,6 +1072,9 @@ async def get_location( 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, @@ -1064,6 +1129,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/client.py index 93f680106d16..399fb9b7d0f7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -132,11 +133,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -284,7 +289,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 @@ -314,6 +319,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") @@ -347,6 +357,175 @@ 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 + + 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 + + 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 = KnowledgeBasesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = KnowledgeBasesClient._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 = KnowledgeBasesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = KnowledgeBasesClient._DEFAULT_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 KnowledgeBasesClient._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, *, @@ -366,22 +545,32 @@ def __init__( transport (Union[str, KnowledgeBasesTransport]): 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. @@ -392,17 +581,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, + ) = KnowledgeBasesClient._read_environment_variables() + self._client_cert_source = KnowledgeBasesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = KnowledgeBasesClient._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" @@ -411,20 +617,33 @@ 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, KnowledgeBasesTransport): + transport_provided = isinstance(transport, KnowledgeBasesTransport) + if transport_provided: # transport is a KnowledgeBasesTransport 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(KnowledgeBasesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or KnowledgeBasesClient._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( @@ -434,17 +653,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_knowledge_bases( @@ -544,6 +763,9 @@ def sample_list_knowledge_bases(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -666,6 +888,9 @@ def sample_get_knowledge_base(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -795,6 +1020,9 @@ def sample_create_knowledge_base(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -891,6 +1119,9 @@ def sample_delete_knowledge_base(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1018,6 +1249,9 @@ def sample_update_knowledge_base(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1085,6 +1319,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1139,6 +1376,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1196,6 +1436,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1247,6 +1490,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1301,6 +1547,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py index ddd6eb0e89db..3acc57f9f4f8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py index f451bfea4b03..f116c50b2397 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py index e62ec2e9d154..6af91c6a9273 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/rest.py index faac0f14f853..24b35c71a1a9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/knowledge_bases/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -372,7 +372,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py index 6fc1e3f78511..f8d377e5a1bf 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/async_client.py @@ -41,9 +41,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -66,8 +66,12 @@ class ParticipantsAsyncClient: _client: ParticipantsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ParticipantsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ParticipantsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ParticipantsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ParticipantsClient._DEFAULT_UNIVERSE answer_record_path = staticmethod(ParticipantsClient.answer_record_path) parse_answer_record_path = staticmethod(ParticipantsClient.parse_answer_record_path) @@ -182,6 +186,25 @@ def transport(self) -> ParticipantsTransport: """ 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(ParticipantsClient).get_transport_class, type(ParticipantsClient) ) @@ -194,7 +217,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the participants client. + """Instantiates the participants async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -205,23 +228,38 @@ def __init__( transport (Union[str, ~.ParticipantsTransport]): 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. @@ -333,6 +371,9 @@ async def sample_create_participant(): 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, @@ -435,6 +476,9 @@ async def sample_get_participant(): 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, @@ -543,6 +587,9 @@ async def sample_list_participants(): 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, @@ -663,6 +710,9 @@ async def sample_update_participant(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -805,6 +855,9 @@ async def sample_analyze_content(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -974,6 +1027,9 @@ def request_generator(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = rpc( requests, @@ -1078,6 +1134,9 @@ async def sample_suggest_articles(): 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, @@ -1182,6 +1241,9 @@ async def sample_suggest_faq_answers(): 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, @@ -1286,6 +1348,9 @@ async def sample_suggest_smart_replies(): 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, @@ -1340,6 +1405,9 @@ async def list_operations( 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, @@ -1394,6 +1462,9 @@ async def get_operation( 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, @@ -1451,6 +1522,9 @@ async def cancel_operation( 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, @@ -1502,6 +1576,9 @@ async def get_location( 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, @@ -1556,6 +1633,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py index 3f0a2c3dd903..4f3f2f3d90f7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/client.py @@ -30,6 +30,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -44,9 +45,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -133,11 +134,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -392,7 +397,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 @@ -422,6 +427,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") @@ -455,6 +465,175 @@ 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 + + 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 + + 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 = ParticipantsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ParticipantsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ParticipantsClient._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 = ParticipantsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ParticipantsClient._DEFAULT_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 ParticipantsClient._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, *, @@ -474,22 +653,32 @@ def __init__( transport (Union[str, ParticipantsTransport]): 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. @@ -500,17 +689,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, + ) = ParticipantsClient._read_environment_variables() + self._client_cert_source = ParticipantsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = ParticipantsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -519,20 +725,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, ParticipantsTransport): + transport_provided = isinstance(transport, ParticipantsTransport) + if transport_provided: # transport is a ParticipantsTransport 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(ParticipantsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or ParticipantsClient._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( @@ -542,17 +758,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 create_participant( @@ -655,6 +871,9 @@ def sample_create_participant(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -757,6 +976,9 @@ def sample_get_participant(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -865,6 +1087,9 @@ def sample_list_participants(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -985,6 +1210,9 @@ def sample_update_participant(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1118,6 +1346,9 @@ def sample_analyze_content(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1283,6 +1514,9 @@ def request_generator(): self._transport.streaming_analyze_content ] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( requests, @@ -1387,6 +1621,9 @@ def sample_suggest_articles(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1491,6 +1728,9 @@ def sample_suggest_faq_answers(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1595,6 +1835,9 @@ def sample_suggest_smart_replies(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1662,6 +1905,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1716,6 +1962,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1773,6 +2022,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1824,6 +2076,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1878,6 +2133,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py index a6b89d35079c..42ccf28c40ec 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py index fa0cc34d3eb4..2306649cba8f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py index db4b3f19e32c..6f795fa1012d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/rest.py index 963e4aaab851..39de7e357a09 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/participants/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -475,7 +475,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py index e8259c917829..e001202c4481 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -65,8 +65,12 @@ class SessionEntityTypesAsyncClient: _client: SessionEntityTypesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SessionEntityTypesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SessionEntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SessionEntityTypesClient._DEFAULT_UNIVERSE session_entity_type_path = staticmethod( SessionEntityTypesClient.session_entity_type_path @@ -177,6 +181,25 @@ def transport(self) -> SessionEntityTypesTransport: """ 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(SessionEntityTypesClient).get_transport_class, type(SessionEntityTypesClient), @@ -190,7 +213,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the session entity types client. + """Instantiates the session entity types async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -201,23 +224,38 @@ def __init__( transport (Union[str, ~.SessionEntityTypesTransport]): 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. @@ -335,6 +373,9 @@ async def sample_list_session_entity_types(): 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, @@ -465,6 +506,9 @@ async def sample_get_session_entity_type(): 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, @@ -606,6 +650,9 @@ async def sample_create_session_entity_type(): 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, @@ -740,6 +787,9 @@ async def sample_update_session_entity_type(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -844,6 +894,9 @@ async def sample_delete_session_entity_type(): 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, @@ -895,6 +948,9 @@ async def list_operations( 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, @@ -949,6 +1005,9 @@ async def get_operation( 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, @@ -1006,6 +1065,9 @@ async def cancel_operation( 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, @@ -1057,6 +1119,9 @@ async def get_location( 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, @@ -1111,6 +1176,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/client.py index 4ebe16f719c5..648f4a261801 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -135,11 +136,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -290,7 +295,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 @@ -320,6 +325,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") @@ -353,6 +363,175 @@ 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 + + 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 + + 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 = SessionEntityTypesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SessionEntityTypesClient._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 = SessionEntityTypesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SessionEntityTypesClient._DEFAULT_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 SessionEntityTypesClient._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, *, @@ -372,22 +551,32 @@ def __init__( transport (Union[str, SessionEntityTypesTransport]): 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. @@ -398,17 +587,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, + ) = SessionEntityTypesClient._read_environment_variables() + self._client_cert_source = SessionEntityTypesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = SessionEntityTypesClient._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" @@ -417,20 +623,33 @@ 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, SessionEntityTypesTransport): + transport_provided = isinstance(transport, SessionEntityTypesTransport) + if transport_provided: # transport is a SessionEntityTypesTransport 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(SessionEntityTypesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SessionEntityTypesClient._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( @@ -440,17 +659,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_session_entity_types( @@ -561,6 +780,9 @@ def sample_list_session_entity_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -691,6 +913,9 @@ def sample_get_session_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -836,6 +1061,9 @@ def sample_create_session_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -974,6 +1202,9 @@ def sample_update_session_entity_type(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1080,6 +1311,9 @@ def sample_delete_session_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1144,6 +1378,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1198,6 +1435,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1255,6 +1495,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1306,6 +1549,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1360,6 +1606,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py index e760b0a282a9..068fb5146268 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/base.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -128,6 +128,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-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py index f1135db55d3a..f8cd9eed33d1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc.py @@ -70,7 +70,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py index 1721f5437117..f173821bae8e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/grpc_asyncio.py @@ -115,7 +115,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/rest.py index 07f43dfce349..0f37f9696609 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/session_entity_types/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -382,7 +382,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py index b784a840deb2..8acd075187a2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/async_client.py @@ -41,9 +41,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -67,8 +67,12 @@ class SessionsAsyncClient: _client: SessionsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SessionsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SessionsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SessionsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SessionsClient._DEFAULT_UNIVERSE context_path = staticmethod(SessionsClient.context_path) parse_context_path = staticmethod(SessionsClient.parse_context_path) @@ -175,6 +179,25 @@ def transport(self) -> SessionsTransport: """ 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(SessionsClient).get_transport_class, type(SessionsClient) ) @@ -187,7 +210,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the sessions client. + """Instantiates the sessions async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -198,23 +221,38 @@ def __init__( transport (Union[str, ~.SessionsTransport]): 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. @@ -384,6 +422,9 @@ async def sample_detect_intent(): gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -538,6 +579,9 @@ def request_generator(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = rpc( requests, @@ -592,6 +636,9 @@ async def list_operations( 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, @@ -646,6 +693,9 @@ async def get_operation( 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, @@ -703,6 +753,9 @@ async def cancel_operation( 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, @@ -754,6 +807,9 @@ async def get_location( 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, @@ -808,6 +864,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/client.py index e41e30dceb88..c32679272531 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/client.py @@ -30,6 +30,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -44,9 +45,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -134,11 +135,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -347,7 +352,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 @@ -377,6 +382,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") @@ -410,6 +420,175 @@ 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 + + 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 + + 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 = SessionsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SessionsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SessionsClient._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 = SessionsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SessionsClient._DEFAULT_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 SessionsClient._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, *, @@ -429,22 +608,32 @@ def __init__( transport (Union[str, SessionsTransport]): 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. @@ -455,17 +644,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, + ) = SessionsClient._read_environment_variables() + self._client_cert_source = SessionsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = SessionsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -474,20 +680,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, SessionsTransport): + transport_provided = isinstance(transport, SessionsTransport) + if transport_provided: # transport is a SessionsTransport 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(SessionsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or SessionsClient._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( @@ -497,17 +713,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 detect_intent( @@ -659,6 +875,9 @@ def sample_detect_intent(): gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -809,6 +1028,9 @@ def request_generator(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.streaming_detect_intent] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( requests, @@ -876,6 +1098,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -930,6 +1155,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -987,6 +1215,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1038,6 +1269,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1092,6 +1326,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py index c6e2886ac0d5..2c5167d67171 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py index e4ef6e016034..24710e0ce0b6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc.py @@ -69,7 +69,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py index fff30c835cd7..d81f44bdde7c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/grpc_asyncio.py @@ -114,7 +114,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/rest.py index 15cc81729c21..99c81991cc59 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/sessions/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -260,7 +260,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/versions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/async_client.py index 4ce78f1ae96c..3a624dca7b6b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -61,8 +61,12 @@ class VersionsAsyncClient: _client: VersionsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = VersionsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = VersionsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = VersionsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = VersionsClient._DEFAULT_UNIVERSE version_path = staticmethod(VersionsClient.version_path) parse_version_path = staticmethod(VersionsClient.parse_version_path) @@ -161,6 +165,25 @@ def transport(self) -> VersionsTransport: """ 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(VersionsClient).get_transport_class, type(VersionsClient) ) @@ -173,7 +196,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the versions client. + """Instantiates the versions async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -184,23 +207,38 @@ def __init__( transport (Union[str, ~.VersionsTransport]): 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. @@ -311,6 +349,9 @@ async def sample_list_versions(): 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, @@ -443,6 +484,9 @@ async def sample_get_version(): 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, @@ -578,6 +622,9 @@ async def sample_create_version(): 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, @@ -717,6 +764,9 @@ async def sample_update_version(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -813,6 +863,9 @@ async def sample_delete_version(): 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, @@ -864,6 +917,9 @@ async def list_operations( 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, @@ -918,6 +974,9 @@ async def get_operation( 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, @@ -975,6 +1034,9 @@ async def cancel_operation( 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, @@ -1026,6 +1088,9 @@ async def get_location( 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, @@ -1080,6 +1145,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/client.py index 205f90a3b5f4..ede5558dbad1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -129,11 +130,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -281,7 +286,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 @@ -311,6 +316,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") @@ -344,6 +354,175 @@ 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 + + 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 + + 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 = VersionsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = VersionsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = VersionsClient._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 = VersionsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = VersionsClient._DEFAULT_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 VersionsClient._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, *, @@ -363,22 +542,32 @@ def __init__( transport (Union[str, VersionsTransport]): 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. @@ -389,17 +578,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, + ) = VersionsClient._read_environment_variables() + self._client_cert_source = VersionsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = VersionsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -408,20 +614,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, VersionsTransport): + transport_provided = isinstance(transport, VersionsTransport) + if transport_provided: # transport is a VersionsTransport 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(VersionsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or VersionsClient._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( @@ -431,17 +647,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_versions( @@ -543,6 +759,9 @@ def sample_list_versions(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -675,6 +894,9 @@ def sample_get_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -810,6 +1032,9 @@ def sample_create_version(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -949,6 +1174,9 @@ def sample_update_version(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1045,6 +1273,9 @@ def sample_delete_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1109,6 +1340,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1163,6 +1397,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1220,6 +1457,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1271,6 +1511,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1325,6 +1568,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/base.py index 8bd950bdf9b6..4929b8b65178 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc.py index b246e4b7ac09..2e23d5ae7d77 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py index e61f7a334a1e..32fa7a712fa3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/rest.py index 0be9e6e02f27..1a26d6b54d1a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2/services/versions/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -355,7 +355,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/gapic_version.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/gapic_version.py index 2d5ed6f35b7a..360a0d13ebdd 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/gapic_version.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.27.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/async_client.py index ae9311b221fe..8119a082e156 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -66,8 +66,12 @@ class AgentsAsyncClient: _client: AgentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = AgentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AgentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = AgentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = AgentsClient._DEFAULT_UNIVERSE agent_path = staticmethod(AgentsClient.agent_path) parse_agent_path = staticmethod(AgentsClient.parse_agent_path) @@ -164,6 +168,25 @@ def transport(self) -> AgentsTransport: """ 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(AgentsClient).get_transport_class, type(AgentsClient) ) @@ -176,7 +199,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the agents client. + """Instantiates the agents async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -187,23 +210,38 @@ def __init__( transport (Union[str, ~.AgentsTransport]): 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. @@ -316,6 +354,9 @@ async def sample_get_agent(): 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, @@ -434,6 +475,9 @@ async def sample_set_agent(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -528,6 +572,9 @@ async def sample_delete_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. await rpc( request, @@ -637,6 +684,9 @@ async def sample_search_agents(): 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, @@ -777,6 +827,9 @@ async def sample_train_agent(): 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, @@ -904,6 +957,9 @@ async def sample_export_agent(): 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, @@ -1036,6 +1092,9 @@ async def sample_import_agent(): 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, @@ -1166,6 +1225,9 @@ async def sample_restore_agent(): 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, @@ -1256,6 +1318,9 @@ async def sample_get_validation_result(): 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, @@ -1310,6 +1375,9 @@ async def list_operations( 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, @@ -1364,6 +1432,9 @@ async def get_operation( 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, @@ -1421,6 +1492,9 @@ async def cancel_operation( 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, @@ -1472,6 +1546,9 @@ async def get_location( 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, @@ -1526,6 +1603,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/client.py index b4aa6831b012..84116a88fbd0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -134,11 +135,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -282,7 +287,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 @@ -312,6 +317,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") @@ -345,6 +355,175 @@ 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 + + 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 + + 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 = AgentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = AgentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = AgentsClient._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 = AgentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = AgentsClient._DEFAULT_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 AgentsClient._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, *, @@ -364,22 +543,32 @@ def __init__( transport (Union[str, AgentsTransport]): 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. @@ -390,17 +579,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, + ) = AgentsClient._read_environment_variables() + self._client_cert_source = AgentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = AgentsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -409,20 +615,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, AgentsTransport): + transport_provided = isinstance(transport, AgentsTransport) + if transport_provided: # transport is a AgentsTransport 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(AgentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or AgentsClient._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( @@ -432,17 +648,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 get_agent( @@ -546,6 +762,9 @@ def sample_get_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -664,6 +883,9 @@ def sample_set_agent(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -758,6 +980,9 @@ def sample_delete_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -867,6 +1092,9 @@ def sample_search_agents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1007,6 +1235,9 @@ def sample_train_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1134,6 +1365,9 @@ def sample_export_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1267,6 +1501,9 @@ def sample_import_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1398,6 +1635,9 @@ def sample_restore_agent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1489,6 +1729,9 @@ def sample_get_validation_result(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1556,6 +1799,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1610,6 +1856,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1667,6 +1916,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1718,6 +1970,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1772,6 +2027,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py index d13c53f6707e..2d9f3b2d0f87 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/base.py @@ -64,7 +64,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -127,6 +127,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-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py index a4e67b704221..a3f30579728f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc.py @@ -69,7 +69,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py index 41f143cbcd8c..d2aeae28b3b4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/grpc_asyncio.py @@ -114,7 +114,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/rest.py index 598c7232332c..c9a4bef5b524 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/agents/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -479,7 +479,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py index 4b95d73f40aa..5635021b6a1e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/async_client.py @@ -39,9 +39,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -63,8 +63,12 @@ class AnswerRecordsAsyncClient: _client: AnswerRecordsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = AnswerRecordsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = AnswerRecordsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = AnswerRecordsClient._DEFAULT_UNIVERSE answer_record_path = staticmethod(AnswerRecordsClient.answer_record_path) parse_answer_record_path = staticmethod( @@ -179,6 +183,25 @@ def transport(self) -> AnswerRecordsTransport: """ 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(AnswerRecordsClient).get_transport_class, type(AnswerRecordsClient) ) @@ -191,7 +214,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the answer records client. + """Instantiates the answer records async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -202,23 +225,38 @@ def __init__( transport (Union[str, ~.AnswerRecordsTransport]): 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. @@ -336,6 +374,9 @@ async def sample_get_answer_record(): 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, @@ -443,6 +484,9 @@ async def sample_list_answer_records(): 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, @@ -597,6 +641,9 @@ async def sample_update_answer_record(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -651,6 +698,9 @@ async def list_operations( 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, @@ -705,6 +755,9 @@ async def get_operation( 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, @@ -762,6 +815,9 @@ async def cancel_operation( 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, @@ -813,6 +869,9 @@ async def get_location( 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, @@ -867,6 +926,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py index beba4a1e8d60..e905023874f2 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/client.py @@ -43,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -131,11 +131,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -344,7 +348,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 @@ -374,6 +378,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") @@ -407,6 +416,175 @@ 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 + + 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 + + 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 = AnswerRecordsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = AnswerRecordsClient._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 = AnswerRecordsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = AnswerRecordsClient._DEFAULT_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 AnswerRecordsClient._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, *, @@ -426,22 +604,32 @@ def __init__( transport (Union[str, AnswerRecordsTransport]): 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. @@ -452,17 +640,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = AnswerRecordsClient._read_environment_variables() + self._client_cert_source = AnswerRecordsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = AnswerRecordsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -471,20 +676,33 @@ 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, AnswerRecordsTransport): + transport_provided = isinstance(transport, AnswerRecordsTransport) + if transport_provided: # transport is a AnswerRecordsTransport 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(AnswerRecordsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or AnswerRecordsClient._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( @@ -494,17 +712,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 get_answer_record( @@ -613,6 +831,9 @@ def sample_get_answer_record(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -720,6 +941,9 @@ def sample_list_answer_records(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -874,6 +1098,9 @@ def sample_update_answer_record(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -941,6 +1168,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -995,6 +1225,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1052,6 +1285,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1103,6 +1339,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1157,6 +1396,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py index d87df5f6cdf6..dc90af5187bc 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py index e2b2c2a17493..77c2501fb3b8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py index 6140f23b0e90..0d956c8aace4 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/rest.py index 378dde8e5912..6b6fd9c698c0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/answer_records/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -320,7 +320,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py index eac1206cbd9d..ed8a0f4bce52 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -63,8 +63,12 @@ class ContextsAsyncClient: _client: ContextsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ContextsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ContextsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ContextsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ContextsClient._DEFAULT_UNIVERSE context_path = staticmethod(ContextsClient.context_path) parse_context_path = staticmethod(ContextsClient.parse_context_path) @@ -163,6 +167,25 @@ def transport(self) -> ContextsTransport: """ 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(ContextsClient).get_transport_class, type(ContextsClient) ) @@ -175,7 +198,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the contexts client. + """Instantiates the contexts async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -186,23 +209,38 @@ def __init__( transport (Union[str, ~.ContextsTransport]): 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. @@ -320,6 +358,9 @@ async def sample_list_contexts(): 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, @@ -457,6 +498,9 @@ async def sample_get_context(): 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, @@ -597,6 +641,9 @@ async def sample_create_context(): 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, @@ -725,6 +772,9 @@ async def sample_update_context(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -828,6 +878,9 @@ async def sample_delete_context(): 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, @@ -928,6 +981,9 @@ async def sample_delete_all_contexts(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. await rpc( request, @@ -979,6 +1035,9 @@ async def list_operations( 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, @@ -1033,6 +1092,9 @@ async def get_operation( 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, @@ -1090,6 +1152,9 @@ async def cancel_operation( 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, @@ -1141,6 +1206,9 @@ async def get_location( 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, @@ -1195,6 +1263,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/client.py index 843e667d46dd..e1512e2b82e0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -131,11 +132,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -286,7 +291,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 @@ -316,6 +321,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") @@ -349,6 +359,175 @@ 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 + + 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 + + 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 = ContextsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ContextsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ContextsClient._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 = ContextsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ContextsClient._DEFAULT_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 ContextsClient._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, *, @@ -368,22 +547,32 @@ def __init__( transport (Union[str, ContextsTransport]): 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. @@ -394,17 +583,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, + ) = ContextsClient._read_environment_variables() + self._client_cert_source = ContextsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ContextsClient._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" @@ -413,20 +619,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, ContextsTransport): + transport_provided = isinstance(transport, ContextsTransport) + if transport_provided: # transport is a ContextsTransport 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(ContextsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or ContextsClient._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( @@ -436,17 +652,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_contexts( @@ -555,6 +771,9 @@ def sample_list_contexts(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -692,6 +911,9 @@ def sample_get_context(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -832,6 +1054,9 @@ def sample_create_context(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -960,6 +1185,9 @@ def sample_update_context(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1063,6 +1291,9 @@ def sample_delete_context(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1163,6 +1394,9 @@ def sample_delete_all_contexts(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1227,6 +1461,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1281,6 +1518,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1338,6 +1578,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1389,6 +1632,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1443,6 +1689,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py index d95fec9e0d59..d9f3bc63761c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py index a0cd3698fcc9..117567fbb205 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py index ccf5cae6b94a..67fe460cbb68 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/rest.py index be62e36d36f9..593e7b60a5cc 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/contexts/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -372,7 +372,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py index 9580c811cc84..badf59abd033 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -69,8 +69,12 @@ class ConversationProfilesAsyncClient: _client: ConversationProfilesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ConversationProfilesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ConversationProfilesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ConversationProfilesClient._DEFAULT_UNIVERSE agent_path = staticmethod(ConversationProfilesClient.agent_path) parse_agent_path = staticmethod(ConversationProfilesClient.parse_agent_path) @@ -201,6 +205,25 @@ def transport(self) -> ConversationProfilesTransport: """ 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(ConversationProfilesClient).get_transport_class, type(ConversationProfilesClient), @@ -214,7 +237,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the conversation profiles client. + """Instantiates the conversation profiles async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -225,23 +248,38 @@ def __init__( transport (Union[str, ~.ConversationProfilesTransport]): 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. @@ -352,6 +390,9 @@ async def sample_list_conversation_profiles(): 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, @@ -466,6 +507,9 @@ async def sample_get_conversation_profile(): 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, @@ -593,6 +637,9 @@ async def sample_create_conversation_profile(): 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, @@ -720,6 +767,9 @@ async def sample_update_conversation_profile(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -819,6 +869,9 @@ async def sample_delete_conversation_profile(): 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, @@ -976,6 +1029,9 @@ async def sample_set_suggestion_feature_config(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1135,6 +1191,9 @@ async def sample_clear_suggestion_feature_config(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1197,6 +1256,9 @@ async def list_operations( 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, @@ -1251,6 +1313,9 @@ async def get_operation( 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, @@ -1308,6 +1373,9 @@ async def cancel_operation( 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, @@ -1359,6 +1427,9 @@ async def get_location( 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, @@ -1413,6 +1484,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py index b4c624393376..294c87023f82 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -139,11 +140,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -392,7 +397,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 @@ -422,6 +427,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") @@ -455,6 +465,175 @@ 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 + + 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 + + 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 = ConversationProfilesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ConversationProfilesClient._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 = ConversationProfilesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ConversationProfilesClient._DEFAULT_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 ConversationProfilesClient._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, *, @@ -474,22 +653,32 @@ def __init__( transport (Union[str, ConversationProfilesTransport]): 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. @@ -500,17 +689,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = ConversationProfilesClient._read_environment_variables() + self._client_cert_source = ConversationProfilesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ConversationProfilesClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -519,20 +725,33 @@ 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, ConversationProfilesTransport): + transport_provided = isinstance(transport, ConversationProfilesTransport) + if transport_provided: # transport is a ConversationProfilesTransport 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(ConversationProfilesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or ConversationProfilesClient._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( @@ -542,17 +761,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_conversation_profiles( @@ -658,6 +877,9 @@ def sample_list_conversation_profiles(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -772,6 +994,9 @@ def sample_get_conversation_profile(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -903,6 +1128,9 @@ def sample_create_conversation_profile(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1034,6 +1262,9 @@ def sample_update_conversation_profile(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1137,6 +1368,9 @@ def sample_delete_conversation_profile(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1300,6 +1534,9 @@ def sample_set_suggestion_feature_config(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1465,6 +1702,9 @@ def sample_clear_suggestion_feature_config(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1540,6 +1780,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1594,6 +1837,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1651,6 +1897,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1702,6 +1951,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1756,6 +2008,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py index cc7dde9eb680..4b234f38c359 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/base.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -128,6 +128,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-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py index f36842fc939e..88121a29bfa8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc.py @@ -70,7 +70,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py index f5a139f9b364..f8988e48b358 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/grpc_asyncio.py @@ -115,7 +115,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/rest.py index 83186844d0cd..a693c737acae 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversation_profiles/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -456,7 +456,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py index 5ccf8564b4d0..c23e92639b8b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -63,8 +63,12 @@ class ConversationsAsyncClient: _client: ConversationsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ConversationsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ConversationsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ConversationsClient._DEFAULT_UNIVERSE agent_path = staticmethod(ConversationsClient.agent_path) parse_agent_path = staticmethod(ConversationsClient.parse_agent_path) @@ -201,6 +205,25 @@ def transport(self) -> ConversationsTransport: """ 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(ConversationsClient).get_transport_class, type(ConversationsClient) ) @@ -213,7 +236,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the conversations client. + """Instantiates the conversations async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -224,23 +247,38 @@ def __init__( transport (Union[str, ~.ConversationsTransport]): 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. @@ -383,6 +421,9 @@ async def sample_create_conversation(): 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, @@ -491,6 +532,9 @@ async def sample_list_conversations(): 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, @@ -607,6 +651,9 @@ async def sample_get_conversation(): 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, @@ -717,6 +764,9 @@ async def sample_complete_conversation(): 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, @@ -827,6 +877,9 @@ async def sample_batch_create_messages(): 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, @@ -938,6 +991,9 @@ async def sample_list_messages(): 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, @@ -1056,6 +1112,9 @@ async def sample_suggest_conversation_summary(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1154,6 +1213,9 @@ async def sample_generate_stateless_summary(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1235,6 +1297,9 @@ async def sample_search_knowledge(): 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, @@ -1289,6 +1354,9 @@ async def list_operations( 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, @@ -1343,6 +1411,9 @@ async def get_operation( 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, @@ -1400,6 +1471,9 @@ async def cancel_operation( 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, @@ -1451,6 +1525,9 @@ async def get_location( 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, @@ -1505,6 +1582,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py index 73287f59f80d..4f8f226c3ba3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -131,11 +132,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -446,7 +451,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 @@ -476,6 +481,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") @@ -509,6 +519,175 @@ 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 + + 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 + + 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 = ConversationsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ConversationsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ConversationsClient._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 = ConversationsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ConversationsClient._DEFAULT_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 ConversationsClient._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, *, @@ -528,22 +707,32 @@ def __init__( transport (Union[str, ConversationsTransport]): 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. @@ -554,17 +743,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, + ) = ConversationsClient._read_environment_variables() + self._client_cert_source = ConversationsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ConversationsClient._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" @@ -573,20 +779,33 @@ 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, ConversationsTransport): + transport_provided = isinstance(transport, ConversationsTransport) + if transport_provided: # transport is a ConversationsTransport 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(ConversationsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or ConversationsClient._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( @@ -596,17 +815,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 create_conversation( @@ -740,6 +959,9 @@ def sample_create_conversation(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -848,6 +1070,9 @@ def sample_list_conversations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -964,6 +1189,9 @@ def sample_get_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1074,6 +1302,9 @@ def sample_complete_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1184,6 +1415,9 @@ def sample_batch_create_messages(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1295,6 +1529,9 @@ def sample_list_messages(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1415,6 +1652,9 @@ def sample_suggest_conversation_summary(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1516,6 +1756,9 @@ def sample_generate_stateless_summary(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1598,6 +1841,9 @@ def sample_search_knowledge(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1665,6 +1911,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1719,6 +1968,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1776,6 +2028,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1827,6 +2082,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1881,6 +2139,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py index 82318589839f..8eaa50e80c5f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py index 39a9b0c10aeb..9ad0e378c12f 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py index 016970889120..ea47a412d393 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/rest.py index 93fe74750ef1..48f9d8d3ea0a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/conversations/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -508,7 +508,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/async_client.py index 6afff54c539a..a09772d690f6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -66,8 +66,12 @@ class DocumentsAsyncClient: _client: DocumentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DocumentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DocumentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DocumentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DocumentsClient._DEFAULT_UNIVERSE document_path = staticmethod(DocumentsClient.document_path) parse_document_path = staticmethod(DocumentsClient.parse_document_path) @@ -168,6 +172,25 @@ def transport(self) -> DocumentsTransport: """ 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(DocumentsClient).get_transport_class, type(DocumentsClient) ) @@ -180,7 +203,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the documents client. + """Instantiates the documents async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -191,23 +214,38 @@ def __init__( transport (Union[str, ~.DocumentsTransport]): 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. @@ -318,6 +356,9 @@ async def sample_list_documents(): 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, @@ -439,6 +480,9 @@ async def sample_get_document(): 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, @@ -583,6 +627,9 @@ async def sample_create_document(): 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, @@ -698,6 +745,9 @@ async def sample_import_documents(): 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, @@ -835,6 +885,9 @@ async def sample_delete_document(): 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, @@ -988,6 +1041,9 @@ async def sample_update_document(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1144,6 +1200,9 @@ async def sample_reload_document(): 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, @@ -1206,6 +1265,9 @@ async def list_operations( 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, @@ -1260,6 +1322,9 @@ async def get_operation( 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, @@ -1317,6 +1382,9 @@ async def cancel_operation( 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, @@ -1368,6 +1436,9 @@ async def get_location( 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, @@ -1422,6 +1493,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/client.py index 0f4730d5f130..43d7e0f3c647 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -134,11 +135,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -289,7 +294,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 @@ -319,6 +324,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") @@ -352,6 +362,175 @@ 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 + + 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 + + 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 = DocumentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DocumentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DocumentsClient._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 = DocumentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DocumentsClient._DEFAULT_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 DocumentsClient._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, *, @@ -371,22 +550,32 @@ def __init__( transport (Union[str, DocumentsTransport]): 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. @@ -397,17 +586,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = DocumentsClient._read_environment_variables() + self._client_cert_source = DocumentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = DocumentsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -416,20 +622,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, DocumentsTransport): + transport_provided = isinstance(transport, DocumentsTransport) + if transport_provided: # transport is a DocumentsTransport 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(DocumentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or DocumentsClient._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( @@ -439,17 +655,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_documents( @@ -551,6 +767,9 @@ def sample_list_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -672,6 +891,9 @@ def sample_get_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -816,6 +1038,9 @@ def sample_create_document(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -932,6 +1157,9 @@ def sample_import_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1069,6 +1297,9 @@ def sample_delete_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1222,6 +1453,9 @@ def sample_update_document(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1378,6 +1612,9 @@ def sample_reload_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1453,6 +1690,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1507,6 +1747,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1564,6 +1807,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1615,6 +1861,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1669,6 +1918,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py index f7253d340012..e542b919639e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py index 76e53e94ec02..a47e91426a14 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py index e7aa6da0ca92..c6593d29088d 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/rest.py index 6aed0d9bbf4c..391fc96f2f52 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/documents/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -446,7 +446,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py index cfa438d9973d..51a0b1f1e8b5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -66,8 +66,12 @@ class EntityTypesAsyncClient: _client: EntityTypesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EntityTypesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EntityTypesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = EntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = EntityTypesClient._DEFAULT_UNIVERSE entity_type_path = staticmethod(EntityTypesClient.entity_type_path) parse_entity_type_path = staticmethod(EntityTypesClient.parse_entity_type_path) @@ -170,6 +174,25 @@ def transport(self) -> EntityTypesTransport: """ 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(EntityTypesClient).get_transport_class, type(EntityTypesClient) ) @@ -182,7 +205,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the entity types client. + """Instantiates the entity types async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -193,23 +216,38 @@ def __init__( transport (Union[str, ~.EntityTypesTransport]): 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. @@ -333,6 +371,9 @@ async def sample_list_entity_types(): 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, @@ -473,6 +514,9 @@ async def sample_get_entity_type(): 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, @@ -621,6 +665,9 @@ async def sample_create_entity_type(): 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, @@ -767,6 +814,9 @@ async def sample_update_entity_type(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -867,6 +917,9 @@ async def sample_delete_entity_type(): 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, @@ -967,6 +1020,9 @@ async def sample_batch_update_entity_types(): 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, @@ -1121,6 +1177,9 @@ async def sample_batch_delete_entity_types(): 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, @@ -1287,6 +1346,9 @@ async def sample_batch_create_entities(): 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, @@ -1457,6 +1519,9 @@ async def sample_batch_update_entities(): 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, @@ -1623,6 +1688,9 @@ async def sample_batch_delete_entities(): 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, @@ -1685,6 +1753,9 @@ async def list_operations( 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, @@ -1739,6 +1810,9 @@ async def get_operation( 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, @@ -1796,6 +1870,9 @@ async def cancel_operation( 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, @@ -1847,6 +1924,9 @@ async def get_location( 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, @@ -1901,6 +1981,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/client.py index c70994c9ffed..32698c3f0ee1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -134,11 +135,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -286,7 +291,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 @@ -316,6 +321,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") @@ -349,6 +359,175 @@ 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 + + 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 + + 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 = EntityTypesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EntityTypesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = EntityTypesClient._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 = EntityTypesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = EntityTypesClient._DEFAULT_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 EntityTypesClient._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, *, @@ -368,22 +547,32 @@ def __init__( transport (Union[str, EntityTypesTransport]): 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. @@ -394,17 +583,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, + ) = EntityTypesClient._read_environment_variables() + self._client_cert_source = EntityTypesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = EntityTypesClient._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" @@ -413,20 +619,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, EntityTypesTransport): + transport_provided = isinstance(transport, EntityTypesTransport) + if transport_provided: # transport is a EntityTypesTransport 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(EntityTypesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or EntityTypesClient._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( @@ -436,17 +652,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_entity_types( @@ -561,6 +777,9 @@ def sample_list_entity_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -701,6 +920,9 @@ def sample_get_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -849,6 +1071,9 @@ def sample_create_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -995,6 +1220,9 @@ def sample_update_entity_type(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1095,6 +1323,9 @@ def sample_delete_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1198,6 +1429,9 @@ def sample_batch_update_entity_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1354,6 +1588,9 @@ def sample_batch_delete_entity_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1520,6 +1757,9 @@ def sample_batch_create_entities(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1690,6 +1930,9 @@ def sample_batch_update_entities(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1856,6 +2099,9 @@ def sample_batch_delete_entities(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1931,6 +2177,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1985,6 +2234,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2042,6 +2294,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -2093,6 +2348,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2147,6 +2405,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py index 110dfdc3c084..99dc922bb51b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py index 97e38458096c..f8a48943238a 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py index 885239f31c0d..f1ef0da55152 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/rest.py index 627f5b501a28..ad6cbae118eb 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/entity_types/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -529,7 +529,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/async_client.py index a4a2309586ec..e53f509fc9a9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -61,8 +61,12 @@ class EnvironmentsAsyncClient: _client: EnvironmentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EnvironmentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = EnvironmentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = EnvironmentsClient._DEFAULT_UNIVERSE environment_path = staticmethod(EnvironmentsClient.environment_path) parse_environment_path = staticmethod(EnvironmentsClient.parse_environment_path) @@ -169,6 +173,25 @@ def transport(self) -> EnvironmentsTransport: """ 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(EnvironmentsClient).get_transport_class, type(EnvironmentsClient) ) @@ -181,7 +204,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the environments client. + """Instantiates the environments async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -192,23 +215,38 @@ def __init__( transport (Union[str, ~.EnvironmentsTransport]): 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. @@ -319,6 +357,9 @@ async def sample_list_environments(): 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, @@ -427,6 +468,9 @@ async def sample_get_environment(): 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, @@ -527,6 +571,9 @@ async def sample_create_environment(): 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, @@ -639,6 +686,9 @@ async def sample_update_environment(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -710,6 +760,9 @@ async def sample_delete_environment(): 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, @@ -791,6 +844,9 @@ async def sample_get_environment_history(): 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, @@ -854,6 +910,9 @@ async def list_operations( 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, @@ -908,6 +967,9 @@ async def get_operation( 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, @@ -965,6 +1027,9 @@ async def cancel_operation( 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, @@ -1016,6 +1081,9 @@ async def get_location( 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, @@ -1070,6 +1138,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/client.py index 847f6f287849..cfa892437a93 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -129,11 +130,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -315,7 +320,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 @@ -345,6 +350,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") @@ -378,6 +388,175 @@ 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 + + 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 + + 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 = EnvironmentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = EnvironmentsClient._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 = EnvironmentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = EnvironmentsClient._DEFAULT_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 EnvironmentsClient._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, *, @@ -397,22 +576,32 @@ def __init__( transport (Union[str, EnvironmentsTransport]): 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. @@ -423,17 +612,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, + ) = EnvironmentsClient._read_environment_variables() + self._client_cert_source = EnvironmentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = EnvironmentsClient._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" @@ -442,20 +648,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, EnvironmentsTransport): + transport_provided = isinstance(transport, EnvironmentsTransport) + if transport_provided: # transport is a EnvironmentsTransport 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(EnvironmentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or EnvironmentsClient._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( @@ -465,17 +681,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_environments( @@ -577,6 +793,9 @@ def sample_list_environments(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -686,6 +905,9 @@ def sample_get_environment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -787,6 +1009,9 @@ def sample_create_environment(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -900,6 +1125,9 @@ def sample_update_environment(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -972,6 +1200,9 @@ def sample_delete_environment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1054,6 +1285,9 @@ def sample_get_environment_history(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1130,6 +1364,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1184,6 +1421,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1241,6 +1481,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1292,6 +1535,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1346,6 +1592,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py index f76af7895add..1eac2c7e1090 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py index 581c437ceadd..37146ecd1001 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py index c967461ff26b..b1d3709130ba 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/rest.py index 51a276863376..7eb401f8b3fa 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/environments/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -398,7 +398,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py index 6b72d5bd1b2b..1e36cf3fc2f5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -61,8 +61,12 @@ class FulfillmentsAsyncClient: _client: FulfillmentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = FulfillmentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = FulfillmentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = FulfillmentsClient._DEFAULT_UNIVERSE fulfillment_path = staticmethod(FulfillmentsClient.fulfillment_path) parse_fulfillment_path = staticmethod(FulfillmentsClient.parse_fulfillment_path) @@ -165,6 +169,25 @@ def transport(self) -> FulfillmentsTransport: """ 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(FulfillmentsClient).get_transport_class, type(FulfillmentsClient) ) @@ -177,7 +200,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the fulfillments client. + """Instantiates the fulfillments async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -188,23 +211,38 @@ def __init__( transport (Union[str, ~.FulfillmentsTransport]): 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. @@ -320,6 +358,9 @@ async def sample_get_fulfillment(): 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, @@ -447,6 +488,9 @@ async def sample_update_fulfillment(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -501,6 +545,9 @@ async def list_operations( 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, @@ -555,6 +602,9 @@ async def get_operation( 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, @@ -612,6 +662,9 @@ async def cancel_operation( 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, @@ -663,6 +716,9 @@ async def get_location( 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, @@ -717,6 +773,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py index decc84b2b31e..184b3f8794e1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -129,11 +130,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -277,7 +282,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 @@ -307,6 +312,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") @@ -340,6 +350,175 @@ 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 + + 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 + + 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 = FulfillmentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = FulfillmentsClient._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 = FulfillmentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = FulfillmentsClient._DEFAULT_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 FulfillmentsClient._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, *, @@ -359,22 +538,32 @@ def __init__( transport (Union[str, FulfillmentsTransport]): 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. @@ -385,17 +574,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, + ) = FulfillmentsClient._read_environment_variables() + self._client_cert_source = FulfillmentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = FulfillmentsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -404,20 +610,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, FulfillmentsTransport): + transport_provided = isinstance(transport, FulfillmentsTransport) + if transport_provided: # transport is a FulfillmentsTransport 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(FulfillmentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or FulfillmentsClient._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( @@ -427,17 +643,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 get_fulfillment( @@ -544,6 +760,9 @@ def sample_get_fulfillment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -671,6 +890,9 @@ def sample_update_fulfillment(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -738,6 +960,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -792,6 +1017,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -849,6 +1077,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -900,6 +1131,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -954,6 +1188,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py index 917f3115405b..c22a426bf160 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc.py index 71d2b74bdbe2..dec1a7894061 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py index 228d4e685d52..3187ef53bb42 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/rest.py index 5eb81d8d2017..93911b11c7ed 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/fulfillments/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -289,7 +289,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/async_client.py index 866498e622d0..bafa9a713726 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -67,8 +67,12 @@ class IntentsAsyncClient: _client: IntentsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = IntentsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = IntentsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = IntentsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = IntentsClient._DEFAULT_UNIVERSE context_path = staticmethod(IntentsClient.context_path) parse_context_path = staticmethod(IntentsClient.parse_context_path) @@ -169,6 +173,25 @@ def transport(self) -> IntentsTransport: """ 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(IntentsClient).get_transport_class, type(IntentsClient) ) @@ -181,7 +204,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the intents client. + """Instantiates the intents async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -192,23 +215,38 @@ def __init__( transport (Union[str, ~.IntentsTransport]): 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. @@ -338,6 +376,9 @@ async def sample_list_intents(): 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, @@ -473,6 +514,9 @@ async def sample_get_intent(): 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, @@ -616,6 +660,9 @@ async def sample_create_intent(): 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, @@ -757,6 +804,9 @@ async def sample_update_intent(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -861,6 +911,9 @@ async def sample_delete_intent(): 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, @@ -1008,6 +1061,9 @@ async def sample_batch_update_intents(): 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, @@ -1163,6 +1219,9 @@ async def sample_batch_delete_intents(): 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, @@ -1225,6 +1284,9 @@ async def list_operations( 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, @@ -1279,6 +1341,9 @@ async def get_operation( 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, @@ -1336,6 +1401,9 @@ async def cancel_operation( 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, @@ -1387,6 +1455,9 @@ async def get_location( 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, @@ -1441,6 +1512,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/client.py index c60dee78f9cd..f4678cefc510 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -135,11 +136,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -307,7 +312,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 @@ -337,6 +342,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") @@ -370,6 +380,175 @@ 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 + + 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 + + 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 = IntentsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = IntentsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = IntentsClient._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 = IntentsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = IntentsClient._DEFAULT_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 IntentsClient._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, *, @@ -389,22 +568,32 @@ def __init__( transport (Union[str, IntentsTransport]): 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. @@ -415,17 +604,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = IntentsClient._read_environment_variables() + self._client_cert_source = IntentsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = IntentsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -434,20 +640,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, IntentsTransport): + transport_provided = isinstance(transport, IntentsTransport) + if transport_provided: # transport is a IntentsTransport 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(IntentsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or IntentsClient._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( @@ -457,17 +673,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_intents( @@ -588,6 +804,9 @@ def sample_list_intents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -723,6 +942,9 @@ def sample_get_intent(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -866,6 +1088,9 @@ def sample_create_intent(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1007,6 +1232,9 @@ def sample_update_intent(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1111,6 +1339,9 @@ def sample_delete_intent(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1258,6 +1489,9 @@ def sample_batch_update_intents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1413,6 +1647,9 @@ def sample_batch_delete_intents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1488,6 +1725,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1542,6 +1782,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1599,6 +1842,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1650,6 +1896,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1704,6 +1953,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py index 6565009acc65..9b37c3129410 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py index eadd3323fd88..b5f21453adec 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py index 3b14562b9051..7683b05bf3de 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/rest.py index 84ee2aba578c..c543b3772ecf 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/intents/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -424,7 +424,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py index 28563d99b55b..b7552e769eea 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -62,8 +62,12 @@ class KnowledgeBasesAsyncClient: _client: KnowledgeBasesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = KnowledgeBasesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = KnowledgeBasesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = KnowledgeBasesClient._DEFAULT_UNIVERSE knowledge_base_path = staticmethod(KnowledgeBasesClient.knowledge_base_path) parse_knowledge_base_path = staticmethod( @@ -172,6 +176,25 @@ def transport(self) -> KnowledgeBasesTransport: """ 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(KnowledgeBasesClient).get_transport_class, type(KnowledgeBasesClient) ) @@ -184,7 +207,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the knowledge bases client. + """Instantiates the knowledge bases async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -195,23 +218,38 @@ def __init__( transport (Union[str, ~.KnowledgeBasesTransport]): 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. @@ -322,6 +360,9 @@ async def sample_list_knowledge_bases(): 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, @@ -447,6 +488,9 @@ async def sample_get_knowledge_base(): 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, @@ -579,6 +623,9 @@ async def sample_create_knowledge_base(): 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, @@ -678,6 +725,9 @@ async def sample_delete_knowledge_base(): 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, @@ -808,6 +858,9 @@ async def sample_update_knowledge_base(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -862,6 +915,9 @@ async def list_operations( 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, @@ -916,6 +972,9 @@ async def get_operation( 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, @@ -973,6 +1032,9 @@ async def cancel_operation( 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, @@ -1024,6 +1086,9 @@ async def get_location( 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, @@ -1078,6 +1143,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py index ac93e5a96e28..cb3e573c56c0 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -132,11 +133,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -284,7 +289,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 @@ -314,6 +319,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") @@ -347,6 +357,175 @@ 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 + + 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 + + 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 = KnowledgeBasesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = KnowledgeBasesClient._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 = KnowledgeBasesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = KnowledgeBasesClient._DEFAULT_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 KnowledgeBasesClient._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, *, @@ -366,22 +545,32 @@ def __init__( transport (Union[str, KnowledgeBasesTransport]): 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. @@ -392,17 +581,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, + ) = KnowledgeBasesClient._read_environment_variables() + self._client_cert_source = KnowledgeBasesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = KnowledgeBasesClient._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" @@ -411,20 +617,33 @@ 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, KnowledgeBasesTransport): + transport_provided = isinstance(transport, KnowledgeBasesTransport) + if transport_provided: # transport is a KnowledgeBasesTransport 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(KnowledgeBasesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or KnowledgeBasesClient._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( @@ -434,17 +653,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_knowledge_bases( @@ -546,6 +765,9 @@ def sample_list_knowledge_bases(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -671,6 +893,9 @@ def sample_get_knowledge_base(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -803,6 +1028,9 @@ def sample_create_knowledge_base(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -902,6 +1130,9 @@ def sample_delete_knowledge_base(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1032,6 +1263,9 @@ def sample_update_knowledge_base(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1099,6 +1333,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1153,6 +1390,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1210,6 +1450,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1261,6 +1504,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1315,6 +1561,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py index 27ce97cf5220..7c0f1b7b54d1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py index 0eeec18189ad..0809a91f033c 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py index ea8ab3726a18..bb473c568496 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/rest.py index e2caeec7a157..b9e08ecd53a3 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/knowledge_bases/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -372,7 +372,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py index 14ce58f9f8eb..6ded5e4b3fe9 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/async_client.py @@ -42,9 +42,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -67,8 +67,12 @@ class ParticipantsAsyncClient: _client: ParticipantsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ParticipantsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ParticipantsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ParticipantsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = ParticipantsClient._DEFAULT_UNIVERSE answer_record_path = staticmethod(ParticipantsClient.answer_record_path) parse_answer_record_path = staticmethod(ParticipantsClient.parse_answer_record_path) @@ -185,6 +189,25 @@ def transport(self) -> ParticipantsTransport: """ 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(ParticipantsClient).get_transport_class, type(ParticipantsClient) ) @@ -197,7 +220,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the participants client. + """Instantiates the participants async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -208,23 +231,38 @@ def __init__( transport (Union[str, ~.ParticipantsTransport]): 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. @@ -336,6 +374,9 @@ async def sample_create_participant(): 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, @@ -438,6 +479,9 @@ async def sample_get_participant(): 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, @@ -546,6 +590,9 @@ async def sample_list_participants(): 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, @@ -666,6 +713,9 @@ async def sample_update_participant(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -813,6 +863,9 @@ async def sample_analyze_content(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -985,6 +1038,9 @@ def request_generator(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = rpc( requests, @@ -1096,6 +1152,9 @@ async def sample_suggest_articles(): 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, @@ -1200,6 +1259,9 @@ async def sample_suggest_faq_answers(): 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, @@ -1304,6 +1366,9 @@ async def sample_suggest_smart_replies(): 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, @@ -1410,6 +1475,9 @@ async def sample_list_suggestions(): 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, @@ -1517,6 +1585,9 @@ async def sample_compile_suggestion(): 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, @@ -1571,6 +1642,9 @@ async def list_operations( 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, @@ -1625,6 +1699,9 @@ async def get_operation( 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, @@ -1682,6 +1759,9 @@ async def cancel_operation( 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, @@ -1733,6 +1813,9 @@ async def get_location( 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, @@ -1787,6 +1870,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py index 407bd05b5739..0f885cb0ba06 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/client.py @@ -45,9 +45,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -134,11 +134,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -415,7 +419,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 @@ -445,6 +449,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") @@ -478,6 +487,175 @@ 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 + + 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 + + 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 = ParticipantsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ParticipantsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ParticipantsClient._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 = ParticipantsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ParticipantsClient._DEFAULT_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 ParticipantsClient._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, *, @@ -497,22 +675,32 @@ def __init__( transport (Union[str, ParticipantsTransport]): 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. @@ -523,17 +711,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, + ) = ParticipantsClient._read_environment_variables() + self._client_cert_source = ParticipantsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = ParticipantsClient._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" @@ -542,20 +747,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, ParticipantsTransport): + transport_provided = isinstance(transport, ParticipantsTransport) + if transport_provided: # transport is a ParticipantsTransport 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(ParticipantsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or ParticipantsClient._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( @@ -565,17 +780,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 create_participant( @@ -678,6 +893,9 @@ def sample_create_participant(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -780,6 +998,9 @@ def sample_get_participant(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -888,6 +1109,9 @@ def sample_list_participants(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1008,6 +1232,9 @@ def sample_update_participant(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1146,6 +1373,9 @@ def sample_analyze_content(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1314,6 +1544,9 @@ def request_generator(): self._transport.streaming_analyze_content ] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( requests, @@ -1425,6 +1658,9 @@ def sample_suggest_articles(): 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 +1765,9 @@ def sample_suggest_faq_answers(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1633,6 +1872,9 @@ def sample_suggest_smart_replies(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1740,6 +1982,9 @@ def sample_list_suggestions(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1847,6 +2092,9 @@ def sample_compile_suggestion(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1914,6 +2162,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1968,6 +2219,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2025,6 +2279,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -2076,6 +2333,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2130,6 +2390,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py index 0a98515a8852..4b7e4318f1ee 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py index 0d35faa6a137..e1f19a0ecb02 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py index ad7accf68cc6..b80c40073053 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/rest.py index 23afed228a88..013b733a2b20 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/participants/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -537,7 +537,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py index 9fa6c728a36f..75865e9ff8c1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -65,8 +65,12 @@ class SessionEntityTypesAsyncClient: _client: SessionEntityTypesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SessionEntityTypesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SessionEntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SessionEntityTypesClient._DEFAULT_UNIVERSE session_entity_type_path = staticmethod( SessionEntityTypesClient.session_entity_type_path @@ -177,6 +181,25 @@ def transport(self) -> SessionEntityTypesTransport: """ 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(SessionEntityTypesClient).get_transport_class, type(SessionEntityTypesClient), @@ -190,7 +213,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the session entity types client. + """Instantiates the session entity types async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -201,23 +224,38 @@ def __init__( transport (Union[str, ~.SessionEntityTypesTransport]): 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. @@ -340,6 +378,9 @@ async def sample_list_session_entity_types(): 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, @@ -475,6 +516,9 @@ async def sample_get_session_entity_type(): 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, @@ -614,6 +658,9 @@ async def sample_create_session_entity_type(): 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, @@ -741,6 +788,9 @@ async def sample_update_session_entity_type(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -850,6 +900,9 @@ async def sample_delete_session_entity_type(): 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, @@ -901,6 +954,9 @@ async def list_operations( 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, @@ -955,6 +1011,9 @@ async def get_operation( 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, @@ -1012,6 +1071,9 @@ async def cancel_operation( 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, @@ -1063,6 +1125,9 @@ async def get_location( 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, @@ -1117,6 +1182,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py index 215ed1266f51..ff52a5961c70 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -135,11 +136,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -290,7 +295,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 @@ -320,6 +325,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") @@ -353,6 +363,175 @@ 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 + + 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 + + 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 = SessionEntityTypesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SessionEntityTypesClient._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 = SessionEntityTypesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SessionEntityTypesClient._DEFAULT_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 SessionEntityTypesClient._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, *, @@ -372,22 +551,32 @@ def __init__( transport (Union[str, SessionEntityTypesTransport]): 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. @@ -398,17 +587,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, + ) = SessionEntityTypesClient._read_environment_variables() + self._client_cert_source = SessionEntityTypesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = SessionEntityTypesClient._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" @@ -417,20 +623,33 @@ 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, SessionEntityTypesTransport): + transport_provided = isinstance(transport, SessionEntityTypesTransport) + if transport_provided: # transport is a SessionEntityTypesTransport 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(SessionEntityTypesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SessionEntityTypesClient._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( @@ -440,17 +659,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_session_entity_types( @@ -566,6 +785,9 @@ def sample_list_session_entity_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -701,6 +923,9 @@ def sample_get_session_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -844,6 +1069,9 @@ def sample_create_session_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -975,6 +1203,9 @@ def sample_update_session_entity_type(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1086,6 +1317,9 @@ def sample_delete_session_entity_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1150,6 +1384,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1204,6 +1441,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1261,6 +1501,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1312,6 +1555,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1366,6 +1612,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py index dfbe771f1d27..c2759c39ab41 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/base.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -128,6 +128,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-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py index 6dd5641b513f..65c5564ec2f5 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc.py @@ -70,7 +70,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py index 4870811d80e5..bf54fc894b28 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/grpc_asyncio.py @@ -115,7 +115,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/rest.py index e8d478669269..4f371ec543a1 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/session_entity_types/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -382,7 +382,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py index bbdf531880e8..63300ed1552b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/async_client.py @@ -41,9 +41,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -67,8 +67,12 @@ class SessionsAsyncClient: _client: SessionsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SessionsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SessionsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SessionsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SessionsClient._DEFAULT_UNIVERSE context_path = staticmethod(SessionsClient.context_path) parse_context_path = staticmethod(SessionsClient.parse_context_path) @@ -177,6 +181,25 @@ def transport(self) -> SessionsTransport: """ 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(SessionsClient).get_transport_class, type(SessionsClient) ) @@ -189,7 +212,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the sessions client. + """Instantiates the sessions async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -200,23 +223,38 @@ def __init__( transport (Union[str, ~.SessionsTransport]): 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. @@ -390,6 +428,9 @@ async def sample_detect_intent(): gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -548,6 +589,9 @@ def request_generator(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = rpc( requests, @@ -602,6 +646,9 @@ async def list_operations( 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, @@ -656,6 +703,9 @@ async def get_operation( 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, @@ -713,6 +763,9 @@ async def cancel_operation( 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, @@ -764,6 +817,9 @@ async def get_location( 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, @@ -818,6 +874,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/client.py index a484b903c7f0..0848ad737fa6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/client.py @@ -30,6 +30,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -44,9 +45,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -134,11 +135,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -369,7 +374,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 @@ -399,6 +404,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") @@ -432,6 +442,175 @@ 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 + + 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 + + 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 = SessionsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SessionsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SessionsClient._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 = SessionsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SessionsClient._DEFAULT_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 SessionsClient._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, *, @@ -451,22 +630,32 @@ def __init__( transport (Union[str, SessionsTransport]): 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. @@ -477,17 +666,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, + ) = SessionsClient._read_environment_variables() + self._client_cert_source = SessionsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = SessionsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -496,20 +702,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, SessionsTransport): + transport_provided = isinstance(transport, SessionsTransport) + if transport_provided: # transport is a SessionsTransport 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(SessionsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or SessionsClient._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( @@ -519,17 +735,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 detect_intent( @@ -685,6 +901,9 @@ def sample_detect_intent(): gapic_v1.routing_header.to_grpc_metadata((("session", request.session),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -839,6 +1058,9 @@ def request_generator(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.streaming_detect_intent] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( requests, @@ -906,6 +1128,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -960,6 +1185,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1017,6 +1245,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1068,6 +1299,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1122,6 +1356,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py index 2044e4569d54..ca31ab261dbc 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/base.py @@ -62,7 +62,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -125,6 +125,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-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py index 98e3f27aef7d..10defa3c75c8 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc.py @@ -69,7 +69,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py index 572529c284f9..22e389758ff7 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/grpc_asyncio.py @@ -114,7 +114,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/rest.py index ff32313714ba..600a07b815a6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/sessions/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -260,7 +260,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/async_client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/async_client.py index bad469685a05..a6d2ff1076e6 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/async_client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -63,8 +63,12 @@ class VersionsAsyncClient: _client: VersionsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = VersionsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = VersionsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = VersionsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = VersionsClient._DEFAULT_UNIVERSE version_path = staticmethod(VersionsClient.version_path) parse_version_path = staticmethod(VersionsClient.parse_version_path) @@ -163,6 +167,25 @@ def transport(self) -> VersionsTransport: """ 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(VersionsClient).get_transport_class, type(VersionsClient) ) @@ -175,7 +198,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the versions client. + """Instantiates the versions async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -186,23 +209,38 @@ def __init__( transport (Union[str, ~.VersionsTransport]): 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. @@ -313,6 +351,9 @@ async def sample_list_versions(): 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, @@ -445,6 +486,9 @@ async def sample_get_version(): 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, @@ -580,6 +624,9 @@ async def sample_create_version(): 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, @@ -719,6 +766,9 @@ async def sample_update_version(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -815,6 +865,9 @@ async def sample_delete_version(): 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, @@ -866,6 +919,9 @@ async def list_operations( 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, @@ -920,6 +976,9 @@ async def get_operation( 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, @@ -977,6 +1036,9 @@ async def cancel_operation( 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, @@ -1028,6 +1090,9 @@ async def get_location( 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, @@ -1082,6 +1147,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/client.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/client.py index 298b82968160..d401b77ea501 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/client.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dialogflow_v2beta1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -131,11 +132,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 = "dialogflow.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dialogflow.{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 @@ -283,7 +288,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 @@ -313,6 +318,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") @@ -346,6 +356,175 @@ 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 + + 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 + + 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 = VersionsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = VersionsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = VersionsClient._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 = VersionsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = VersionsClient._DEFAULT_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 VersionsClient._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, *, @@ -365,22 +544,32 @@ def __init__( transport (Union[str, VersionsTransport]): 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. @@ -391,17 +580,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, + ) = VersionsClient._read_environment_variables() + self._client_cert_source = VersionsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = VersionsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -410,20 +616,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, VersionsTransport): + transport_provided = isinstance(transport, VersionsTransport) + if transport_provided: # transport is a VersionsTransport 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(VersionsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or VersionsClient._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( @@ -433,17 +649,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_versions( @@ -545,6 +761,9 @@ def sample_list_versions(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -677,6 +896,9 @@ def sample_get_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -812,6 +1034,9 @@ def sample_create_version(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -951,6 +1176,9 @@ def sample_update_version(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1047,6 +1275,9 @@ def sample_delete_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1111,6 +1342,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1165,6 +1399,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1222,6 +1459,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1273,6 +1513,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1327,6 +1570,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py index 49c40fb010ce..8ef0ed3196ee 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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 @@ -126,6 +126,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-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc.py index 80410e393ae0..a4c3dc52ef63 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py index e79ef3156f9e..ca622d0d063e 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/rest.py b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/rest.py index 477e0aba6770..46ee9f0d120b 100644 --- a/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/rest.py +++ b/packages/google-cloud-dialogflow/google/cloud/dialogflow_v2beta1/services/versions/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -356,7 +356,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dialogflow.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-dialogflow/noxfile.py b/packages/google-cloud-dialogflow/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-dialogflow/noxfile.py +++ b/packages/google-cloud-dialogflow/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-dialogflow/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.v2.json b/packages/google-cloud-dialogflow/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.v2.json index 00543f879382..15f4b2c8fa69 100644 --- a/packages/google-cloud-dialogflow/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.v2.json +++ b/packages/google-cloud-dialogflow/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.v2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-dialogflow", - "version": "2.27.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-dialogflow/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.v2beta1.json b/packages/google-cloud-dialogflow/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.v2beta1.json index 0e505e3bfc1d..11feb40f02d8 100644 --- a/packages/google-cloud-dialogflow/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.v2beta1.json +++ b/packages/google-cloud-dialogflow/samples/generated_samples/snippet_metadata_google.cloud.dialogflow.v2beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-dialogflow", - "version": "2.27.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_agents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_agents.py index 2ee044f392bb..dae253110c0c 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_agents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_agents.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -82,6 +82,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -105,6 +128,237 @@ def test__get_default_mtls_endpoint(): assert AgentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert AgentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert AgentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert AgentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + AgentsClient._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 AgentsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert AgentsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert AgentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + AgentsClient._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 AgentsClient._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 AgentsClient._get_client_cert_source(None, False) is None + assert ( + AgentsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + AgentsClient._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 ( + AgentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + AgentsClient._get_client_cert_source(mock_provided_cert_source, "true") + is mock_provided_cert_source + ) + + +@mock.patch.object( + AgentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsClient), +) +@mock.patch.object( + AgentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = AgentsClient._DEFAULT_UNIVERSE + default_endpoint = AgentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AgentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + AgentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + AgentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == AgentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AgentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + AgentsClient._get_api_endpoint(None, None, default_universe, "always") + == AgentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AgentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == AgentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AgentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + AgentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + AgentsClient._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 ( + AgentsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + AgentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + AgentsClient._get_universe_domain(None, None) == AgentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + AgentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (AgentsClient, transports.AgentsGrpcTransport, "grpc"), + (AgentsClient, transports.AgentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -114,7 +368,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_agents_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -164,7 +418,7 @@ def test_agents_client_service_account_always_use_jwt(transport_class, transport ], ) def test_agents_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -209,15 +463,21 @@ def test_agents_client_get_transport_class(): ], ) @mock.patch.object( - AgentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AgentsClient) + AgentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsClient), ) @mock.patch.object( - AgentsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AgentsAsyncClient) + AgentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsAsyncClient), ) def test_agents_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(AgentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -252,7 +512,9 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -282,15 +544,23 @@ def test_agents_client_client_options(client_class, transport_class, transport_n # 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") @@ -300,7 +570,9 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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", @@ -318,7 +590,9 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -350,10 +624,14 @@ def test_agents_client_client_options(client_class, transport_class, transport_n ], ) @mock.patch.object( - AgentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AgentsClient) + AgentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsClient), ) @mock.patch.object( - AgentsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AgentsAsyncClient) + AgentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_agents_client_mtls_env_auto( @@ -376,7 +654,9 @@ def test_agents_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 @@ -408,7 +688,9 @@ def test_agents_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 @@ -442,7 +724,9 @@ def test_agents_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, @@ -526,6 +810,116 @@ def test_agents_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", [AgentsClient, AgentsAsyncClient]) +@mock.patch.object( + AgentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsClient), +) +@mock.patch.object( + AgentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsAsyncClient), +) +def test_agents_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = AgentsClient._DEFAULT_UNIVERSE + default_endpoint = AgentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AgentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -548,7 +942,9 @@ def test_agents_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, @@ -583,7 +979,9 @@ def test_agents_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, @@ -636,7 +1034,9 @@ def test_agents_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, @@ -653,8 +1053,8 @@ def test_agents_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -686,7 +1086,7 @@ def test_agents_client_create_channel_credentials_file( ) def test_get_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -740,7 +1140,7 @@ def test_get_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -757,7 +1157,7 @@ async def test_get_agent_async( transport: str = "grpc_asyncio", request_type=agent.GetAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -816,7 +1216,7 @@ async def test_get_agent_async_from_dict(): def test_get_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -846,7 +1246,7 @@ def test_get_agent_field_headers(): @pytest.mark.asyncio async def test_get_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -875,7 +1275,7 @@ async def test_get_agent_field_headers_async(): def test_get_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -899,7 +1299,7 @@ def test_get_agent_flattened(): def test_get_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -914,7 +1314,7 @@ def test_get_agent_flattened_error(): @pytest.mark.asyncio async def test_get_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -941,7 +1341,7 @@ async def test_get_agent_flattened_async(): @pytest.mark.asyncio async def test_get_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -962,7 +1362,7 @@ async def test_get_agent_flattened_error_async(): ) def test_set_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1016,7 +1416,7 @@ def test_set_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1033,7 +1433,7 @@ async def test_set_agent_async( transport: str = "grpc_asyncio", request_type=gcd_agent.SetAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1092,7 +1492,7 @@ async def test_set_agent_async_from_dict(): def test_set_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1122,7 +1522,7 @@ def test_set_agent_field_headers(): @pytest.mark.asyncio async def test_set_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1151,7 +1551,7 @@ async def test_set_agent_field_headers_async(): def test_set_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1175,7 +1575,7 @@ def test_set_agent_flattened(): def test_set_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1190,7 +1590,7 @@ def test_set_agent_flattened_error(): @pytest.mark.asyncio async def test_set_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1217,7 +1617,7 @@ async def test_set_agent_flattened_async(): @pytest.mark.asyncio async def test_set_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1238,7 +1638,7 @@ async def test_set_agent_flattened_error_async(): ) def test_delete_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1265,7 +1665,7 @@ def test_delete_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1282,7 +1682,7 @@ async def test_delete_agent_async( transport: str = "grpc_asyncio", request_type=agent.DeleteAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1312,7 +1712,7 @@ async def test_delete_agent_async_from_dict(): def test_delete_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1342,7 +1742,7 @@ def test_delete_agent_field_headers(): @pytest.mark.asyncio async def test_delete_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1371,7 +1771,7 @@ async def test_delete_agent_field_headers_async(): def test_delete_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1395,7 +1795,7 @@ def test_delete_agent_flattened(): def test_delete_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1410,7 +1810,7 @@ def test_delete_agent_flattened_error(): @pytest.mark.asyncio async def test_delete_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1437,7 +1837,7 @@ async def test_delete_agent_flattened_async(): @pytest.mark.asyncio async def test_delete_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1458,7 +1858,7 @@ async def test_delete_agent_flattened_error_async(): ) def test_search_agents(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1488,7 +1888,7 @@ def test_search_agents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1505,7 +1905,7 @@ async def test_search_agents_async( transport: str = "grpc_asyncio", request_type=agent.SearchAgentsRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1540,7 +1940,7 @@ async def test_search_agents_async_from_dict(): def test_search_agents_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1570,7 +1970,7 @@ def test_search_agents_field_headers(): @pytest.mark.asyncio async def test_search_agents_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1601,7 +2001,7 @@ async def test_search_agents_field_headers_async(): def test_search_agents_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1625,7 +2025,7 @@ def test_search_agents_flattened(): def test_search_agents_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1640,7 +2040,7 @@ def test_search_agents_flattened_error(): @pytest.mark.asyncio async def test_search_agents_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1669,7 +2069,7 @@ async def test_search_agents_flattened_async(): @pytest.mark.asyncio async def test_search_agents_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1683,7 +2083,7 @@ async def test_search_agents_flattened_error_async(): def test_search_agents_pager(transport_name: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1733,7 +2133,7 @@ def test_search_agents_pager(transport_name: str = "grpc"): def test_search_agents_pages(transport_name: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1775,7 +2175,7 @@ def test_search_agents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_search_agents_async_pager(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1825,7 +2225,7 @@ async def test_search_agents_async_pager(): @pytest.mark.asyncio async def test_search_agents_async_pages(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1880,7 +2280,7 @@ async def test_search_agents_async_pages(): ) def test_train_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1907,7 +2307,7 @@ def test_train_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1924,7 +2324,7 @@ async def test_train_agent_async( transport: str = "grpc_asyncio", request_type=agent.TrainAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1956,7 +2356,7 @@ async def test_train_agent_async_from_dict(): def test_train_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1986,7 +2386,7 @@ def test_train_agent_field_headers(): @pytest.mark.asyncio async def test_train_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2017,7 +2417,7 @@ async def test_train_agent_field_headers_async(): def test_train_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2041,7 +2441,7 @@ def test_train_agent_flattened(): def test_train_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2056,7 +2456,7 @@ def test_train_agent_flattened_error(): @pytest.mark.asyncio async def test_train_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2085,7 +2485,7 @@ async def test_train_agent_flattened_async(): @pytest.mark.asyncio async def test_train_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2106,7 +2506,7 @@ async def test_train_agent_flattened_error_async(): ) def test_export_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2133,7 +2533,7 @@ def test_export_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2150,7 +2550,7 @@ async def test_export_agent_async( transport: str = "grpc_asyncio", request_type=agent.ExportAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2182,7 +2582,7 @@ async def test_export_agent_async_from_dict(): def test_export_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2212,7 +2612,7 @@ def test_export_agent_field_headers(): @pytest.mark.asyncio async def test_export_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2243,7 +2643,7 @@ async def test_export_agent_field_headers_async(): def test_export_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2267,7 +2667,7 @@ def test_export_agent_flattened(): def test_export_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2282,7 +2682,7 @@ def test_export_agent_flattened_error(): @pytest.mark.asyncio async def test_export_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2311,7 +2711,7 @@ async def test_export_agent_flattened_async(): @pytest.mark.asyncio async def test_export_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2332,7 +2732,7 @@ async def test_export_agent_flattened_error_async(): ) def test_import_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2359,7 +2759,7 @@ def test_import_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2376,7 +2776,7 @@ async def test_import_agent_async( transport: str = "grpc_asyncio", request_type=agent.ImportAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2408,7 +2808,7 @@ async def test_import_agent_async_from_dict(): def test_import_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2438,7 +2838,7 @@ def test_import_agent_field_headers(): @pytest.mark.asyncio async def test_import_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2476,7 +2876,7 @@ async def test_import_agent_field_headers_async(): ) def test_restore_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2503,7 +2903,7 @@ def test_restore_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2520,7 +2920,7 @@ async def test_restore_agent_async( transport: str = "grpc_asyncio", request_type=agent.RestoreAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2552,7 +2952,7 @@ async def test_restore_agent_async_from_dict(): def test_restore_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2582,7 +2982,7 @@ def test_restore_agent_field_headers(): @pytest.mark.asyncio async def test_restore_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2620,7 +3020,7 @@ async def test_restore_agent_field_headers_async(): ) def test_get_validation_result(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2649,7 +3049,7 @@ def test_get_validation_result_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2668,7 +3068,7 @@ async def test_get_validation_result_async( transport: str = "grpc_asyncio", request_type=agent.GetValidationResultRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2702,7 +3102,7 @@ async def test_get_validation_result_async_from_dict(): def test_get_validation_result_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2734,7 +3134,7 @@ def test_get_validation_result_field_headers(): @pytest.mark.asyncio async def test_get_validation_result_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2774,7 +3174,7 @@ async def test_get_validation_result_field_headers_async(): ) def test_get_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2847,7 +3247,7 @@ def test_get_agent_rest_required_fields(request_type=agent.GetAgentRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2856,7 +3256,7 @@ def test_get_agent_rest_required_fields(request_type=agent.GetAgentRequest): jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2865,7 +3265,7 @@ def test_get_agent_rest_required_fields(request_type=agent.GetAgentRequest): assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2907,7 +3307,7 @@ def test_get_agent_rest_required_fields(request_type=agent.GetAgentRequest): def test_get_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_agent._get_unset_required_fields({}) @@ -2917,7 +3317,7 @@ def test_get_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -2969,7 +3369,7 @@ def test_get_agent_rest_bad_request( transport: str = "rest", request_type=agent.GetAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2991,7 +3391,7 @@ def test_get_agent_rest_bad_request( def test_get_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3031,7 +3431,7 @@ def test_get_agent_rest_flattened(): def test_get_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3046,7 +3446,7 @@ def test_get_agent_rest_flattened_error(transport: str = "rest"): def test_get_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3059,7 +3459,7 @@ def test_get_agent_rest_error(): ) def test_set_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3215,14 +3615,14 @@ def test_set_agent_rest_required_fields(request_type=gcd_agent.SetAgentRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_agent._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3231,7 +3631,7 @@ def test_set_agent_rest_required_fields(request_type=gcd_agent.SetAgentRequest): # verify required fields with non-default values are left alone client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3274,7 +3674,7 @@ def test_set_agent_rest_required_fields(request_type=gcd_agent.SetAgentRequest): def test_set_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.set_agent._get_unset_required_fields({}) @@ -3284,7 +3684,7 @@ def test_set_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_set_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -3336,7 +3736,7 @@ def test_set_agent_rest_bad_request( transport: str = "rest", request_type=gcd_agent.SetAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3358,7 +3758,7 @@ def test_set_agent_rest_bad_request( def test_set_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3398,7 +3798,7 @@ def test_set_agent_rest_flattened(): def test_set_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3413,7 +3813,7 @@ def test_set_agent_rest_flattened_error(transport: str = "rest"): def test_set_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3426,7 +3826,7 @@ def test_set_agent_rest_error(): ) def test_delete_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3470,7 +3870,7 @@ def test_delete_agent_rest_required_fields(request_type=agent.DeleteAgentRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3479,7 +3879,7 @@ def test_delete_agent_rest_required_fields(request_type=agent.DeleteAgentRequest jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3488,7 +3888,7 @@ def test_delete_agent_rest_required_fields(request_type=agent.DeleteAgentRequest assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3527,7 +3927,7 @@ def test_delete_agent_rest_required_fields(request_type=agent.DeleteAgentRequest def test_delete_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_agent._get_unset_required_fields({}) @@ -3537,7 +3937,7 @@ def test_delete_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -3583,7 +3983,7 @@ def test_delete_agent_rest_bad_request( transport: str = "rest", request_type=agent.DeleteAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3605,7 +4005,7 @@ def test_delete_agent_rest_bad_request( def test_delete_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3643,7 +4043,7 @@ def test_delete_agent_rest_flattened(): def test_delete_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3658,7 +4058,7 @@ def test_delete_agent_rest_flattened_error(transport: str = "rest"): def test_delete_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3671,7 +4071,7 @@ def test_delete_agent_rest_error(): ) def test_search_agents_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3720,7 +4120,7 @@ def test_search_agents_rest_required_fields(request_type=agent.SearchAgentsReque # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_agents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3729,7 +4129,7 @@ def test_search_agents_rest_required_fields(request_type=agent.SearchAgentsReque jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_agents._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3745,7 +4145,7 @@ def test_search_agents_rest_required_fields(request_type=agent.SearchAgentsReque assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3787,7 +4187,7 @@ def test_search_agents_rest_required_fields(request_type=agent.SearchAgentsReque def test_search_agents_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search_agents._get_unset_required_fields({}) @@ -3805,7 +4205,7 @@ def test_search_agents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_agents_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -3859,7 +4259,7 @@ def test_search_agents_rest_bad_request( transport: str = "rest", request_type=agent.SearchAgentsRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3881,7 +4281,7 @@ def test_search_agents_rest_bad_request( def test_search_agents_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3921,7 +4321,7 @@ def test_search_agents_rest_flattened(): def test_search_agents_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3936,7 +4336,7 @@ def test_search_agents_rest_flattened_error(transport: str = "rest"): def test_search_agents_rest_pager(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4004,7 +4404,7 @@ def test_search_agents_rest_pager(transport: str = "rest"): ) def test_train_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4048,7 +4448,7 @@ def test_train_agent_rest_required_fields(request_type=agent.TrainAgentRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4057,7 +4457,7 @@ def test_train_agent_rest_required_fields(request_type=agent.TrainAgentRequest): jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4066,7 +4466,7 @@ def test_train_agent_rest_required_fields(request_type=agent.TrainAgentRequest): assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4106,7 +4506,7 @@ def test_train_agent_rest_required_fields(request_type=agent.TrainAgentRequest): def test_train_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.train_agent._get_unset_required_fields({}) @@ -4116,7 +4516,7 @@ def test_train_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_train_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -4172,7 +4572,7 @@ def test_train_agent_rest_bad_request( transport: str = "rest", request_type=agent.TrainAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4194,7 +4594,7 @@ def test_train_agent_rest_bad_request( def test_train_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4232,7 +4632,7 @@ def test_train_agent_rest_flattened(): def test_train_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4247,7 +4647,7 @@ def test_train_agent_rest_flattened_error(transport: str = "rest"): def test_train_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4260,7 +4660,7 @@ def test_train_agent_rest_error(): ) def test_export_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4305,7 +4705,7 @@ def test_export_agent_rest_required_fields(request_type=agent.ExportAgentRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4315,7 +4715,7 @@ def test_export_agent_rest_required_fields(request_type=agent.ExportAgentRequest jsonified_request["agentUri"] = "agent_uri_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4326,7 +4726,7 @@ def test_export_agent_rest_required_fields(request_type=agent.ExportAgentRequest assert jsonified_request["agentUri"] == "agent_uri_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4366,7 +4766,7 @@ def test_export_agent_rest_required_fields(request_type=agent.ExportAgentRequest def test_export_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.export_agent._get_unset_required_fields({}) @@ -4384,7 +4784,7 @@ def test_export_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_export_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -4440,7 +4840,7 @@ def test_export_agent_rest_bad_request( transport: str = "rest", request_type=agent.ExportAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4462,7 +4862,7 @@ def test_export_agent_rest_bad_request( def test_export_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4500,7 +4900,7 @@ def test_export_agent_rest_flattened(): def test_export_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4515,7 +4915,7 @@ def test_export_agent_rest_flattened_error(transport: str = "rest"): def test_export_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4528,7 +4928,7 @@ def test_export_agent_rest_error(): ) def test_import_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4572,7 +4972,7 @@ def test_import_agent_rest_required_fields(request_type=agent.ImportAgentRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4581,7 +4981,7 @@ def test_import_agent_rest_required_fields(request_type=agent.ImportAgentRequest jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4590,7 +4990,7 @@ def test_import_agent_rest_required_fields(request_type=agent.ImportAgentRequest assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4630,7 +5030,7 @@ def test_import_agent_rest_required_fields(request_type=agent.ImportAgentRequest def test_import_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_agent._get_unset_required_fields({}) @@ -4640,7 +5040,7 @@ def test_import_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -4696,7 +5096,7 @@ def test_import_agent_rest_bad_request( transport: str = "rest", request_type=agent.ImportAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4718,7 +5118,7 @@ def test_import_agent_rest_bad_request( def test_import_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4731,7 +5131,7 @@ def test_import_agent_rest_error(): ) def test_restore_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4775,7 +5175,7 @@ def test_restore_agent_rest_required_fields(request_type=agent.RestoreAgentReque # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).restore_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4784,7 +5184,7 @@ def test_restore_agent_rest_required_fields(request_type=agent.RestoreAgentReque jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).restore_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4793,7 +5193,7 @@ def test_restore_agent_rest_required_fields(request_type=agent.RestoreAgentReque assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4833,7 +5233,7 @@ def test_restore_agent_rest_required_fields(request_type=agent.RestoreAgentReque def test_restore_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.restore_agent._get_unset_required_fields({}) @@ -4843,7 +5243,7 @@ def test_restore_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_restore_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -4899,7 +5299,7 @@ def test_restore_agent_rest_bad_request( transport: str = "rest", request_type=agent.RestoreAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4921,7 +5321,7 @@ def test_restore_agent_rest_bad_request( def test_restore_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4934,7 +5334,7 @@ def test_restore_agent_rest_error(): ) def test_get_validation_result_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4982,7 +5382,7 @@ def test_get_validation_result_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_validation_result._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4991,7 +5391,7 @@ def test_get_validation_result_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_validation_result._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("language_code",)) @@ -5002,7 +5402,7 @@ def test_get_validation_result_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5044,7 +5444,7 @@ def test_get_validation_result_rest_required_fields( def test_get_validation_result_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_validation_result._get_unset_required_fields({}) @@ -5054,7 +5454,7 @@ def test_get_validation_result_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_validation_result_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -5110,7 +5510,7 @@ def test_get_validation_result_rest_bad_request( transport: str = "rest", request_type=agent.GetValidationResultRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5132,24 +5532,24 @@ def test_get_validation_result_rest_bad_request( def test_get_validation_result_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AgentsClient( @@ -5159,7 +5559,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5170,16 +5570,17 @@ 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 = AgentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AgentsClient( @@ -5191,7 +5592,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = AgentsClient(transport=transport) assert client.transport is transport @@ -5200,13 +5601,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.AgentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5223,7 +5624,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5237,7 +5638,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = AgentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5245,7 +5646,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5257,7 +5658,7 @@ def test_agents_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.AgentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5269,7 +5670,7 @@ def test_agents_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AgentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5319,7 +5720,7 @@ def test_agents_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.agents.transports.AgentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AgentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5341,7 +5742,7 @@ def test_agents_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.agents.transports.AgentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AgentsTransport() adc.assert_called_once() @@ -5349,7 +5750,7 @@ def test_agents_base_transport_with_adc(): def test_agents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) AgentsClient() adc.assert_called_once_with( scopes=None, @@ -5372,7 +5773,7 @@ def test_agents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5422,7 +5823,7 @@ def test_agents_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5450,7 +5851,7 @@ def test_agents_transport_create_channel(transport_class, grpc_helpers): [transports.AgentsGrpcTransport, transports.AgentsGrpcAsyncIOTransport], ) def test_agents_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5488,7 +5889,7 @@ def test_agents_grpc_transport_client_cert_source_for_mtls(transport_class): def test_agents_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5500,7 +5901,7 @@ def test_agents_http_transport_client_cert_source_for_mtls(): def test_agents_rest_lro_client(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5525,7 +5926,7 @@ def test_agents_rest_lro_client(): ) def test_agents_host_no_port(transport_name): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -5548,7 +5949,7 @@ def test_agents_host_no_port(transport_name): ) def test_agents_host_with_port(transport_name): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -5568,8 +5969,8 @@ def test_agents_host_with_port(transport_name): ], ) def test_agents_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = AgentsClient( credentials=creds1, transport=transport_name, @@ -5652,7 +6053,7 @@ def test_agents_transport_channel_mtls_with_client_cert_source(transport_class): mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5727,7 +6128,7 @@ def test_agents_transport_channel_mtls_with_adc(transport_class): def test_agents_grpc_lro_client(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5744,7 +6145,7 @@ def test_agents_grpc_lro_client(): def test_agents_grpc_lro_async_client(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -5889,7 +6290,7 @@ def test_client_with_default_client_info(): transports.AgentsTransport, "_prep_wrapped_messages" ) as prep: client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5899,7 +6300,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = AgentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5908,7 +6309,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5923,7 +6324,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5953,7 +6354,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -5981,7 +6382,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6009,7 +6410,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6037,7 +6438,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6067,7 +6468,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6095,7 +6496,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6125,7 +6526,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6153,7 +6554,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6181,7 +6582,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6207,7 +6608,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6232,7 +6633,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6256,7 +6657,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6285,7 +6686,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6312,7 +6713,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6330,7 +6731,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6346,7 +6747,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6371,7 +6772,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6397,7 +6798,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6426,7 +6827,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6455,7 +6856,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6473,7 +6874,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6491,7 +6892,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6516,7 +6917,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6542,7 +6943,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6571,7 +6972,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6600,7 +7001,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6618,7 +7019,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6636,7 +7037,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6661,7 +7062,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6687,7 +7088,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6716,7 +7117,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6745,7 +7146,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6763,7 +7164,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6781,7 +7182,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6806,7 +7207,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6831,7 +7232,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = AgentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = AgentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -6858,7 +7259,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = AgentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = AgentsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -6886,7 +7287,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6904,7 +7305,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6928,7 +7329,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -6945,7 +7346,7 @@ def test_client_ctx(): ] for transport in transports: client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -6976,7 +7377,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_answer_records.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_answer_records.py index 69090fed7d80..0a9caf7f4e0b 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_answer_records.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_answer_records.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -73,6 +73,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -102,6 +125,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert AnswerRecordsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert AnswerRecordsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert AnswerRecordsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + AnswerRecordsClient._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 AnswerRecordsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert AnswerRecordsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert AnswerRecordsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + AnswerRecordsClient._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 AnswerRecordsClient._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 AnswerRecordsClient._get_client_cert_source(None, False) is None + assert ( + AnswerRecordsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + AnswerRecordsClient._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 ( + AnswerRecordsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + AnswerRecordsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + AnswerRecordsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsClient), +) +@mock.patch.object( + AnswerRecordsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = AnswerRecordsClient._DEFAULT_UNIVERSE + default_endpoint = AnswerRecordsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AnswerRecordsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + AnswerRecordsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + AnswerRecordsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AnswerRecordsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + AnswerRecordsClient._get_api_endpoint(None, None, default_universe, "always") + == AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AnswerRecordsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AnswerRecordsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + AnswerRecordsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + AnswerRecordsClient._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 ( + AnswerRecordsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + AnswerRecordsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + AnswerRecordsClient._get_universe_domain(None, None) + == AnswerRecordsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + AnswerRecordsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (AnswerRecordsClient, transports.AnswerRecordsGrpcTransport, "grpc"), + (AnswerRecordsClient, transports.AnswerRecordsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -111,7 +391,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_answer_records_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -163,7 +443,7 @@ def test_answer_records_client_service_account_always_use_jwt( ], ) def test_answer_records_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -213,20 +493,22 @@ def test_answer_records_client_get_transport_class(): ) @mock.patch.object( AnswerRecordsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AnswerRecordsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsClient), ) @mock.patch.object( AnswerRecordsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AnswerRecordsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsAsyncClient), ) def test_answer_records_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(AnswerRecordsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -261,7 +543,9 @@ def test_answer_records_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, @@ -291,15 +575,23 @@ def test_answer_records_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") @@ -309,7 +601,9 @@ def test_answer_records_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", @@ -327,7 +621,9 @@ def test_answer_records_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, @@ -360,13 +656,13 @@ def test_answer_records_client_client_options( ) @mock.patch.object( AnswerRecordsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AnswerRecordsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsClient), ) @mock.patch.object( AnswerRecordsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AnswerRecordsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_answer_records_client_mtls_env_auto( @@ -389,7 +685,9 @@ def test_answer_records_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 @@ -421,7 +719,9 @@ def test_answer_records_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 @@ -455,7 +755,9 @@ def test_answer_records_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, @@ -545,6 +847,118 @@ def test_answer_records_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", [AnswerRecordsClient, AnswerRecordsAsyncClient] +) +@mock.patch.object( + AnswerRecordsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsClient), +) +@mock.patch.object( + AnswerRecordsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsAsyncClient), +) +def test_answer_records_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = AnswerRecordsClient._DEFAULT_UNIVERSE + default_endpoint = AnswerRecordsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AnswerRecordsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -571,7 +985,9 @@ def test_answer_records_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, @@ -611,7 +1027,9 @@ def test_answer_records_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, @@ -671,7 +1089,9 @@ def test_answer_records_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, @@ -688,8 +1108,8 @@ def test_answer_records_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -721,7 +1141,7 @@ def test_answer_records_client_create_channel_credentials_file( ) def test_list_answer_records(request_type, transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -753,7 +1173,7 @@ def test_list_answer_records_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -772,7 +1192,7 @@ async def test_list_answer_records_async( transport: str = "grpc_asyncio", request_type=answer_record.ListAnswerRecordsRequest ): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -809,7 +1229,7 @@ async def test_list_answer_records_async_from_dict(): def test_list_answer_records_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -841,7 +1261,7 @@ def test_list_answer_records_field_headers(): @pytest.mark.asyncio async def test_list_answer_records_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -874,7 +1294,7 @@ async def test_list_answer_records_field_headers_async(): def test_list_answer_records_flattened(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -900,7 +1320,7 @@ def test_list_answer_records_flattened(): def test_list_answer_records_flattened_error(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -915,7 +1335,7 @@ def test_list_answer_records_flattened_error(): @pytest.mark.asyncio async def test_list_answer_records_flattened_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -946,7 +1366,7 @@ async def test_list_answer_records_flattened_async(): @pytest.mark.asyncio async def test_list_answer_records_flattened_error_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -960,7 +1380,7 @@ async def test_list_answer_records_flattened_error_async(): def test_list_answer_records_pager(transport_name: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1012,7 +1432,7 @@ def test_list_answer_records_pager(transport_name: str = "grpc"): def test_list_answer_records_pages(transport_name: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1056,7 +1476,7 @@ def test_list_answer_records_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_answer_records_async_pager(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1108,7 +1528,7 @@ async def test_list_answer_records_async_pager(): @pytest.mark.asyncio async def test_list_answer_records_async_pages(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1165,7 +1585,7 @@ async def test_list_answer_records_async_pages(): ) def test_update_answer_record(request_type, transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1197,7 +1617,7 @@ def test_update_answer_record_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1217,7 +1637,7 @@ async def test_update_answer_record_async( request_type=gcd_answer_record.UpdateAnswerRecordRequest, ): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1254,7 +1674,7 @@ async def test_update_answer_record_async_from_dict(): def test_update_answer_record_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1286,7 +1706,7 @@ def test_update_answer_record_field_headers(): @pytest.mark.asyncio async def test_update_answer_record_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1319,7 +1739,7 @@ async def test_update_answer_record_field_headers_async(): def test_update_answer_record_flattened(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1349,7 +1769,7 @@ def test_update_answer_record_flattened(): def test_update_answer_record_flattened_error(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1365,7 +1785,7 @@ def test_update_answer_record_flattened_error(): @pytest.mark.asyncio async def test_update_answer_record_flattened_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1400,7 +1820,7 @@ async def test_update_answer_record_flattened_async(): @pytest.mark.asyncio async def test_update_answer_record_flattened_error_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1422,7 +1842,7 @@ async def test_update_answer_record_flattened_error_async(): ) def test_list_answer_records_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1473,7 +1893,7 @@ def test_list_answer_records_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_answer_records._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1482,7 +1902,7 @@ def test_list_answer_records_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_answer_records._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -1499,7 +1919,7 @@ def test_list_answer_records_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1541,7 +1961,7 @@ def test_list_answer_records_rest_required_fields( def test_list_answer_records_rest_unset_required_fields(): transport = transports.AnswerRecordsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_answer_records._get_unset_required_fields({}) @@ -1560,7 +1980,7 @@ def test_list_answer_records_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_answer_records_rest_interceptors(null_interceptor): transport = transports.AnswerRecordsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AnswerRecordsRestInterceptor(), @@ -1618,7 +2038,7 @@ def test_list_answer_records_rest_bad_request( transport: str = "rest", request_type=answer_record.ListAnswerRecordsRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1640,7 +2060,7 @@ def test_list_answer_records_rest_bad_request( def test_list_answer_records_rest_flattened(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1680,7 +2100,7 @@ def test_list_answer_records_rest_flattened(): def test_list_answer_records_rest_flattened_error(transport: str = "rest"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1695,7 +2115,7 @@ def test_list_answer_records_rest_flattened_error(transport: str = "rest"): def test_list_answer_records_rest_pager(transport: str = "rest"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1765,7 +2185,7 @@ def test_list_answer_records_rest_pager(transport: str = "rest"): ) def test_update_answer_record_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2137,14 +2557,14 @@ def test_update_answer_record_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_answer_record._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_answer_record._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -2153,7 +2573,7 @@ def test_update_answer_record_rest_required_fields( # verify required fields with non-default values are left alone client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2196,7 +2616,7 @@ def test_update_answer_record_rest_required_fields( def test_update_answer_record_rest_unset_required_fields(): transport = transports.AnswerRecordsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_answer_record._get_unset_required_fields({}) @@ -2214,7 +2634,7 @@ def test_update_answer_record_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_answer_record_rest_interceptors(null_interceptor): transport = transports.AnswerRecordsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AnswerRecordsRestInterceptor(), @@ -2272,7 +2692,7 @@ def test_update_answer_record_rest_bad_request( transport: str = "rest", request_type=gcd_answer_record.UpdateAnswerRecordRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2294,7 +2714,7 @@ def test_update_answer_record_rest_bad_request( def test_update_answer_record_rest_flattened(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2339,7 +2759,7 @@ def test_update_answer_record_rest_flattened(): def test_update_answer_record_rest_flattened_error(transport: str = "rest"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2355,24 +2775,24 @@ def test_update_answer_record_rest_flattened_error(transport: str = "rest"): def test_update_answer_record_rest_error(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AnswerRecordsClient( @@ -2382,7 +2802,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -2393,16 +2813,17 @@ 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 = AnswerRecordsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AnswerRecordsClient( @@ -2414,7 +2835,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = AnswerRecordsClient(transport=transport) assert client.transport is transport @@ -2423,13 +2844,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.AnswerRecordsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -2446,7 +2867,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -2460,7 +2881,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = AnswerRecordsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -2468,7 +2889,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -2480,7 +2901,7 @@ def test_answer_records_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.AnswerRecordsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -2492,7 +2913,7 @@ def test_answer_records_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AnswerRecordsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -2530,7 +2951,7 @@ def test_answer_records_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AnswerRecordsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2552,7 +2973,7 @@ def test_answer_records_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AnswerRecordsTransport() adc.assert_called_once() @@ -2560,7 +2981,7 @@ def test_answer_records_base_transport_with_adc(): def test_answer_records_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) AnswerRecordsClient() adc.assert_called_once_with( scopes=None, @@ -2583,7 +3004,7 @@ def test_answer_records_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2633,7 +3054,7 @@ def test_answer_records_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2664,7 +3085,7 @@ def test_answer_records_transport_create_channel(transport_class, grpc_helpers): ], ) def test_answer_records_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2702,7 +3123,7 @@ def test_answer_records_grpc_transport_client_cert_source_for_mtls(transport_cla def test_answer_records_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -2722,7 +3143,7 @@ def test_answer_records_http_transport_client_cert_source_for_mtls(): ) def test_answer_records_host_no_port(transport_name): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -2745,7 +3166,7 @@ def test_answer_records_host_no_port(transport_name): ) def test_answer_records_host_with_port(transport_name): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -2765,8 +3186,8 @@ def test_answer_records_host_with_port(transport_name): ], ) def test_answer_records_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = AnswerRecordsClient( credentials=creds1, transport=transport_name, @@ -2831,7 +3252,7 @@ def test_answer_records_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -3089,7 +3510,7 @@ def test_client_with_default_client_info(): transports.AnswerRecordsTransport, "_prep_wrapped_messages" ) as prep: client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3099,7 +3520,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = AnswerRecordsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3108,7 +3529,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -3123,7 +3544,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3153,7 +3574,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -3181,7 +3602,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3209,7 +3630,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -3237,7 +3658,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3267,7 +3688,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -3295,7 +3716,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3325,7 +3746,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -3353,7 +3774,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3381,7 +3802,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -3407,7 +3828,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3432,7 +3853,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3456,7 +3877,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3485,7 +3906,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3512,7 +3933,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -3530,7 +3951,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -3546,7 +3967,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3571,7 +3992,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3597,7 +4018,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3626,7 +4047,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3655,7 +4076,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3673,7 +4094,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3691,7 +4112,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3716,7 +4137,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3742,7 +4163,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3771,7 +4192,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3800,7 +4221,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3818,7 +4239,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3836,7 +4257,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3861,7 +4282,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3887,7 +4308,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3916,7 +4337,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3945,7 +4366,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3963,7 +4384,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3981,7 +4402,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4006,7 +4427,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4031,7 +4452,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = AnswerRecordsClient(credentials=ga_credentials.AnonymousCredentials()) + client = AnswerRecordsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -4058,7 +4479,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = AnswerRecordsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = AnswerRecordsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -4086,7 +4509,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -4104,7 +4527,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -4128,7 +4551,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -4145,7 +4568,7 @@ def test_client_ctx(): ] for transport in transports: client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -4176,7 +4599,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_contexts.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_contexts.py index 02786df339b0..ef832d36196b 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_contexts.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_contexts.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -71,6 +71,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -95,6 +118,244 @@ def test__get_default_mtls_endpoint(): assert ContextsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert ContextsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ContextsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ContextsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ContextsClient._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 ContextsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ContextsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ContextsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ContextsClient._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 ContextsClient._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 ContextsClient._get_client_cert_source(None, False) is None + assert ( + ContextsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + ContextsClient._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 ( + ContextsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ContextsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ContextsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsClient), +) +@mock.patch.object( + ContextsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ContextsClient._DEFAULT_UNIVERSE + default_endpoint = ContextsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ContextsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ContextsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ContextsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ContextsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ContextsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + ContextsClient._get_api_endpoint(None, None, default_universe, "always") + == ContextsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ContextsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ContextsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ContextsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ContextsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ContextsClient._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 ( + ContextsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + ContextsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ContextsClient._get_universe_domain(None, None) + == ContextsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ContextsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (ContextsClient, transports.ContextsGrpcTransport, "grpc"), + (ContextsClient, transports.ContextsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -104,7 +365,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_contexts_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -156,7 +417,7 @@ def test_contexts_client_service_account_always_use_jwt( ], ) def test_contexts_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -201,17 +462,21 @@ def test_contexts_client_get_transport_class(): ], ) @mock.patch.object( - ContextsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ContextsClient) + ContextsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsClient), ) @mock.patch.object( ContextsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ContextsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsAsyncClient), ) def test_contexts_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(ContextsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -246,7 +511,9 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -276,15 +543,23 @@ def test_contexts_client_client_options(client_class, transport_class, transport # 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") @@ -294,7 +569,9 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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", @@ -312,7 +589,9 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -344,12 +623,14 @@ def test_contexts_client_client_options(client_class, transport_class, transport ], ) @mock.patch.object( - ContextsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ContextsClient) + ContextsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsClient), ) @mock.patch.object( ContextsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ContextsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_contexts_client_mtls_env_auto( @@ -372,7 +653,9 @@ def test_contexts_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 @@ -404,7 +687,9 @@ def test_contexts_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 @@ -438,7 +723,9 @@ def test_contexts_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, @@ -524,6 +811,116 @@ def test_contexts_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", [ContextsClient, ContextsAsyncClient]) +@mock.patch.object( + ContextsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsClient), +) +@mock.patch.object( + ContextsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsAsyncClient), +) +def test_contexts_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ContextsClient._DEFAULT_UNIVERSE + default_endpoint = ContextsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ContextsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -546,7 +943,9 @@ def test_contexts_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, @@ -581,7 +980,9 @@ def test_contexts_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, @@ -634,7 +1035,9 @@ def test_contexts_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, @@ -651,8 +1054,8 @@ def test_contexts_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -684,7 +1087,7 @@ def test_contexts_client_create_channel_credentials_file( ) def test_list_contexts(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -714,7 +1117,7 @@ def test_list_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -731,7 +1134,7 @@ async def test_list_contexts_async( transport: str = "grpc_asyncio", request_type=context.ListContextsRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -766,7 +1169,7 @@ async def test_list_contexts_async_from_dict(): def test_list_contexts_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -796,7 +1199,7 @@ def test_list_contexts_field_headers(): @pytest.mark.asyncio async def test_list_contexts_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -827,7 +1230,7 @@ async def test_list_contexts_field_headers_async(): def test_list_contexts_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -851,7 +1254,7 @@ def test_list_contexts_flattened(): def test_list_contexts_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -866,7 +1269,7 @@ def test_list_contexts_flattened_error(): @pytest.mark.asyncio async def test_list_contexts_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -895,7 +1298,7 @@ async def test_list_contexts_flattened_async(): @pytest.mark.asyncio async def test_list_contexts_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -909,7 +1312,7 @@ async def test_list_contexts_flattened_error_async(): def test_list_contexts_pager(transport_name: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -959,7 +1362,7 @@ def test_list_contexts_pager(transport_name: str = "grpc"): def test_list_contexts_pages(transport_name: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1001,7 +1404,7 @@ def test_list_contexts_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_contexts_async_pager(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1051,7 +1454,7 @@ async def test_list_contexts_async_pager(): @pytest.mark.asyncio async def test_list_contexts_async_pages(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1106,7 +1509,7 @@ async def test_list_contexts_async_pages(): ) def test_get_context(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1138,7 +1541,7 @@ def test_get_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1155,7 +1558,7 @@ async def test_get_context_async( transport: str = "grpc_asyncio", request_type=context.GetContextRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1192,7 +1595,7 @@ async def test_get_context_async_from_dict(): def test_get_context_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1222,7 +1625,7 @@ def test_get_context_field_headers(): @pytest.mark.asyncio async def test_get_context_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1251,7 +1654,7 @@ async def test_get_context_field_headers_async(): def test_get_context_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1275,7 +1678,7 @@ def test_get_context_flattened(): def test_get_context_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1290,7 +1693,7 @@ def test_get_context_flattened_error(): @pytest.mark.asyncio async def test_get_context_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1317,7 +1720,7 @@ async def test_get_context_flattened_async(): @pytest.mark.asyncio async def test_get_context_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1338,7 +1741,7 @@ async def test_get_context_flattened_error_async(): ) def test_create_context(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1370,7 +1773,7 @@ def test_create_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1387,7 +1790,7 @@ async def test_create_context_async( transport: str = "grpc_asyncio", request_type=gcd_context.CreateContextRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1424,7 +1827,7 @@ async def test_create_context_async_from_dict(): def test_create_context_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1454,7 +1857,7 @@ def test_create_context_field_headers(): @pytest.mark.asyncio async def test_create_context_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1483,7 +1886,7 @@ async def test_create_context_field_headers_async(): def test_create_context_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1511,7 +1914,7 @@ def test_create_context_flattened(): def test_create_context_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1527,7 +1930,7 @@ def test_create_context_flattened_error(): @pytest.mark.asyncio async def test_create_context_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1558,7 +1961,7 @@ async def test_create_context_flattened_async(): @pytest.mark.asyncio async def test_create_context_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1580,7 +1983,7 @@ async def test_create_context_flattened_error_async(): ) def test_update_context(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1612,7 +2015,7 @@ def test_update_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1629,7 +2032,7 @@ async def test_update_context_async( transport: str = "grpc_asyncio", request_type=gcd_context.UpdateContextRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1666,7 +2069,7 @@ async def test_update_context_async_from_dict(): def test_update_context_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1696,7 +2099,7 @@ def test_update_context_field_headers(): @pytest.mark.asyncio async def test_update_context_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1725,7 +2128,7 @@ async def test_update_context_field_headers_async(): def test_update_context_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1753,7 +2156,7 @@ def test_update_context_flattened(): def test_update_context_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1769,7 +2172,7 @@ def test_update_context_flattened_error(): @pytest.mark.asyncio async def test_update_context_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1800,7 +2203,7 @@ async def test_update_context_flattened_async(): @pytest.mark.asyncio async def test_update_context_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1822,7 +2225,7 @@ async def test_update_context_flattened_error_async(): ) def test_delete_context(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1849,7 +2252,7 @@ def test_delete_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1866,7 +2269,7 @@ async def test_delete_context_async( transport: str = "grpc_asyncio", request_type=context.DeleteContextRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1896,7 +2299,7 @@ async def test_delete_context_async_from_dict(): def test_delete_context_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1926,7 +2329,7 @@ def test_delete_context_field_headers(): @pytest.mark.asyncio async def test_delete_context_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1955,7 +2358,7 @@ async def test_delete_context_field_headers_async(): def test_delete_context_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1979,7 +2382,7 @@ def test_delete_context_flattened(): def test_delete_context_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1994,7 +2397,7 @@ def test_delete_context_flattened_error(): @pytest.mark.asyncio async def test_delete_context_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2021,7 +2424,7 @@ async def test_delete_context_flattened_async(): @pytest.mark.asyncio async def test_delete_context_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2042,7 +2445,7 @@ async def test_delete_context_flattened_error_async(): ) def test_delete_all_contexts(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2071,7 +2474,7 @@ def test_delete_all_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2090,7 +2493,7 @@ async def test_delete_all_contexts_async( transport: str = "grpc_asyncio", request_type=context.DeleteAllContextsRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2122,7 +2525,7 @@ async def test_delete_all_contexts_async_from_dict(): def test_delete_all_contexts_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2154,7 +2557,7 @@ def test_delete_all_contexts_field_headers(): @pytest.mark.asyncio async def test_delete_all_contexts_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2185,7 +2588,7 @@ async def test_delete_all_contexts_field_headers_async(): def test_delete_all_contexts_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2211,7 +2614,7 @@ def test_delete_all_contexts_flattened(): def test_delete_all_contexts_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2226,7 +2629,7 @@ def test_delete_all_contexts_flattened_error(): @pytest.mark.asyncio async def test_delete_all_contexts_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2255,7 +2658,7 @@ async def test_delete_all_contexts_flattened_async(): @pytest.mark.asyncio async def test_delete_all_contexts_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2276,7 +2679,7 @@ async def test_delete_all_contexts_flattened_error_async(): ) def test_list_contexts_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2325,7 +2728,7 @@ def test_list_contexts_rest_required_fields(request_type=context.ListContextsReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_contexts._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2334,7 +2737,7 @@ def test_list_contexts_rest_required_fields(request_type=context.ListContextsReq jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_contexts._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2350,7 +2753,7 @@ def test_list_contexts_rest_required_fields(request_type=context.ListContextsReq assert jsonified_request["parent"] == "parent_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2392,7 +2795,7 @@ def test_list_contexts_rest_required_fields(request_type=context.ListContextsReq def test_list_contexts_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_contexts._get_unset_required_fields({}) @@ -2410,7 +2813,7 @@ def test_list_contexts_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_contexts_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -2464,7 +2867,7 @@ def test_list_contexts_rest_bad_request( transport: str = "rest", request_type=context.ListContextsRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2486,7 +2889,7 @@ def test_list_contexts_rest_bad_request( def test_list_contexts_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2528,7 +2931,7 @@ def test_list_contexts_rest_flattened(): def test_list_contexts_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2543,7 +2946,7 @@ def test_list_contexts_rest_flattened_error(transport: str = "rest"): def test_list_contexts_rest_pager(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2611,7 +3014,7 @@ def test_list_contexts_rest_pager(transport: str = "rest"): ) def test_get_context_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2662,7 +3065,7 @@ def test_get_context_rest_required_fields(request_type=context.GetContextRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2671,7 +3074,7 @@ def test_get_context_rest_required_fields(request_type=context.GetContextRequest jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2680,7 +3083,7 @@ def test_get_context_rest_required_fields(request_type=context.GetContextRequest assert jsonified_request["name"] == "name_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2722,7 +3125,7 @@ def test_get_context_rest_required_fields(request_type=context.GetContextRequest def test_get_context_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_context._get_unset_required_fields({}) @@ -2732,7 +3135,7 @@ def test_get_context_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_context_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -2784,7 +3187,7 @@ def test_get_context_rest_bad_request( transport: str = "rest", request_type=context.GetContextRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2806,7 +3209,7 @@ def test_get_context_rest_bad_request( def test_get_context_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2850,7 +3253,7 @@ def test_get_context_rest_flattened(): def test_get_context_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2865,7 +3268,7 @@ def test_get_context_rest_flattened_error(transport: str = "rest"): def test_get_context_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2878,7 +3281,7 @@ def test_get_context_rest_error(): ) def test_create_context_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3003,7 +3406,7 @@ def test_create_context_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3012,7 +3415,7 @@ def test_create_context_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3021,7 +3424,7 @@ def test_create_context_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3064,7 +3467,7 @@ def test_create_context_rest_required_fields( def test_create_context_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_context._get_unset_required_fields({}) @@ -3082,7 +3485,7 @@ def test_create_context_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_context_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -3136,7 +3539,7 @@ def test_create_context_rest_bad_request( transport: str = "rest", request_type=gcd_context.CreateContextRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3158,7 +3561,7 @@ def test_create_context_rest_bad_request( def test_create_context_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3201,7 +3604,7 @@ def test_create_context_rest_flattened(): def test_create_context_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3217,7 +3620,7 @@ def test_create_context_rest_flattened_error(transport: str = "rest"): def test_create_context_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3230,7 +3633,7 @@ def test_create_context_rest_error(): ) def test_update_context_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3356,14 +3759,14 @@ def test_update_context_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_context._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3372,7 +3775,7 @@ def test_update_context_rest_required_fields( # verify required fields with non-default values are left alone client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3415,7 +3818,7 @@ def test_update_context_rest_required_fields( def test_update_context_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_context._get_unset_required_fields({}) @@ -3425,7 +3828,7 @@ def test_update_context_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_context_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -3479,7 +3882,7 @@ def test_update_context_rest_bad_request( transport: str = "rest", request_type=gcd_context.UpdateContextRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3503,7 +3906,7 @@ def test_update_context_rest_bad_request( def test_update_context_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3550,7 +3953,7 @@ def test_update_context_rest_flattened(): def test_update_context_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3566,7 +3969,7 @@ def test_update_context_rest_flattened_error(transport: str = "rest"): def test_update_context_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3579,7 +3982,7 @@ def test_update_context_rest_error(): ) def test_delete_context_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3623,7 +4026,7 @@ def test_delete_context_rest_required_fields(request_type=context.DeleteContextR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3632,7 +4035,7 @@ def test_delete_context_rest_required_fields(request_type=context.DeleteContextR jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3641,7 +4044,7 @@ def test_delete_context_rest_required_fields(request_type=context.DeleteContextR assert jsonified_request["name"] == "name_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3680,7 +4083,7 @@ def test_delete_context_rest_required_fields(request_type=context.DeleteContextR def test_delete_context_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_context._get_unset_required_fields({}) @@ -3690,7 +4093,7 @@ def test_delete_context_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_context_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -3736,7 +4139,7 @@ def test_delete_context_rest_bad_request( transport: str = "rest", request_type=context.DeleteContextRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3758,7 +4161,7 @@ def test_delete_context_rest_bad_request( def test_delete_context_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3800,7 +4203,7 @@ def test_delete_context_rest_flattened(): def test_delete_context_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3815,7 +4218,7 @@ def test_delete_context_rest_flattened_error(transport: str = "rest"): def test_delete_context_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3828,7 +4231,7 @@ def test_delete_context_rest_error(): ) def test_delete_all_contexts_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3874,7 +4277,7 @@ def test_delete_all_contexts_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_all_contexts._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3883,7 +4286,7 @@ def test_delete_all_contexts_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_all_contexts._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3892,7 +4295,7 @@ def test_delete_all_contexts_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3931,7 +4334,7 @@ def test_delete_all_contexts_rest_required_fields( def test_delete_all_contexts_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_all_contexts._get_unset_required_fields({}) @@ -3941,7 +4344,7 @@ def test_delete_all_contexts_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_all_contexts_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -3989,7 +4392,7 @@ def test_delete_all_contexts_rest_bad_request( transport: str = "rest", request_type=context.DeleteAllContextsRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4011,7 +4414,7 @@ def test_delete_all_contexts_rest_bad_request( def test_delete_all_contexts_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4051,7 +4454,7 @@ def test_delete_all_contexts_rest_flattened(): def test_delete_all_contexts_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4066,24 +4469,24 @@ def test_delete_all_contexts_rest_flattened_error(transport: str = "rest"): def test_delete_all_contexts_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ContextsClient( @@ -4093,7 +4496,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4104,16 +4507,17 @@ 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 = ContextsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ContextsClient( @@ -4125,7 +4529,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ContextsClient(transport=transport) assert client.transport is transport @@ -4134,13 +4538,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ContextsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4157,7 +4561,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4171,7 +4575,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ContextsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4179,7 +4583,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4191,7 +4595,7 @@ def test_contexts_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ContextsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4203,7 +4607,7 @@ def test_contexts_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ContextsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4245,7 +4649,7 @@ def test_contexts_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.contexts.transports.ContextsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ContextsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4267,7 +4671,7 @@ def test_contexts_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.contexts.transports.ContextsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ContextsTransport() adc.assert_called_once() @@ -4275,7 +4679,7 @@ def test_contexts_base_transport_with_adc(): def test_contexts_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ContextsClient() adc.assert_called_once_with( scopes=None, @@ -4298,7 +4702,7 @@ def test_contexts_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4348,7 +4752,7 @@ def test_contexts_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4376,7 +4780,7 @@ def test_contexts_transport_create_channel(transport_class, grpc_helpers): [transports.ContextsGrpcTransport, transports.ContextsGrpcAsyncIOTransport], ) def test_contexts_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4414,7 +4818,7 @@ def test_contexts_grpc_transport_client_cert_source_for_mtls(transport_class): def test_contexts_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4434,7 +4838,7 @@ def test_contexts_http_transport_client_cert_source_for_mtls(): ) def test_contexts_host_no_port(transport_name): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4457,7 +4861,7 @@ def test_contexts_host_no_port(transport_name): ) def test_contexts_host_with_port(transport_name): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4477,8 +4881,8 @@ def test_contexts_host_with_port(transport_name): ], ) def test_contexts_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ContextsClient( credentials=creds1, transport=transport_name, @@ -4552,7 +4956,7 @@ def test_contexts_transport_channel_mtls_with_client_cert_source(transport_class mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4761,7 +5165,7 @@ def test_client_with_default_client_info(): transports.ContextsTransport, "_prep_wrapped_messages" ) as prep: client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4771,7 +5175,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ContextsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4780,7 +5184,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4795,7 +5199,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4825,7 +5229,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4853,7 +5257,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4881,7 +5285,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4909,7 +5313,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4939,7 +5343,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4967,7 +5371,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4997,7 +5401,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -5025,7 +5429,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5053,7 +5457,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -5079,7 +5483,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5104,7 +5508,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5128,7 +5532,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5157,7 +5561,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5184,7 +5588,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5202,7 +5606,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5218,7 +5622,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5243,7 +5647,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5269,7 +5673,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5298,7 +5702,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5327,7 +5731,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5345,7 +5749,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5363,7 +5767,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5388,7 +5792,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5414,7 +5818,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5443,7 +5847,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5472,7 +5876,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5490,7 +5894,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5508,7 +5912,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5533,7 +5937,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5559,7 +5963,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5588,7 +5992,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5617,7 +6021,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5635,7 +6039,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5653,7 +6057,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5678,7 +6082,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5703,7 +6107,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = ContextsClient(credentials=ga_credentials.AnonymousCredentials()) + client = ContextsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5730,7 +6134,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = ContextsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = ContextsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5758,7 +6162,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5776,7 +6180,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5800,7 +6204,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5817,7 +6221,7 @@ def test_client_ctx(): ] for transport in transports: client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5848,7 +6252,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_datasets.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_datasets.py index d268f7ab8192..9f5b6a015d21 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_datasets.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_datasets.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -83,6 +83,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -113,6 +136,289 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert ConversationDatasetsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ConversationDatasetsClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ConversationDatasetsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ConversationDatasetsClient._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 ConversationDatasetsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ConversationDatasetsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ConversationDatasetsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationDatasetsClient._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 ConversationDatasetsClient._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 ConversationDatasetsClient._get_client_cert_source(None, False) is None + assert ( + ConversationDatasetsClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + ConversationDatasetsClient._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 ( + ConversationDatasetsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ConversationDatasetsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ConversationDatasetsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationDatasetsClient), +) +@mock.patch.object( + ConversationDatasetsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationDatasetsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ConversationDatasetsClient._DEFAULT_UNIVERSE + default_endpoint = ConversationDatasetsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationDatasetsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ConversationDatasetsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ConversationDatasetsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ConversationDatasetsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationDatasetsClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + ConversationDatasetsClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == ConversationDatasetsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationDatasetsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ConversationDatasetsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationDatasetsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ConversationDatasetsClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationDatasetsClient._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 ( + ConversationDatasetsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ConversationDatasetsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ConversationDatasetsClient._get_universe_domain(None, None) + == ConversationDatasetsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ConversationDatasetsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + ConversationDatasetsClient, + transports.ConversationDatasetsGrpcTransport, + "grpc", + ), + ( + ConversationDatasetsClient, + transports.ConversationDatasetsRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -124,7 +430,7 @@ def test__get_default_mtls_endpoint(): def test_conversation_datasets_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -178,7 +484,7 @@ def test_conversation_datasets_client_service_account_always_use_jwt( def test_conversation_datasets_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -236,20 +542,22 @@ def test_conversation_datasets_client_get_transport_class(): ) @mock.patch.object( ConversationDatasetsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationDatasetsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationDatasetsClient), ) @mock.patch.object( ConversationDatasetsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationDatasetsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationDatasetsAsyncClient), ) def test_conversation_datasets_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ConversationDatasetsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -284,7 +592,9 @@ def test_conversation_datasets_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, @@ -314,15 +624,23 @@ def test_conversation_datasets_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") @@ -332,7 +650,9 @@ def test_conversation_datasets_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", @@ -350,7 +670,9 @@ def test_conversation_datasets_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, @@ -403,13 +725,13 @@ def test_conversation_datasets_client_client_options( ) @mock.patch.object( ConversationDatasetsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationDatasetsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationDatasetsClient), ) @mock.patch.object( ConversationDatasetsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationDatasetsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationDatasetsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_conversation_datasets_client_mtls_env_auto( @@ -432,7 +754,9 @@ def test_conversation_datasets_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 @@ -464,7 +788,9 @@ def test_conversation_datasets_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 @@ -498,7 +824,9 @@ def test_conversation_datasets_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, @@ -588,6 +916,118 @@ def test_conversation_datasets_client_get_mtls_endpoint_and_cert_source(client_c 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", [ConversationDatasetsClient, ConversationDatasetsAsyncClient] +) +@mock.patch.object( + ConversationDatasetsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationDatasetsClient), +) +@mock.patch.object( + ConversationDatasetsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationDatasetsAsyncClient), +) +def test_conversation_datasets_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ConversationDatasetsClient._DEFAULT_UNIVERSE + default_endpoint = ConversationDatasetsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationDatasetsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -622,7 +1062,9 @@ def test_conversation_datasets_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, @@ -667,7 +1109,9 @@ def test_conversation_datasets_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, @@ -727,7 +1171,9 @@ def test_conversation_datasets_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, @@ -744,8 +1190,8 @@ def test_conversation_datasets_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -777,7 +1223,7 @@ def test_conversation_datasets_client_create_channel_credentials_file( ) def test_create_conversation_dataset(request_type, transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -806,7 +1252,7 @@ def test_create_conversation_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -826,7 +1272,7 @@ async def test_create_conversation_dataset_async( request_type=gcd_conversation_dataset.CreateConversationDatasetRequest, ): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -860,7 +1306,7 @@ async def test_create_conversation_dataset_async_from_dict(): def test_create_conversation_dataset_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -892,7 +1338,7 @@ def test_create_conversation_dataset_field_headers(): @pytest.mark.asyncio async def test_create_conversation_dataset_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -925,7 +1371,7 @@ async def test_create_conversation_dataset_field_headers_async(): def test_create_conversation_dataset_flattened(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -957,7 +1403,7 @@ def test_create_conversation_dataset_flattened(): def test_create_conversation_dataset_flattened_error(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -975,7 +1421,7 @@ def test_create_conversation_dataset_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_dataset_flattened_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1012,7 +1458,7 @@ async def test_create_conversation_dataset_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_dataset_flattened_error_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1036,7 +1482,7 @@ async def test_create_conversation_dataset_flattened_error_async(): ) def test_get_conversation_dataset(request_type, transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1074,7 +1520,7 @@ def test_get_conversation_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1094,7 +1540,7 @@ async def test_get_conversation_dataset_async( request_type=conversation_dataset.GetConversationDatasetRequest, ): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1137,7 +1583,7 @@ async def test_get_conversation_dataset_async_from_dict(): def test_get_conversation_dataset_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1169,7 +1615,7 @@ def test_get_conversation_dataset_field_headers(): @pytest.mark.asyncio async def test_get_conversation_dataset_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1202,7 +1648,7 @@ async def test_get_conversation_dataset_field_headers_async(): def test_get_conversation_dataset_flattened(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1228,7 +1674,7 @@ def test_get_conversation_dataset_flattened(): def test_get_conversation_dataset_flattened_error(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1243,7 +1689,7 @@ def test_get_conversation_dataset_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_dataset_flattened_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1274,7 +1720,7 @@ async def test_get_conversation_dataset_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_dataset_flattened_error_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1295,7 +1741,7 @@ async def test_get_conversation_dataset_flattened_error_async(): ) def test_list_conversation_datasets(request_type, transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1327,7 +1773,7 @@ def test_list_conversation_datasets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1347,7 +1793,7 @@ async def test_list_conversation_datasets_async( request_type=conversation_dataset.ListConversationDatasetsRequest, ): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1384,7 +1830,7 @@ async def test_list_conversation_datasets_async_from_dict(): def test_list_conversation_datasets_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1416,7 +1862,7 @@ def test_list_conversation_datasets_field_headers(): @pytest.mark.asyncio async def test_list_conversation_datasets_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1449,7 +1895,7 @@ async def test_list_conversation_datasets_field_headers_async(): def test_list_conversation_datasets_flattened(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1475,7 +1921,7 @@ def test_list_conversation_datasets_flattened(): def test_list_conversation_datasets_flattened_error(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1490,7 +1936,7 @@ def test_list_conversation_datasets_flattened_error(): @pytest.mark.asyncio async def test_list_conversation_datasets_flattened_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1521,7 +1967,7 @@ async def test_list_conversation_datasets_flattened_async(): @pytest.mark.asyncio async def test_list_conversation_datasets_flattened_error_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1535,7 +1981,7 @@ async def test_list_conversation_datasets_flattened_error_async(): def test_list_conversation_datasets_pager(transport_name: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1589,7 +2035,7 @@ def test_list_conversation_datasets_pager(transport_name: str = "grpc"): def test_list_conversation_datasets_pages(transport_name: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1633,7 +2079,7 @@ def test_list_conversation_datasets_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversation_datasets_async_pager(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1687,7 +2133,7 @@ async def test_list_conversation_datasets_async_pager(): @pytest.mark.asyncio async def test_list_conversation_datasets_async_pages(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1744,7 +2190,7 @@ async def test_list_conversation_datasets_async_pages(): ) def test_delete_conversation_dataset(request_type, transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1773,7 +2219,7 @@ def test_delete_conversation_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1793,7 +2239,7 @@ async def test_delete_conversation_dataset_async( request_type=conversation_dataset.DeleteConversationDatasetRequest, ): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1827,7 +2273,7 @@ async def test_delete_conversation_dataset_async_from_dict(): def test_delete_conversation_dataset_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1859,7 +2305,7 @@ def test_delete_conversation_dataset_field_headers(): @pytest.mark.asyncio async def test_delete_conversation_dataset_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1892,7 +2338,7 @@ async def test_delete_conversation_dataset_field_headers_async(): def test_delete_conversation_dataset_flattened(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1918,7 +2364,7 @@ def test_delete_conversation_dataset_flattened(): def test_delete_conversation_dataset_flattened_error(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1933,7 +2379,7 @@ def test_delete_conversation_dataset_flattened_error(): @pytest.mark.asyncio async def test_delete_conversation_dataset_flattened_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1964,7 +2410,7 @@ async def test_delete_conversation_dataset_flattened_async(): @pytest.mark.asyncio async def test_delete_conversation_dataset_flattened_error_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1985,7 +2431,7 @@ async def test_delete_conversation_dataset_flattened_error_async(): ) def test_import_conversation_data(request_type, transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2014,7 +2460,7 @@ def test_import_conversation_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2034,7 +2480,7 @@ async def test_import_conversation_data_async( request_type=conversation_dataset.ImportConversationDataRequest, ): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2068,7 +2514,7 @@ async def test_import_conversation_data_async_from_dict(): def test_import_conversation_data_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2100,7 +2546,7 @@ def test_import_conversation_data_field_headers(): @pytest.mark.asyncio async def test_import_conversation_data_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2140,7 +2586,7 @@ async def test_import_conversation_data_field_headers_async(): ) def test_create_conversation_dataset_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2266,7 +2712,7 @@ def test_create_conversation_dataset_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_dataset._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2275,7 +2721,7 @@ def test_create_conversation_dataset_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_dataset._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2284,7 +2730,7 @@ def test_create_conversation_dataset_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2324,7 +2770,7 @@ def test_create_conversation_dataset_rest_required_fields( def test_create_conversation_dataset_rest_unset_required_fields(): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_conversation_dataset._get_unset_required_fields({}) @@ -2342,7 +2788,7 @@ def test_create_conversation_dataset_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_dataset_rest_interceptors(null_interceptor): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationDatasetsRestInterceptor(), @@ -2405,7 +2851,7 @@ def test_create_conversation_dataset_rest_bad_request( request_type=gcd_conversation_dataset.CreateConversationDatasetRequest, ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2427,7 +2873,7 @@ def test_create_conversation_dataset_rest_bad_request( def test_create_conversation_dataset_rest_flattened(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2470,7 +2916,7 @@ def test_create_conversation_dataset_rest_flattened(): def test_create_conversation_dataset_rest_flattened_error(transport: str = "rest"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2488,7 +2934,7 @@ def test_create_conversation_dataset_rest_flattened_error(transport: str = "rest def test_create_conversation_dataset_rest_error(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2501,7 +2947,7 @@ def test_create_conversation_dataset_rest_error(): ) def test_get_conversation_dataset_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2558,7 +3004,7 @@ def test_get_conversation_dataset_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_dataset._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2567,7 +3013,7 @@ def test_get_conversation_dataset_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_dataset._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2576,7 +3022,7 @@ def test_get_conversation_dataset_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2618,7 +3064,7 @@ def test_get_conversation_dataset_rest_required_fields( def test_get_conversation_dataset_rest_unset_required_fields(): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_conversation_dataset._get_unset_required_fields({}) @@ -2628,7 +3074,7 @@ def test_get_conversation_dataset_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_dataset_rest_interceptors(null_interceptor): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationDatasetsRestInterceptor(), @@ -2687,7 +3133,7 @@ def test_get_conversation_dataset_rest_bad_request( request_type=conversation_dataset.GetConversationDatasetRequest, ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2709,7 +3155,7 @@ def test_get_conversation_dataset_rest_bad_request( def test_get_conversation_dataset_rest_flattened(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2750,7 +3196,7 @@ def test_get_conversation_dataset_rest_flattened(): def test_get_conversation_dataset_rest_flattened_error(transport: str = "rest"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2765,7 +3211,7 @@ def test_get_conversation_dataset_rest_flattened_error(transport: str = "rest"): def test_get_conversation_dataset_rest_error(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2778,7 +3224,7 @@ def test_get_conversation_dataset_rest_error(): ) def test_list_conversation_datasets_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2831,7 +3277,7 @@ def test_list_conversation_datasets_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_datasets._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2840,7 +3286,7 @@ def test_list_conversation_datasets_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_datasets._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2856,7 +3302,7 @@ def test_list_conversation_datasets_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2900,7 +3346,7 @@ def test_list_conversation_datasets_rest_required_fields( def test_list_conversation_datasets_rest_unset_required_fields(): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_conversation_datasets._get_unset_required_fields({}) @@ -2918,7 +3364,7 @@ def test_list_conversation_datasets_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversation_datasets_rest_interceptors(null_interceptor): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationDatasetsRestInterceptor(), @@ -2980,7 +3426,7 @@ def test_list_conversation_datasets_rest_bad_request( request_type=conversation_dataset.ListConversationDatasetsRequest, ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3002,7 +3448,7 @@ def test_list_conversation_datasets_rest_bad_request( def test_list_conversation_datasets_rest_flattened(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3045,7 +3491,7 @@ def test_list_conversation_datasets_rest_flattened(): def test_list_conversation_datasets_rest_flattened_error(transport: str = "rest"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3060,7 +3506,7 @@ def test_list_conversation_datasets_rest_flattened_error(transport: str = "rest" def test_list_conversation_datasets_rest_pager(transport: str = "rest"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3133,7 +3579,7 @@ def test_list_conversation_datasets_rest_pager(transport: str = "rest"): ) def test_delete_conversation_dataset_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3181,7 +3627,7 @@ def test_delete_conversation_dataset_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation_dataset._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3190,7 +3636,7 @@ def test_delete_conversation_dataset_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation_dataset._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3199,7 +3645,7 @@ def test_delete_conversation_dataset_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3238,7 +3684,7 @@ def test_delete_conversation_dataset_rest_required_fields( def test_delete_conversation_dataset_rest_unset_required_fields(): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_conversation_dataset._get_unset_required_fields({}) @@ -3248,7 +3694,7 @@ def test_delete_conversation_dataset_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_conversation_dataset_rest_interceptors(null_interceptor): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationDatasetsRestInterceptor(), @@ -3311,7 +3757,7 @@ def test_delete_conversation_dataset_rest_bad_request( request_type=conversation_dataset.DeleteConversationDatasetRequest, ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3335,7 +3781,7 @@ def test_delete_conversation_dataset_rest_bad_request( def test_delete_conversation_dataset_rest_flattened(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3377,7 +3823,7 @@ def test_delete_conversation_dataset_rest_flattened(): def test_delete_conversation_dataset_rest_flattened_error(transport: str = "rest"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3392,7 +3838,7 @@ def test_delete_conversation_dataset_rest_flattened_error(transport: str = "rest def test_delete_conversation_dataset_rest_error(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3405,7 +3851,7 @@ def test_delete_conversation_dataset_rest_error(): ) def test_import_conversation_data_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3451,7 +3897,7 @@ def test_import_conversation_data_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_conversation_data._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3460,7 +3906,7 @@ def test_import_conversation_data_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_conversation_data._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3469,7 +3915,7 @@ def test_import_conversation_data_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3509,7 +3955,7 @@ def test_import_conversation_data_rest_required_fields( def test_import_conversation_data_rest_unset_required_fields(): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_conversation_data._get_unset_required_fields({}) @@ -3527,7 +3973,7 @@ def test_import_conversation_data_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_conversation_data_rest_interceptors(null_interceptor): transport = transports.ConversationDatasetsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationDatasetsRestInterceptor(), @@ -3588,7 +4034,7 @@ def test_import_conversation_data_rest_bad_request( request_type=conversation_dataset.ImportConversationDataRequest, ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3610,24 +4056,24 @@ def test_import_conversation_data_rest_bad_request( def test_import_conversation_data_rest_error(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConversationDatasetsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ConversationDatasetsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationDatasetsClient( @@ -3637,7 +4083,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ConversationDatasetsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3648,16 +4094,17 @@ 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 = ConversationDatasetsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ConversationDatasetsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationDatasetsClient( @@ -3669,7 +4116,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationDatasetsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ConversationDatasetsClient(transport=transport) assert client.transport is transport @@ -3678,13 +4125,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationDatasetsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ConversationDatasetsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3701,7 +4148,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3715,7 +4162,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ConversationDatasetsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3723,7 +4170,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3735,7 +4182,7 @@ def test_conversation_datasets_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ConversationDatasetsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3747,7 +4194,7 @@ def test_conversation_datasets_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConversationDatasetsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3793,7 +4240,7 @@ def test_conversation_datasets_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.conversation_datasets.transports.ConversationDatasetsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationDatasetsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3815,7 +4262,7 @@ def test_conversation_datasets_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.conversation_datasets.transports.ConversationDatasetsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationDatasetsTransport() adc.assert_called_once() @@ -3823,7 +4270,7 @@ def test_conversation_datasets_base_transport_with_adc(): def test_conversation_datasets_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ConversationDatasetsClient() adc.assert_called_once_with( scopes=None, @@ -3846,7 +4293,7 @@ def test_conversation_datasets_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -3896,7 +4343,7 @@ def test_conversation_datasets_transport_create_channel(transport_class, grpc_he ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3929,7 +4376,7 @@ def test_conversation_datasets_transport_create_channel(transport_class, grpc_he def test_conversation_datasets_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3967,7 +4414,7 @@ def test_conversation_datasets_grpc_transport_client_cert_source_for_mtls( def test_conversation_datasets_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -3979,7 +4426,7 @@ def test_conversation_datasets_http_transport_client_cert_source_for_mtls(): def test_conversation_datasets_rest_lro_client(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -4004,7 +4451,7 @@ def test_conversation_datasets_rest_lro_client(): ) def test_conversation_datasets_host_no_port(transport_name): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4027,7 +4474,7 @@ def test_conversation_datasets_host_no_port(transport_name): ) def test_conversation_datasets_host_with_port(transport_name): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4047,8 +4494,8 @@ def test_conversation_datasets_host_with_port(transport_name): ], ) def test_conversation_datasets_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ConversationDatasetsClient( credentials=creds1, transport=transport_name, @@ -4124,7 +4571,7 @@ def test_conversation_datasets_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4202,7 +4649,7 @@ def test_conversation_datasets_transport_channel_mtls_with_adc(transport_class): def test_conversation_datasets_grpc_lro_client(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -4219,7 +4666,7 @@ def test_conversation_datasets_grpc_lro_client(): def test_conversation_datasets_grpc_lro_async_client(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -4372,7 +4819,7 @@ def test_client_with_default_client_info(): transports.ConversationDatasetsTransport, "_prep_wrapped_messages" ) as prep: client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4382,7 +4829,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ConversationDatasetsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4391,7 +4838,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4406,7 +4853,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4436,7 +4883,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4464,7 +4911,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4492,7 +4939,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4520,7 +4967,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4550,7 +4997,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4578,7 +5025,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4608,7 +5055,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4636,7 +5083,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4664,7 +5111,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4690,7 +5137,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4715,7 +5162,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4739,7 +5186,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4768,7 +5215,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4795,7 +5242,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4813,7 +5260,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4829,7 +5276,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4854,7 +5301,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4880,7 +5327,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4909,7 +5356,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4938,7 +5385,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4956,7 +5403,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4974,7 +5421,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4999,7 +5446,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5025,7 +5472,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5054,7 +5501,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5083,7 +5530,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5101,7 +5548,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5119,7 +5566,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5144,7 +5591,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5170,7 +5617,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5199,7 +5646,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5228,7 +5675,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5246,7 +5693,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5264,7 +5711,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5289,7 +5736,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5315,7 +5762,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5344,7 +5791,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5373,7 +5820,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5391,7 +5838,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ConversationDatasetsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5415,7 +5862,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5432,7 +5879,7 @@ def test_client_ctx(): ] for transport in transports: client = ConversationDatasetsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5466,7 +5913,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_models.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_models.py index 352aeeed5729..0c774c15967a 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_models.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_models.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -82,6 +82,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -112,6 +135,279 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert ConversationModelsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ConversationModelsClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ConversationModelsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ConversationModelsClient._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 ConversationModelsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ConversationModelsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ConversationModelsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationModelsClient._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 ConversationModelsClient._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 ConversationModelsClient._get_client_cert_source(None, False) is None + assert ( + ConversationModelsClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + ConversationModelsClient._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 ( + ConversationModelsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ConversationModelsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ConversationModelsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationModelsClient), +) +@mock.patch.object( + ConversationModelsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationModelsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ConversationModelsClient._DEFAULT_UNIVERSE + default_endpoint = ConversationModelsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationModelsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ConversationModelsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ConversationModelsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ConversationModelsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationModelsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + ConversationModelsClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == ConversationModelsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationModelsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ConversationModelsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationModelsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ConversationModelsClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationModelsClient._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 ( + ConversationModelsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ConversationModelsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ConversationModelsClient._get_universe_domain(None, None) + == ConversationModelsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ConversationModelsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (ConversationModelsClient, transports.ConversationModelsGrpcTransport, "grpc"), + (ConversationModelsClient, transports.ConversationModelsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -123,7 +419,7 @@ def test__get_default_mtls_endpoint(): def test_conversation_models_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -177,7 +473,7 @@ def test_conversation_models_client_service_account_always_use_jwt( def test_conversation_models_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -227,20 +523,22 @@ def test_conversation_models_client_get_transport_class(): ) @mock.patch.object( ConversationModelsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationModelsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationModelsClient), ) @mock.patch.object( ConversationModelsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationModelsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationModelsAsyncClient), ) def test_conversation_models_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ConversationModelsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -275,7 +573,9 @@ def test_conversation_models_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, @@ -305,15 +605,23 @@ def test_conversation_models_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") @@ -323,7 +631,9 @@ def test_conversation_models_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", @@ -341,7 +651,9 @@ def test_conversation_models_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, @@ -394,13 +706,13 @@ def test_conversation_models_client_client_options( ) @mock.patch.object( ConversationModelsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationModelsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationModelsClient), ) @mock.patch.object( ConversationModelsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationModelsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationModelsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_conversation_models_client_mtls_env_auto( @@ -423,7 +735,9 @@ def test_conversation_models_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 @@ -455,7 +769,9 @@ def test_conversation_models_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 @@ -489,7 +805,9 @@ def test_conversation_models_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, @@ -579,6 +897,118 @@ def test_conversation_models_client_get_mtls_endpoint_and_cert_source(client_cla 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", [ConversationModelsClient, ConversationModelsAsyncClient] +) +@mock.patch.object( + ConversationModelsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationModelsClient), +) +@mock.patch.object( + ConversationModelsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationModelsAsyncClient), +) +def test_conversation_models_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ConversationModelsClient._DEFAULT_UNIVERSE + default_endpoint = ConversationModelsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationModelsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -605,7 +1035,9 @@ def test_conversation_models_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, @@ -650,7 +1082,9 @@ def test_conversation_models_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, @@ -710,7 +1144,9 @@ def test_conversation_models_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, @@ -727,8 +1163,8 @@ def test_conversation_models_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -760,7 +1196,7 @@ def test_conversation_models_client_create_channel_credentials_file( ) def test_create_conversation_model(request_type, transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -789,7 +1225,7 @@ def test_create_conversation_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -809,7 +1245,7 @@ async def test_create_conversation_model_async( request_type=gcd_conversation_model.CreateConversationModelRequest, ): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -843,7 +1279,7 @@ async def test_create_conversation_model_async_from_dict(): def test_create_conversation_model_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -875,7 +1311,7 @@ def test_create_conversation_model_field_headers(): @pytest.mark.asyncio async def test_create_conversation_model_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -908,7 +1344,7 @@ async def test_create_conversation_model_field_headers_async(): def test_create_conversation_model_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -940,7 +1376,7 @@ def test_create_conversation_model_flattened(): def test_create_conversation_model_flattened_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -958,7 +1394,7 @@ def test_create_conversation_model_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_model_flattened_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -995,7 +1431,7 @@ async def test_create_conversation_model_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_model_flattened_error_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1019,7 +1455,7 @@ async def test_create_conversation_model_flattened_error_async(): ) def test_get_conversation_model(request_type, transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1057,7 +1493,7 @@ def test_get_conversation_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1077,7 +1513,7 @@ async def test_get_conversation_model_async( request_type=conversation_model.GetConversationModelRequest, ): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1120,7 +1556,7 @@ async def test_get_conversation_model_async_from_dict(): def test_get_conversation_model_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1152,7 +1588,7 @@ def test_get_conversation_model_field_headers(): @pytest.mark.asyncio async def test_get_conversation_model_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1185,7 +1621,7 @@ async def test_get_conversation_model_field_headers_async(): def test_get_conversation_model_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1211,7 +1647,7 @@ def test_get_conversation_model_flattened(): def test_get_conversation_model_flattened_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1226,7 +1662,7 @@ def test_get_conversation_model_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_model_flattened_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1257,7 +1693,7 @@ async def test_get_conversation_model_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_model_flattened_error_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1278,7 +1714,7 @@ async def test_get_conversation_model_flattened_error_async(): ) def test_list_conversation_models(request_type, transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1310,7 +1746,7 @@ def test_list_conversation_models_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1330,7 +1766,7 @@ async def test_list_conversation_models_async( request_type=conversation_model.ListConversationModelsRequest, ): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1367,7 +1803,7 @@ async def test_list_conversation_models_async_from_dict(): def test_list_conversation_models_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1399,7 +1835,7 @@ def test_list_conversation_models_field_headers(): @pytest.mark.asyncio async def test_list_conversation_models_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1432,7 +1868,7 @@ async def test_list_conversation_models_field_headers_async(): def test_list_conversation_models_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1458,7 +1894,7 @@ def test_list_conversation_models_flattened(): def test_list_conversation_models_flattened_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1473,7 +1909,7 @@ def test_list_conversation_models_flattened_error(): @pytest.mark.asyncio async def test_list_conversation_models_flattened_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1504,7 +1940,7 @@ async def test_list_conversation_models_flattened_async(): @pytest.mark.asyncio async def test_list_conversation_models_flattened_error_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1518,7 +1954,7 @@ async def test_list_conversation_models_flattened_error_async(): def test_list_conversation_models_pager(transport_name: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1570,7 +2006,7 @@ def test_list_conversation_models_pager(transport_name: str = "grpc"): def test_list_conversation_models_pages(transport_name: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1614,7 +2050,7 @@ def test_list_conversation_models_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversation_models_async_pager(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1668,7 +2104,7 @@ async def test_list_conversation_models_async_pager(): @pytest.mark.asyncio async def test_list_conversation_models_async_pages(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1725,7 +2161,7 @@ async def test_list_conversation_models_async_pages(): ) def test_delete_conversation_model(request_type, transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1754,7 +2190,7 @@ def test_delete_conversation_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1774,7 +2210,7 @@ async def test_delete_conversation_model_async( request_type=conversation_model.DeleteConversationModelRequest, ): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1808,7 +2244,7 @@ async def test_delete_conversation_model_async_from_dict(): def test_delete_conversation_model_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1840,7 +2276,7 @@ def test_delete_conversation_model_field_headers(): @pytest.mark.asyncio async def test_delete_conversation_model_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1873,7 +2309,7 @@ async def test_delete_conversation_model_field_headers_async(): def test_delete_conversation_model_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1899,7 +2335,7 @@ def test_delete_conversation_model_flattened(): def test_delete_conversation_model_flattened_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1914,7 +2350,7 @@ def test_delete_conversation_model_flattened_error(): @pytest.mark.asyncio async def test_delete_conversation_model_flattened_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1945,7 +2381,7 @@ async def test_delete_conversation_model_flattened_async(): @pytest.mark.asyncio async def test_delete_conversation_model_flattened_error_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1966,7 +2402,7 @@ async def test_delete_conversation_model_flattened_error_async(): ) def test_deploy_conversation_model(request_type, transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1995,7 +2431,7 @@ def test_deploy_conversation_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2015,7 +2451,7 @@ async def test_deploy_conversation_model_async( request_type=conversation_model.DeployConversationModelRequest, ): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2049,7 +2485,7 @@ async def test_deploy_conversation_model_async_from_dict(): def test_deploy_conversation_model_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2081,7 +2517,7 @@ def test_deploy_conversation_model_field_headers(): @pytest.mark.asyncio async def test_deploy_conversation_model_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2121,7 +2557,7 @@ async def test_deploy_conversation_model_field_headers_async(): ) def test_undeploy_conversation_model(request_type, transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2150,7 +2586,7 @@ def test_undeploy_conversation_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2170,7 +2606,7 @@ async def test_undeploy_conversation_model_async( request_type=conversation_model.UndeployConversationModelRequest, ): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2204,7 +2640,7 @@ async def test_undeploy_conversation_model_async_from_dict(): def test_undeploy_conversation_model_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2236,7 +2672,7 @@ def test_undeploy_conversation_model_field_headers(): @pytest.mark.asyncio async def test_undeploy_conversation_model_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2276,7 +2712,7 @@ async def test_undeploy_conversation_model_field_headers_async(): ) def test_get_conversation_model_evaluation(request_type, transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2312,7 +2748,7 @@ def test_get_conversation_model_evaluation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2332,7 +2768,7 @@ async def test_get_conversation_model_evaluation_async( request_type=conversation_model.GetConversationModelEvaluationRequest, ): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2373,7 +2809,7 @@ async def test_get_conversation_model_evaluation_async_from_dict(): def test_get_conversation_model_evaluation_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2405,7 +2841,7 @@ def test_get_conversation_model_evaluation_field_headers(): @pytest.mark.asyncio async def test_get_conversation_model_evaluation_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2438,7 +2874,7 @@ async def test_get_conversation_model_evaluation_field_headers_async(): def test_get_conversation_model_evaluation_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2464,7 +2900,7 @@ def test_get_conversation_model_evaluation_flattened(): def test_get_conversation_model_evaluation_flattened_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2479,7 +2915,7 @@ def test_get_conversation_model_evaluation_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_model_evaluation_flattened_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2510,7 +2946,7 @@ async def test_get_conversation_model_evaluation_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_model_evaluation_flattened_error_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2531,7 +2967,7 @@ async def test_get_conversation_model_evaluation_flattened_error_async(): ) def test_list_conversation_model_evaluations(request_type, transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2563,7 +2999,7 @@ def test_list_conversation_model_evaluations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2583,7 +3019,7 @@ async def test_list_conversation_model_evaluations_async( request_type=conversation_model.ListConversationModelEvaluationsRequest, ): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2620,7 +3056,7 @@ async def test_list_conversation_model_evaluations_async_from_dict(): def test_list_conversation_model_evaluations_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2654,7 +3090,7 @@ def test_list_conversation_model_evaluations_field_headers(): @pytest.mark.asyncio async def test_list_conversation_model_evaluations_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2687,7 +3123,7 @@ async def test_list_conversation_model_evaluations_field_headers_async(): def test_list_conversation_model_evaluations_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2715,7 +3151,7 @@ def test_list_conversation_model_evaluations_flattened(): def test_list_conversation_model_evaluations_flattened_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2730,7 +3166,7 @@ def test_list_conversation_model_evaluations_flattened_error(): @pytest.mark.asyncio async def test_list_conversation_model_evaluations_flattened_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2763,7 +3199,7 @@ async def test_list_conversation_model_evaluations_flattened_async(): @pytest.mark.asyncio async def test_list_conversation_model_evaluations_flattened_error_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2777,7 +3213,7 @@ async def test_list_conversation_model_evaluations_flattened_error_async(): def test_list_conversation_model_evaluations_pager(transport_name: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2832,7 +3268,7 @@ def test_list_conversation_model_evaluations_pager(transport_name: str = "grpc") def test_list_conversation_model_evaluations_pages(transport_name: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2876,7 +3312,7 @@ def test_list_conversation_model_evaluations_pages(transport_name: str = "grpc") @pytest.mark.asyncio async def test_list_conversation_model_evaluations_async_pager(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2931,7 +3367,7 @@ async def test_list_conversation_model_evaluations_async_pager(): @pytest.mark.asyncio async def test_list_conversation_model_evaluations_async_pages(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2988,7 +3424,7 @@ async def test_list_conversation_model_evaluations_async_pages(): ) def test_create_conversation_model_evaluation(request_type, transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3017,7 +3453,7 @@ def test_create_conversation_model_evaluation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3037,7 +3473,7 @@ async def test_create_conversation_model_evaluation_async( request_type=conversation_model.CreateConversationModelEvaluationRequest, ): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3071,7 +3507,7 @@ async def test_create_conversation_model_evaluation_async_from_dict(): def test_create_conversation_model_evaluation_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3103,7 +3539,7 @@ def test_create_conversation_model_evaluation_field_headers(): @pytest.mark.asyncio async def test_create_conversation_model_evaluation_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3136,7 +3572,7 @@ async def test_create_conversation_model_evaluation_field_headers_async(): def test_create_conversation_model_evaluation_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3168,7 +3604,7 @@ def test_create_conversation_model_evaluation_flattened(): def test_create_conversation_model_evaluation_flattened_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3186,7 +3622,7 @@ def test_create_conversation_model_evaluation_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_model_evaluation_flattened_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3223,7 +3659,7 @@ async def test_create_conversation_model_evaluation_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_model_evaluation_flattened_error_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3247,7 +3683,7 @@ async def test_create_conversation_model_evaluation_flattened_error_async(): ) def test_create_conversation_model_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3371,21 +3807,21 @@ def test_create_conversation_model_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3425,7 +3861,7 @@ def test_create_conversation_model_rest_required_fields( def test_create_conversation_model_rest_unset_required_fields(): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_conversation_model._get_unset_required_fields({}) @@ -3435,7 +3871,7 @@ def test_create_conversation_model_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_model_rest_interceptors(null_interceptor): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationModelsRestInterceptor(), @@ -3496,7 +3932,7 @@ def test_create_conversation_model_rest_bad_request( request_type=gcd_conversation_model.CreateConversationModelRequest, ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3518,7 +3954,7 @@ def test_create_conversation_model_rest_bad_request( def test_create_conversation_model_rest_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3560,7 +3996,7 @@ def test_create_conversation_model_rest_flattened(): def test_create_conversation_model_rest_flattened_error(transport: str = "rest"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3578,7 +4014,7 @@ def test_create_conversation_model_rest_flattened_error(transport: str = "rest") def test_create_conversation_model_rest_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3591,7 +4027,7 @@ def test_create_conversation_model_rest_error(): ) def test_get_conversation_model_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3648,7 +4084,7 @@ def test_get_conversation_model_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3657,7 +4093,7 @@ def test_get_conversation_model_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3666,7 +4102,7 @@ def test_get_conversation_model_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3708,7 +4144,7 @@ def test_get_conversation_model_rest_required_fields( def test_get_conversation_model_rest_unset_required_fields(): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_conversation_model._get_unset_required_fields({}) @@ -3718,7 +4154,7 @@ def test_get_conversation_model_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_model_rest_interceptors(null_interceptor): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationModelsRestInterceptor(), @@ -3776,7 +4212,7 @@ def test_get_conversation_model_rest_bad_request( transport: str = "rest", request_type=conversation_model.GetConversationModelRequest ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3798,7 +4234,7 @@ def test_get_conversation_model_rest_bad_request( def test_get_conversation_model_rest_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3839,7 +4275,7 @@ def test_get_conversation_model_rest_flattened(): def test_get_conversation_model_rest_flattened_error(transport: str = "rest"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3854,7 +4290,7 @@ def test_get_conversation_model_rest_flattened_error(transport: str = "rest"): def test_get_conversation_model_rest_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3867,7 +4303,7 @@ def test_get_conversation_model_rest_error(): ) def test_list_conversation_models_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3920,7 +4356,7 @@ def test_list_conversation_models_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_models._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3929,7 +4365,7 @@ def test_list_conversation_models_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_models._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3945,7 +4381,7 @@ def test_list_conversation_models_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3989,7 +4425,7 @@ def test_list_conversation_models_rest_required_fields( def test_list_conversation_models_rest_unset_required_fields(): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_conversation_models._get_unset_required_fields({}) @@ -4007,7 +4443,7 @@ def test_list_conversation_models_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversation_models_rest_interceptors(null_interceptor): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationModelsRestInterceptor(), @@ -4068,7 +4504,7 @@ def test_list_conversation_models_rest_bad_request( request_type=conversation_model.ListConversationModelsRequest, ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4090,7 +4526,7 @@ def test_list_conversation_models_rest_bad_request( def test_list_conversation_models_rest_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4133,7 +4569,7 @@ def test_list_conversation_models_rest_flattened(): def test_list_conversation_models_rest_flattened_error(transport: str = "rest"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4148,7 +4584,7 @@ def test_list_conversation_models_rest_flattened_error(transport: str = "rest"): def test_list_conversation_models_rest_pager(transport: str = "rest"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4219,7 +4655,7 @@ def test_list_conversation_models_rest_pager(transport: str = "rest"): ) def test_delete_conversation_model_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4265,7 +4701,7 @@ def test_delete_conversation_model_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4274,7 +4710,7 @@ def test_delete_conversation_model_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4283,7 +4719,7 @@ def test_delete_conversation_model_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4322,7 +4758,7 @@ def test_delete_conversation_model_rest_required_fields( def test_delete_conversation_model_rest_unset_required_fields(): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_conversation_model._get_unset_required_fields({}) @@ -4332,7 +4768,7 @@ def test_delete_conversation_model_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_conversation_model_rest_interceptors(null_interceptor): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationModelsRestInterceptor(), @@ -4393,7 +4829,7 @@ def test_delete_conversation_model_rest_bad_request( request_type=conversation_model.DeleteConversationModelRequest, ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4415,7 +4851,7 @@ def test_delete_conversation_model_rest_bad_request( def test_delete_conversation_model_rest_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4454,7 +4890,7 @@ def test_delete_conversation_model_rest_flattened(): def test_delete_conversation_model_rest_flattened_error(transport: str = "rest"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4469,7 +4905,7 @@ def test_delete_conversation_model_rest_flattened_error(transport: str = "rest") def test_delete_conversation_model_rest_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4482,7 +4918,7 @@ def test_delete_conversation_model_rest_error(): ) def test_deploy_conversation_model_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4528,7 +4964,7 @@ def test_deploy_conversation_model_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).deploy_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4537,7 +4973,7 @@ def test_deploy_conversation_model_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).deploy_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4546,7 +4982,7 @@ def test_deploy_conversation_model_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4586,7 +5022,7 @@ def test_deploy_conversation_model_rest_required_fields( def test_deploy_conversation_model_rest_unset_required_fields(): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.deploy_conversation_model._get_unset_required_fields({}) @@ -4596,7 +5032,7 @@ def test_deploy_conversation_model_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_deploy_conversation_model_rest_interceptors(null_interceptor): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationModelsRestInterceptor(), @@ -4657,7 +5093,7 @@ def test_deploy_conversation_model_rest_bad_request( request_type=conversation_model.DeployConversationModelRequest, ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4679,7 +5115,7 @@ def test_deploy_conversation_model_rest_bad_request( def test_deploy_conversation_model_rest_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4692,7 +5128,7 @@ def test_deploy_conversation_model_rest_error(): ) def test_undeploy_conversation_model_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4738,7 +5174,7 @@ def test_undeploy_conversation_model_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).undeploy_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4747,7 +5183,7 @@ def test_undeploy_conversation_model_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).undeploy_conversation_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4756,7 +5192,7 @@ def test_undeploy_conversation_model_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4796,7 +5232,7 @@ def test_undeploy_conversation_model_rest_required_fields( def test_undeploy_conversation_model_rest_unset_required_fields(): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.undeploy_conversation_model._get_unset_required_fields({}) @@ -4806,7 +5242,7 @@ def test_undeploy_conversation_model_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_undeploy_conversation_model_rest_interceptors(null_interceptor): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationModelsRestInterceptor(), @@ -4867,7 +5303,7 @@ def test_undeploy_conversation_model_rest_bad_request( request_type=conversation_model.UndeployConversationModelRequest, ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4889,7 +5325,7 @@ def test_undeploy_conversation_model_rest_bad_request( def test_undeploy_conversation_model_rest_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4902,7 +5338,7 @@ def test_undeploy_conversation_model_rest_error(): ) def test_get_conversation_model_evaluation_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4959,7 +5395,7 @@ def test_get_conversation_model_evaluation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_model_evaluation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4968,7 +5404,7 @@ def test_get_conversation_model_evaluation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_model_evaluation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4977,7 +5413,7 @@ def test_get_conversation_model_evaluation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5021,7 +5457,7 @@ def test_get_conversation_model_evaluation_rest_required_fields( def test_get_conversation_model_evaluation_rest_unset_required_fields(): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -5033,7 +5469,7 @@ def test_get_conversation_model_evaluation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_model_evaluation_rest_interceptors(null_interceptor): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationModelsRestInterceptor(), @@ -5096,7 +5532,7 @@ def test_get_conversation_model_evaluation_rest_bad_request( request_type=conversation_model.GetConversationModelEvaluationRequest, ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5120,7 +5556,7 @@ def test_get_conversation_model_evaluation_rest_bad_request( def test_get_conversation_model_evaluation_rest_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5166,7 +5602,7 @@ def test_get_conversation_model_evaluation_rest_flattened_error( transport: str = "rest", ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5181,7 +5617,7 @@ def test_get_conversation_model_evaluation_rest_flattened_error( def test_get_conversation_model_evaluation_rest_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5194,7 +5630,7 @@ def test_get_conversation_model_evaluation_rest_error(): ) def test_list_conversation_model_evaluations_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5247,7 +5683,7 @@ def test_list_conversation_model_evaluations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_model_evaluations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5256,7 +5692,7 @@ def test_list_conversation_model_evaluations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_model_evaluations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5272,7 +5708,7 @@ def test_list_conversation_model_evaluations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5318,7 +5754,7 @@ def test_list_conversation_model_evaluations_rest_required_fields( def test_list_conversation_model_evaluations_rest_unset_required_fields(): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -5338,7 +5774,7 @@ def test_list_conversation_model_evaluations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversation_model_evaluations_rest_interceptors(null_interceptor): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationModelsRestInterceptor(), @@ -5403,7 +5839,7 @@ def test_list_conversation_model_evaluations_rest_bad_request( request_type=conversation_model.ListConversationModelEvaluationsRequest, ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5425,7 +5861,7 @@ def test_list_conversation_model_evaluations_rest_bad_request( def test_list_conversation_model_evaluations_rest_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5471,7 +5907,7 @@ def test_list_conversation_model_evaluations_rest_flattened_error( transport: str = "rest", ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5486,7 +5922,7 @@ def test_list_conversation_model_evaluations_rest_flattened_error( def test_list_conversation_model_evaluations_rest_pager(transport: str = "rest"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5562,7 +5998,7 @@ def test_list_conversation_model_evaluations_rest_pager(transport: str = "rest") ) def test_create_conversation_model_evaluation_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5610,7 +6046,7 @@ def test_create_conversation_model_evaluation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_model_evaluation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5619,7 +6055,7 @@ def test_create_conversation_model_evaluation_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_model_evaluation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5628,7 +6064,7 @@ def test_create_conversation_model_evaluation_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5668,7 +6104,7 @@ def test_create_conversation_model_evaluation_rest_required_fields( def test_create_conversation_model_evaluation_rest_unset_required_fields(): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -5688,7 +6124,7 @@ def test_create_conversation_model_evaluation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_model_evaluation_rest_interceptors(null_interceptor): transport = transports.ConversationModelsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationModelsRestInterceptor(), @@ -5751,7 +6187,7 @@ def test_create_conversation_model_evaluation_rest_bad_request( request_type=conversation_model.CreateConversationModelEvaluationRequest, ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5775,7 +6211,7 @@ def test_create_conversation_model_evaluation_rest_bad_request( def test_create_conversation_model_evaluation_rest_flattened(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5822,7 +6258,7 @@ def test_create_conversation_model_evaluation_rest_flattened_error( transport: str = "rest", ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5840,24 +6276,24 @@ def test_create_conversation_model_evaluation_rest_flattened_error( def test_create_conversation_model_evaluation_rest_error(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConversationModelsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ConversationModelsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationModelsClient( @@ -5867,7 +6303,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ConversationModelsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5878,16 +6314,17 @@ 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 = ConversationModelsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ConversationModelsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationModelsClient( @@ -5899,7 +6336,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationModelsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ConversationModelsClient(transport=transport) assert client.transport is transport @@ -5908,13 +6345,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationModelsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ConversationModelsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5931,7 +6368,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5945,7 +6382,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ConversationModelsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5953,7 +6390,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5965,7 +6402,7 @@ def test_conversation_models_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ConversationModelsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5977,7 +6414,7 @@ def test_conversation_models_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConversationModelsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6027,7 +6464,7 @@ def test_conversation_models_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.conversation_models.transports.ConversationModelsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationModelsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6049,7 +6486,7 @@ def test_conversation_models_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.conversation_models.transports.ConversationModelsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationModelsTransport() adc.assert_called_once() @@ -6057,7 +6494,7 @@ def test_conversation_models_base_transport_with_adc(): def test_conversation_models_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ConversationModelsClient() adc.assert_called_once_with( scopes=None, @@ -6080,7 +6517,7 @@ def test_conversation_models_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -6130,7 +6567,7 @@ def test_conversation_models_transport_create_channel(transport_class, grpc_help ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6163,7 +6600,7 @@ def test_conversation_models_transport_create_channel(transport_class, grpc_help def test_conversation_models_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6201,7 +6638,7 @@ def test_conversation_models_grpc_transport_client_cert_source_for_mtls( def test_conversation_models_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -6213,7 +6650,7 @@ def test_conversation_models_http_transport_client_cert_source_for_mtls(): def test_conversation_models_rest_lro_client(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -6238,7 +6675,7 @@ def test_conversation_models_rest_lro_client(): ) def test_conversation_models_host_no_port(transport_name): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -6261,7 +6698,7 @@ def test_conversation_models_host_no_port(transport_name): ) def test_conversation_models_host_with_port(transport_name): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -6281,8 +6718,8 @@ def test_conversation_models_host_with_port(transport_name): ], ) def test_conversation_models_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ConversationModelsClient( credentials=creds1, transport=transport_name, @@ -6370,7 +6807,7 @@ def test_conversation_models_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6448,7 +6885,7 @@ def test_conversation_models_transport_channel_mtls_with_adc(transport_class): def test_conversation_models_grpc_lro_client(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -6465,7 +6902,7 @@ def test_conversation_models_grpc_lro_client(): def test_conversation_models_grpc_lro_async_client(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -6700,7 +7137,7 @@ def test_client_with_default_client_info(): transports.ConversationModelsTransport, "_prep_wrapped_messages" ) as prep: client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6710,7 +7147,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ConversationModelsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6719,7 +7156,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6734,7 +7171,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6764,7 +7201,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -6792,7 +7229,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6820,7 +7257,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6848,7 +7285,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6878,7 +7315,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6906,7 +7343,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6936,7 +7373,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6964,7 +7401,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6992,7 +7429,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -7018,7 +7455,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7043,7 +7480,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7067,7 +7504,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7096,7 +7533,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7123,7 +7560,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7141,7 +7578,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7157,7 +7594,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7182,7 +7619,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7208,7 +7645,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7237,7 +7674,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7266,7 +7703,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7284,7 +7721,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7302,7 +7739,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7327,7 +7764,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7353,7 +7790,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7382,7 +7819,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7411,7 +7848,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7429,7 +7866,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7447,7 +7884,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7472,7 +7909,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7498,7 +7935,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7527,7 +7964,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7556,7 +7993,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7574,7 +8011,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7592,7 +8029,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7617,7 +8054,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7642,7 +8079,9 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = ConversationModelsClient(credentials=ga_credentials.AnonymousCredentials()) + client = ConversationModelsClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7670,7 +8109,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7699,7 +8138,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7717,7 +8156,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ConversationModelsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7741,7 +8180,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7758,7 +8197,7 @@ def test_client_ctx(): ] for transport in transports: client = ConversationModelsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7792,7 +8231,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py index a16a907d0282..63c9cca06c70 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversation_profiles.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -85,6 +85,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -115,6 +138,289 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert ConversationProfilesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ConversationProfilesClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ConversationProfilesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ConversationProfilesClient._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 ConversationProfilesClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ConversationProfilesClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ConversationProfilesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationProfilesClient._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 ConversationProfilesClient._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 ConversationProfilesClient._get_client_cert_source(None, False) is None + assert ( + ConversationProfilesClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + ConversationProfilesClient._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 ( + ConversationProfilesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ConversationProfilesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ConversationProfilesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesClient), +) +@mock.patch.object( + ConversationProfilesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ConversationProfilesClient._DEFAULT_UNIVERSE + default_endpoint = ConversationProfilesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationProfilesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ConversationProfilesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationProfilesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationProfilesClient._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 ( + ConversationProfilesClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ConversationProfilesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ConversationProfilesClient._get_universe_domain(None, None) + == ConversationProfilesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ConversationProfilesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + ConversationProfilesClient, + transports.ConversationProfilesGrpcTransport, + "grpc", + ), + ( + ConversationProfilesClient, + transports.ConversationProfilesRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -126,7 +432,7 @@ def test__get_default_mtls_endpoint(): def test_conversation_profiles_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -180,7 +486,7 @@ def test_conversation_profiles_client_service_account_always_use_jwt( def test_conversation_profiles_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -238,20 +544,22 @@ def test_conversation_profiles_client_get_transport_class(): ) @mock.patch.object( ConversationProfilesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationProfilesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesClient), ) @mock.patch.object( ConversationProfilesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationProfilesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesAsyncClient), ) def test_conversation_profiles_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ConversationProfilesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -286,7 +594,9 @@ def test_conversation_profiles_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, @@ -316,15 +626,23 @@ def test_conversation_profiles_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") @@ -334,7 +652,9 @@ def test_conversation_profiles_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", @@ -352,7 +672,9 @@ def test_conversation_profiles_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, @@ -405,13 +727,13 @@ def test_conversation_profiles_client_client_options( ) @mock.patch.object( ConversationProfilesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationProfilesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesClient), ) @mock.patch.object( ConversationProfilesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationProfilesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_conversation_profiles_client_mtls_env_auto( @@ -434,7 +756,9 @@ def test_conversation_profiles_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 @@ -466,7 +790,9 @@ def test_conversation_profiles_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 @@ -500,7 +826,9 @@ def test_conversation_profiles_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, @@ -590,6 +918,118 @@ def test_conversation_profiles_client_get_mtls_endpoint_and_cert_source(client_c 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", [ConversationProfilesClient, ConversationProfilesAsyncClient] +) +@mock.patch.object( + ConversationProfilesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesClient), +) +@mock.patch.object( + ConversationProfilesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesAsyncClient), +) +def test_conversation_profiles_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ConversationProfilesClient._DEFAULT_UNIVERSE + default_endpoint = ConversationProfilesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationProfilesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -624,7 +1064,9 @@ def test_conversation_profiles_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, @@ -669,7 +1111,9 @@ def test_conversation_profiles_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, @@ -729,7 +1173,9 @@ def test_conversation_profiles_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, @@ -746,8 +1192,8 @@ def test_conversation_profiles_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -779,7 +1225,7 @@ def test_conversation_profiles_client_create_channel_credentials_file( ) def test_list_conversation_profiles(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -811,7 +1257,7 @@ def test_list_conversation_profiles_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -831,7 +1277,7 @@ async def test_list_conversation_profiles_async( request_type=conversation_profile.ListConversationProfilesRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -868,7 +1314,7 @@ async def test_list_conversation_profiles_async_from_dict(): def test_list_conversation_profiles_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -900,7 +1346,7 @@ def test_list_conversation_profiles_field_headers(): @pytest.mark.asyncio async def test_list_conversation_profiles_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -933,7 +1379,7 @@ async def test_list_conversation_profiles_field_headers_async(): def test_list_conversation_profiles_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -959,7 +1405,7 @@ def test_list_conversation_profiles_flattened(): def test_list_conversation_profiles_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -974,7 +1420,7 @@ def test_list_conversation_profiles_flattened_error(): @pytest.mark.asyncio async def test_list_conversation_profiles_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1005,7 +1451,7 @@ async def test_list_conversation_profiles_flattened_async(): @pytest.mark.asyncio async def test_list_conversation_profiles_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1019,7 +1465,7 @@ async def test_list_conversation_profiles_flattened_error_async(): def test_list_conversation_profiles_pager(transport_name: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1073,7 +1519,7 @@ def test_list_conversation_profiles_pager(transport_name: str = "grpc"): def test_list_conversation_profiles_pages(transport_name: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1117,7 +1563,7 @@ def test_list_conversation_profiles_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversation_profiles_async_pager(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1171,7 +1617,7 @@ async def test_list_conversation_profiles_async_pager(): @pytest.mark.asyncio async def test_list_conversation_profiles_async_pages(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1228,7 +1674,7 @@ async def test_list_conversation_profiles_async_pages(): ) def test_get_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1268,7 +1714,7 @@ def test_get_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1288,7 +1734,7 @@ async def test_get_conversation_profile_async( request_type=conversation_profile.GetConversationProfileRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1333,7 +1779,7 @@ async def test_get_conversation_profile_async_from_dict(): def test_get_conversation_profile_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1365,7 +1811,7 @@ def test_get_conversation_profile_field_headers(): @pytest.mark.asyncio async def test_get_conversation_profile_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1398,7 +1844,7 @@ async def test_get_conversation_profile_field_headers_async(): def test_get_conversation_profile_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1424,7 +1870,7 @@ def test_get_conversation_profile_flattened(): def test_get_conversation_profile_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1439,7 +1885,7 @@ def test_get_conversation_profile_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_profile_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1470,7 +1916,7 @@ async def test_get_conversation_profile_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_profile_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1491,7 +1937,7 @@ async def test_get_conversation_profile_flattened_error_async(): ) def test_create_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1531,7 +1977,7 @@ def test_create_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1551,7 +1997,7 @@ async def test_create_conversation_profile_async( request_type=gcd_conversation_profile.CreateConversationProfileRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1596,7 +2042,7 @@ async def test_create_conversation_profile_async_from_dict(): def test_create_conversation_profile_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1628,7 +2074,7 @@ def test_create_conversation_profile_field_headers(): @pytest.mark.asyncio async def test_create_conversation_profile_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1661,7 +2107,7 @@ async def test_create_conversation_profile_field_headers_async(): def test_create_conversation_profile_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1693,7 +2139,7 @@ def test_create_conversation_profile_flattened(): def test_create_conversation_profile_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1711,7 +2157,7 @@ def test_create_conversation_profile_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_profile_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1748,7 +2194,7 @@ async def test_create_conversation_profile_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_profile_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1772,7 +2218,7 @@ async def test_create_conversation_profile_flattened_error_async(): ) def test_update_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1812,7 +2258,7 @@ def test_update_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1832,7 +2278,7 @@ async def test_update_conversation_profile_async( request_type=gcd_conversation_profile.UpdateConversationProfileRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1877,7 +2323,7 @@ async def test_update_conversation_profile_async_from_dict(): def test_update_conversation_profile_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1909,7 +2355,7 @@ def test_update_conversation_profile_field_headers(): @pytest.mark.asyncio async def test_update_conversation_profile_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1942,7 +2388,7 @@ async def test_update_conversation_profile_field_headers_async(): def test_update_conversation_profile_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1974,7 +2420,7 @@ def test_update_conversation_profile_flattened(): def test_update_conversation_profile_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1992,7 +2438,7 @@ def test_update_conversation_profile_flattened_error(): @pytest.mark.asyncio async def test_update_conversation_profile_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2029,7 +2475,7 @@ async def test_update_conversation_profile_flattened_async(): @pytest.mark.asyncio async def test_update_conversation_profile_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2053,7 +2499,7 @@ async def test_update_conversation_profile_flattened_error_async(): ) def test_delete_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2082,7 +2528,7 @@ def test_delete_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2102,7 +2548,7 @@ async def test_delete_conversation_profile_async( request_type=conversation_profile.DeleteConversationProfileRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2134,7 +2580,7 @@ async def test_delete_conversation_profile_async_from_dict(): def test_delete_conversation_profile_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2166,7 +2612,7 @@ def test_delete_conversation_profile_field_headers(): @pytest.mark.asyncio async def test_delete_conversation_profile_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2197,7 +2643,7 @@ async def test_delete_conversation_profile_field_headers_async(): def test_delete_conversation_profile_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2223,7 +2669,7 @@ def test_delete_conversation_profile_flattened(): def test_delete_conversation_profile_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2238,7 +2684,7 @@ def test_delete_conversation_profile_flattened_error(): @pytest.mark.asyncio async def test_delete_conversation_profile_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2267,7 +2713,7 @@ async def test_delete_conversation_profile_flattened_async(): @pytest.mark.asyncio async def test_delete_conversation_profile_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2288,7 +2734,7 @@ async def test_delete_conversation_profile_flattened_error_async(): ) def test_set_suggestion_feature_config(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2317,7 +2763,7 @@ def test_set_suggestion_feature_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2337,7 +2783,7 @@ async def test_set_suggestion_feature_config_async( request_type=gcd_conversation_profile.SetSuggestionFeatureConfigRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2371,7 +2817,7 @@ async def test_set_suggestion_feature_config_async_from_dict(): def test_set_suggestion_feature_config_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2403,7 +2849,7 @@ def test_set_suggestion_feature_config_field_headers(): @pytest.mark.asyncio async def test_set_suggestion_feature_config_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2436,7 +2882,7 @@ async def test_set_suggestion_feature_config_field_headers_async(): def test_set_suggestion_feature_config_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2478,7 +2924,7 @@ def test_set_suggestion_feature_config_flattened(): def test_set_suggestion_feature_config_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2499,7 +2945,7 @@ def test_set_suggestion_feature_config_flattened_error(): @pytest.mark.asyncio async def test_set_suggestion_feature_config_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2546,7 +2992,7 @@ async def test_set_suggestion_feature_config_flattened_async(): @pytest.mark.asyncio async def test_set_suggestion_feature_config_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2573,7 +3019,7 @@ async def test_set_suggestion_feature_config_flattened_error_async(): ) def test_clear_suggestion_feature_config(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2602,7 +3048,7 @@ def test_clear_suggestion_feature_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2622,7 +3068,7 @@ async def test_clear_suggestion_feature_config_async( request_type=gcd_conversation_profile.ClearSuggestionFeatureConfigRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2656,7 +3102,7 @@ async def test_clear_suggestion_feature_config_async_from_dict(): def test_clear_suggestion_feature_config_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2688,7 +3134,7 @@ def test_clear_suggestion_feature_config_field_headers(): @pytest.mark.asyncio async def test_clear_suggestion_feature_config_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2721,7 +3167,7 @@ async def test_clear_suggestion_feature_config_field_headers_async(): def test_clear_suggestion_feature_config_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2755,7 +3201,7 @@ def test_clear_suggestion_feature_config_flattened(): def test_clear_suggestion_feature_config_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2772,7 +3218,7 @@ def test_clear_suggestion_feature_config_flattened_error(): @pytest.mark.asyncio async def test_clear_suggestion_feature_config_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2811,7 +3257,7 @@ async def test_clear_suggestion_feature_config_flattened_async(): @pytest.mark.asyncio async def test_clear_suggestion_feature_config_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2834,7 +3280,7 @@ async def test_clear_suggestion_feature_config_flattened_error_async(): ) def test_list_conversation_profiles_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2887,7 +3333,7 @@ def test_list_conversation_profiles_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_profiles._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2896,7 +3342,7 @@ def test_list_conversation_profiles_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_profiles._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2912,7 +3358,7 @@ def test_list_conversation_profiles_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2956,7 +3402,7 @@ def test_list_conversation_profiles_rest_required_fields( def test_list_conversation_profiles_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_conversation_profiles._get_unset_required_fields({}) @@ -2974,7 +3420,7 @@ def test_list_conversation_profiles_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversation_profiles_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -3036,7 +3482,7 @@ def test_list_conversation_profiles_rest_bad_request( request_type=conversation_profile.ListConversationProfilesRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3058,7 +3504,7 @@ def test_list_conversation_profiles_rest_bad_request( def test_list_conversation_profiles_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3101,7 +3547,7 @@ def test_list_conversation_profiles_rest_flattened(): def test_list_conversation_profiles_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3116,7 +3562,7 @@ def test_list_conversation_profiles_rest_flattened_error(transport: str = "rest" def test_list_conversation_profiles_rest_pager(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3189,7 +3635,7 @@ def test_list_conversation_profiles_rest_pager(transport: str = "rest"): ) def test_get_conversation_profile_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3248,7 +3694,7 @@ def test_get_conversation_profile_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3257,7 +3703,7 @@ def test_get_conversation_profile_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3266,7 +3712,7 @@ def test_get_conversation_profile_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3308,7 +3754,7 @@ def test_get_conversation_profile_rest_required_fields( def test_get_conversation_profile_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_conversation_profile._get_unset_required_fields({}) @@ -3318,7 +3764,7 @@ def test_get_conversation_profile_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_profile_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -3377,7 +3823,7 @@ def test_get_conversation_profile_rest_bad_request( request_type=conversation_profile.GetConversationProfileRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3399,7 +3845,7 @@ def test_get_conversation_profile_rest_bad_request( def test_get_conversation_profile_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3440,7 +3886,7 @@ def test_get_conversation_profile_rest_flattened(): def test_get_conversation_profile_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3455,7 +3901,7 @@ def test_get_conversation_profile_rest_flattened_error(transport: str = "rest"): def test_get_conversation_profile_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3468,7 +3914,7 @@ def test_get_conversation_profile_rest_error(): ) def test_create_conversation_profile_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3689,7 +4135,7 @@ def test_create_conversation_profile_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3698,7 +4144,7 @@ def test_create_conversation_profile_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3707,7 +4153,7 @@ def test_create_conversation_profile_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3750,7 +4196,7 @@ def test_create_conversation_profile_rest_required_fields( def test_create_conversation_profile_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_conversation_profile._get_unset_required_fields({}) @@ -3768,7 +4214,7 @@ def test_create_conversation_profile_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_profile_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -3831,7 +4277,7 @@ def test_create_conversation_profile_rest_bad_request( request_type=gcd_conversation_profile.CreateConversationProfileRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3853,7 +4299,7 @@ def test_create_conversation_profile_rest_bad_request( def test_create_conversation_profile_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3897,7 +4343,7 @@ def test_create_conversation_profile_rest_flattened(): def test_create_conversation_profile_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3915,7 +4361,7 @@ def test_create_conversation_profile_rest_flattened_error(transport: str = "rest def test_create_conversation_profile_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3928,7 +4374,7 @@ def test_create_conversation_profile_rest_error(): ) def test_update_conversation_profile_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4152,14 +4598,14 @@ def test_update_conversation_profile_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation_profile._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -4168,7 +4614,7 @@ def test_update_conversation_profile_rest_required_fields( # verify required fields with non-default values are left alone client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4211,7 +4657,7 @@ def test_update_conversation_profile_rest_required_fields( def test_update_conversation_profile_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_conversation_profile._get_unset_required_fields({}) @@ -4229,7 +4675,7 @@ def test_update_conversation_profile_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_conversation_profile_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -4292,7 +4738,7 @@ def test_update_conversation_profile_rest_bad_request( request_type=gcd_conversation_profile.UpdateConversationProfileRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4318,7 +4764,7 @@ def test_update_conversation_profile_rest_bad_request( def test_update_conversation_profile_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4367,7 +4813,7 @@ def test_update_conversation_profile_rest_flattened(): def test_update_conversation_profile_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4385,7 +4831,7 @@ def test_update_conversation_profile_rest_flattened_error(transport: str = "rest def test_update_conversation_profile_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4398,7 +4844,7 @@ def test_update_conversation_profile_rest_error(): ) def test_delete_conversation_profile_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4444,7 +4890,7 @@ def test_delete_conversation_profile_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4453,7 +4899,7 @@ def test_delete_conversation_profile_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4462,7 +4908,7 @@ def test_delete_conversation_profile_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4501,7 +4947,7 @@ def test_delete_conversation_profile_rest_required_fields( def test_delete_conversation_profile_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_conversation_profile._get_unset_required_fields({}) @@ -4511,7 +4957,7 @@ def test_delete_conversation_profile_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_conversation_profile_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -4563,7 +5009,7 @@ def test_delete_conversation_profile_rest_bad_request( request_type=conversation_profile.DeleteConversationProfileRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4585,7 +5031,7 @@ def test_delete_conversation_profile_rest_bad_request( def test_delete_conversation_profile_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4624,7 +5070,7 @@ def test_delete_conversation_profile_rest_flattened(): def test_delete_conversation_profile_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4639,7 +5085,7 @@ def test_delete_conversation_profile_rest_flattened_error(transport: str = "rest def test_delete_conversation_profile_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4652,7 +5098,7 @@ def test_delete_conversation_profile_rest_error(): ) def test_set_suggestion_feature_config_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4700,7 +5146,7 @@ def test_set_suggestion_feature_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_suggestion_feature_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4709,7 +5155,7 @@ def test_set_suggestion_feature_config_rest_required_fields( jsonified_request["conversationProfile"] = "conversation_profile_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_suggestion_feature_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4718,7 +5164,7 @@ def test_set_suggestion_feature_config_rest_required_fields( assert jsonified_request["conversationProfile"] == "conversation_profile_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4758,7 +5204,7 @@ def test_set_suggestion_feature_config_rest_required_fields( def test_set_suggestion_feature_config_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.set_suggestion_feature_config._get_unset_required_fields( @@ -4779,7 +5225,7 @@ def test_set_suggestion_feature_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_set_suggestion_feature_config_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -4842,7 +5288,7 @@ def test_set_suggestion_feature_config_rest_bad_request( request_type=gcd_conversation_profile.SetSuggestionFeatureConfigRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4866,7 +5312,7 @@ def test_set_suggestion_feature_config_rest_bad_request( def test_set_suggestion_feature_config_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4914,7 +5360,7 @@ def test_set_suggestion_feature_config_rest_flattened(): def test_set_suggestion_feature_config_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4935,7 +5381,7 @@ def test_set_suggestion_feature_config_rest_flattened_error(transport: str = "re def test_set_suggestion_feature_config_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4948,7 +5394,7 @@ def test_set_suggestion_feature_config_rest_error(): ) def test_clear_suggestion_feature_config_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4996,7 +5442,7 @@ def test_clear_suggestion_feature_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).clear_suggestion_feature_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5005,7 +5451,7 @@ def test_clear_suggestion_feature_config_rest_required_fields( jsonified_request["conversationProfile"] = "conversation_profile_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).clear_suggestion_feature_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5014,7 +5460,7 @@ def test_clear_suggestion_feature_config_rest_required_fields( assert jsonified_request["conversationProfile"] == "conversation_profile_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5054,7 +5500,7 @@ def test_clear_suggestion_feature_config_rest_required_fields( def test_clear_suggestion_feature_config_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.clear_suggestion_feature_config._get_unset_required_fields( @@ -5075,7 +5521,7 @@ def test_clear_suggestion_feature_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_clear_suggestion_feature_config_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -5138,7 +5584,7 @@ def test_clear_suggestion_feature_config_rest_bad_request( request_type=gcd_conversation_profile.ClearSuggestionFeatureConfigRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5162,7 +5608,7 @@ def test_clear_suggestion_feature_config_rest_bad_request( def test_clear_suggestion_feature_config_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5206,7 +5652,7 @@ def test_clear_suggestion_feature_config_rest_flattened(): def test_clear_suggestion_feature_config_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5223,24 +5669,24 @@ def test_clear_suggestion_feature_config_rest_flattened_error(transport: str = " def test_clear_suggestion_feature_config_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationProfilesClient( @@ -5250,7 +5696,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5261,16 +5707,17 @@ 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 = ConversationProfilesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationProfilesClient( @@ -5282,7 +5729,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ConversationProfilesClient(transport=transport) assert client.transport is transport @@ -5291,13 +5738,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ConversationProfilesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5314,7 +5761,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5328,7 +5775,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ConversationProfilesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5336,7 +5783,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5348,7 +5795,7 @@ def test_conversation_profiles_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ConversationProfilesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5360,7 +5807,7 @@ def test_conversation_profiles_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConversationProfilesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5408,7 +5855,7 @@ def test_conversation_profiles_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationProfilesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5430,7 +5877,7 @@ def test_conversation_profiles_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationProfilesTransport() adc.assert_called_once() @@ -5438,7 +5885,7 @@ def test_conversation_profiles_base_transport_with_adc(): def test_conversation_profiles_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ConversationProfilesClient() adc.assert_called_once_with( scopes=None, @@ -5461,7 +5908,7 @@ def test_conversation_profiles_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5511,7 +5958,7 @@ def test_conversation_profiles_transport_create_channel(transport_class, grpc_he ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5544,7 +5991,7 @@ def test_conversation_profiles_transport_create_channel(transport_class, grpc_he def test_conversation_profiles_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5582,7 +6029,7 @@ def test_conversation_profiles_grpc_transport_client_cert_source_for_mtls( def test_conversation_profiles_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5594,7 +6041,7 @@ def test_conversation_profiles_http_transport_client_cert_source_for_mtls(): def test_conversation_profiles_rest_lro_client(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5619,7 +6066,7 @@ def test_conversation_profiles_rest_lro_client(): ) def test_conversation_profiles_host_no_port(transport_name): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -5642,7 +6089,7 @@ def test_conversation_profiles_host_no_port(transport_name): ) def test_conversation_profiles_host_with_port(transport_name): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -5662,8 +6109,8 @@ def test_conversation_profiles_host_with_port(transport_name): ], ) def test_conversation_profiles_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ConversationProfilesClient( credentials=creds1, transport=transport_name, @@ -5745,7 +6192,7 @@ def test_conversation_profiles_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5823,7 +6270,7 @@ def test_conversation_profiles_transport_channel_mtls_with_adc(transport_class): def test_conversation_profiles_grpc_lro_client(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5840,7 +6287,7 @@ def test_conversation_profiles_grpc_lro_client(): def test_conversation_profiles_grpc_lro_async_client(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -6115,7 +6562,7 @@ def test_client_with_default_client_info(): transports.ConversationProfilesTransport, "_prep_wrapped_messages" ) as prep: client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6125,7 +6572,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ConversationProfilesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6134,7 +6581,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6149,7 +6596,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6179,7 +6626,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -6207,7 +6654,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6235,7 +6682,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6263,7 +6710,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6293,7 +6740,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6321,7 +6768,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6351,7 +6798,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6379,7 +6826,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6407,7 +6854,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6433,7 +6880,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6458,7 +6905,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6482,7 +6929,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6511,7 +6958,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6538,7 +6985,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6556,7 +7003,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6572,7 +7019,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6597,7 +7044,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6623,7 +7070,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6652,7 +7099,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6681,7 +7128,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6699,7 +7146,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6717,7 +7164,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6742,7 +7189,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6768,7 +7215,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6797,7 +7244,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6826,7 +7273,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6844,7 +7291,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6862,7 +7309,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6887,7 +7334,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6913,7 +7360,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6942,7 +7389,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6971,7 +7418,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6989,7 +7436,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7007,7 +7454,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7032,7 +7479,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7058,7 +7505,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7087,7 +7534,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7116,7 +7563,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7134,7 +7581,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7158,7 +7605,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7175,7 +7622,7 @@ def test_client_ctx(): ] for transport in transports: client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7209,7 +7656,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py index 95b03eb46602..ee3c9b408efe 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_conversations.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -74,6 +74,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -103,6 +126,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert ConversationsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ConversationsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ConversationsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ConversationsClient._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 ConversationsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ConversationsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ConversationsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationsClient._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 ConversationsClient._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 ConversationsClient._get_client_cert_source(None, False) is None + assert ( + ConversationsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + ConversationsClient._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 ( + ConversationsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ConversationsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ConversationsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsClient), +) +@mock.patch.object( + ConversationsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ConversationsClient._DEFAULT_UNIVERSE + default_endpoint = ConversationsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ConversationsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ConversationsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ConversationsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + ConversationsClient._get_api_endpoint(None, None, default_universe, "always") + == ConversationsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ConversationsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ConversationsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationsClient._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 ( + ConversationsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ConversationsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ConversationsClient._get_universe_domain(None, None) + == ConversationsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ConversationsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (ConversationsClient, transports.ConversationsGrpcTransport, "grpc"), + (ConversationsClient, transports.ConversationsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -112,7 +392,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_conversations_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -164,7 +444,7 @@ def test_conversations_client_service_account_always_use_jwt( ], ) def test_conversations_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -214,20 +494,22 @@ def test_conversations_client_get_transport_class(): ) @mock.patch.object( ConversationsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsClient), ) @mock.patch.object( ConversationsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsAsyncClient), ) def test_conversations_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ConversationsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -262,7 +544,9 @@ def test_conversations_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, @@ -292,15 +576,23 @@ def test_conversations_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") @@ -310,7 +602,9 @@ def test_conversations_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", @@ -328,7 +622,9 @@ def test_conversations_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, @@ -361,13 +657,13 @@ def test_conversations_client_client_options( ) @mock.patch.object( ConversationsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsClient), ) @mock.patch.object( ConversationsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_conversations_client_mtls_env_auto( @@ -390,7 +686,9 @@ def test_conversations_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 @@ -422,7 +720,9 @@ def test_conversations_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 @@ -456,7 +756,9 @@ def test_conversations_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, @@ -546,6 +848,118 @@ def test_conversations_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", [ConversationsClient, ConversationsAsyncClient] +) +@mock.patch.object( + ConversationsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsClient), +) +@mock.patch.object( + ConversationsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsAsyncClient), +) +def test_conversations_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ConversationsClient._DEFAULT_UNIVERSE + default_endpoint = ConversationsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -572,7 +986,9 @@ def test_conversations_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, @@ -612,7 +1028,9 @@ def test_conversations_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, @@ -672,7 +1090,9 @@ def test_conversations_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, @@ -689,8 +1109,8 @@ def test_conversations_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -722,7 +1142,7 @@ def test_conversations_client_create_channel_credentials_file( ) def test_create_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -766,7 +1186,7 @@ def test_create_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -786,7 +1206,7 @@ async def test_create_conversation_async( request_type=gcd_conversation.CreateConversationRequest, ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -835,7 +1255,7 @@ async def test_create_conversation_async_from_dict(): def test_create_conversation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -867,7 +1287,7 @@ def test_create_conversation_field_headers(): @pytest.mark.asyncio async def test_create_conversation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -900,7 +1320,7 @@ async def test_create_conversation_field_headers_async(): def test_create_conversation_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -930,7 +1350,7 @@ def test_create_conversation_flattened(): def test_create_conversation_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -946,7 +1366,7 @@ def test_create_conversation_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -981,7 +1401,7 @@ async def test_create_conversation_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1003,7 +1423,7 @@ async def test_create_conversation_flattened_error_async(): ) def test_list_conversations(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1035,7 +1455,7 @@ def test_list_conversations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1054,7 +1474,7 @@ async def test_list_conversations_async( transport: str = "grpc_asyncio", request_type=conversation.ListConversationsRequest ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1091,7 +1511,7 @@ async def test_list_conversations_async_from_dict(): def test_list_conversations_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1123,7 +1543,7 @@ def test_list_conversations_field_headers(): @pytest.mark.asyncio async def test_list_conversations_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1156,7 +1576,7 @@ async def test_list_conversations_field_headers_async(): def test_list_conversations_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1182,7 +1602,7 @@ def test_list_conversations_flattened(): def test_list_conversations_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1197,7 +1617,7 @@ def test_list_conversations_flattened_error(): @pytest.mark.asyncio async def test_list_conversations_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1228,7 +1648,7 @@ async def test_list_conversations_flattened_async(): @pytest.mark.asyncio async def test_list_conversations_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1242,7 +1662,7 @@ async def test_list_conversations_flattened_error_async(): def test_list_conversations_pager(transport_name: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1294,7 +1714,7 @@ def test_list_conversations_pager(transport_name: str = "grpc"): def test_list_conversations_pages(transport_name: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1338,7 +1758,7 @@ def test_list_conversations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversations_async_pager(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1390,7 +1810,7 @@ async def test_list_conversations_async_pager(): @pytest.mark.asyncio async def test_list_conversations_async_pages(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1447,7 +1867,7 @@ async def test_list_conversations_async_pages(): ) def test_get_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1488,7 +1908,7 @@ def test_get_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1505,7 +1925,7 @@ async def test_get_conversation_async( transport: str = "grpc_asyncio", request_type=conversation.GetConversationRequest ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1551,7 +1971,7 @@ async def test_get_conversation_async_from_dict(): def test_get_conversation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1581,7 +2001,7 @@ def test_get_conversation_field_headers(): @pytest.mark.asyncio async def test_get_conversation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1612,7 +2032,7 @@ async def test_get_conversation_field_headers_async(): def test_get_conversation_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1636,7 +2056,7 @@ def test_get_conversation_flattened(): def test_get_conversation_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1651,7 +2071,7 @@ def test_get_conversation_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1680,7 +2100,7 @@ async def test_get_conversation_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1701,7 +2121,7 @@ async def test_get_conversation_flattened_error_async(): ) def test_complete_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1744,7 +2164,7 @@ def test_complete_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1764,7 +2184,7 @@ async def test_complete_conversation_async( request_type=conversation.CompleteConversationRequest, ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1812,7 +2232,7 @@ async def test_complete_conversation_async_from_dict(): def test_complete_conversation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1844,7 +2264,7 @@ def test_complete_conversation_field_headers(): @pytest.mark.asyncio async def test_complete_conversation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1877,7 +2297,7 @@ async def test_complete_conversation_field_headers_async(): def test_complete_conversation_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1903,7 +2323,7 @@ def test_complete_conversation_flattened(): def test_complete_conversation_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1918,7 +2338,7 @@ def test_complete_conversation_flattened_error(): @pytest.mark.asyncio async def test_complete_conversation_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1949,7 +2369,7 @@ async def test_complete_conversation_flattened_async(): @pytest.mark.asyncio async def test_complete_conversation_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1970,7 +2390,7 @@ async def test_complete_conversation_flattened_error_async(): ) def test_list_messages(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2000,7 +2420,7 @@ def test_list_messages_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2017,7 +2437,7 @@ async def test_list_messages_async( transport: str = "grpc_asyncio", request_type=conversation.ListMessagesRequest ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2052,7 +2472,7 @@ async def test_list_messages_async_from_dict(): def test_list_messages_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2082,7 +2502,7 @@ def test_list_messages_field_headers(): @pytest.mark.asyncio async def test_list_messages_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2113,7 +2533,7 @@ async def test_list_messages_field_headers_async(): def test_list_messages_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2137,7 +2557,7 @@ def test_list_messages_flattened(): def test_list_messages_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2152,7 +2572,7 @@ def test_list_messages_flattened_error(): @pytest.mark.asyncio async def test_list_messages_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2181,7 +2601,7 @@ async def test_list_messages_flattened_async(): @pytest.mark.asyncio async def test_list_messages_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2195,7 +2615,7 @@ async def test_list_messages_flattened_error_async(): def test_list_messages_pager(transport_name: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2245,7 +2665,7 @@ def test_list_messages_pager(transport_name: str = "grpc"): def test_list_messages_pages(transport_name: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2287,7 +2707,7 @@ def test_list_messages_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_messages_async_pager(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2337,7 +2757,7 @@ async def test_list_messages_async_pager(): @pytest.mark.asyncio async def test_list_messages_async_pages(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2392,7 +2812,7 @@ async def test_list_messages_async_pages(): ) def test_suggest_conversation_summary(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2426,7 +2846,7 @@ def test_suggest_conversation_summary_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2446,7 +2866,7 @@ async def test_suggest_conversation_summary_async( request_type=gcd_conversation.SuggestConversationSummaryRequest, ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2485,7 +2905,7 @@ async def test_suggest_conversation_summary_async_from_dict(): def test_suggest_conversation_summary_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2517,7 +2937,7 @@ def test_suggest_conversation_summary_field_headers(): @pytest.mark.asyncio async def test_suggest_conversation_summary_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2550,7 +2970,7 @@ async def test_suggest_conversation_summary_field_headers_async(): def test_suggest_conversation_summary_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2576,7 +2996,7 @@ def test_suggest_conversation_summary_flattened(): def test_suggest_conversation_summary_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2591,7 +3011,7 @@ def test_suggest_conversation_summary_flattened_error(): @pytest.mark.asyncio async def test_suggest_conversation_summary_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2622,7 +3042,7 @@ async def test_suggest_conversation_summary_flattened_async(): @pytest.mark.asyncio async def test_suggest_conversation_summary_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2643,7 +3063,7 @@ async def test_suggest_conversation_summary_flattened_error_async(): ) def test_generate_stateless_summary(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2677,7 +3097,7 @@ def test_generate_stateless_summary_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2697,7 +3117,7 @@ async def test_generate_stateless_summary_async( request_type=conversation.GenerateStatelessSummaryRequest, ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2736,7 +3156,7 @@ async def test_generate_stateless_summary_async_from_dict(): def test_generate_stateless_summary_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2768,7 +3188,7 @@ def test_generate_stateless_summary_field_headers(): @pytest.mark.asyncio async def test_generate_stateless_summary_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2808,7 +3228,7 @@ async def test_generate_stateless_summary_field_headers_async(): ) def test_search_knowledge(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2838,7 +3258,7 @@ def test_search_knowledge_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2855,7 +3275,7 @@ async def test_search_knowledge_async( transport: str = "grpc_asyncio", request_type=conversation.SearchKnowledgeRequest ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2890,7 +3310,7 @@ async def test_search_knowledge_async_from_dict(): def test_search_knowledge_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2920,7 +3340,7 @@ def test_search_knowledge_field_headers(): @pytest.mark.asyncio async def test_search_knowledge_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2958,7 +3378,7 @@ async def test_search_knowledge_field_headers_async(): ) def test_create_conversation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3097,7 +3517,7 @@ def test_create_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3106,7 +3526,7 @@ def test_create_conversation_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("conversation_id",)) @@ -3117,7 +3537,7 @@ def test_create_conversation_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3160,7 +3580,7 @@ def test_create_conversation_rest_required_fields( def test_create_conversation_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_conversation._get_unset_required_fields({}) @@ -3178,7 +3598,7 @@ def test_create_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -3236,7 +3656,7 @@ def test_create_conversation_rest_bad_request( transport: str = "rest", request_type=gcd_conversation.CreateConversationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3258,7 +3678,7 @@ def test_create_conversation_rest_bad_request( def test_create_conversation_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3299,7 +3719,7 @@ def test_create_conversation_rest_flattened(): def test_create_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3315,7 +3735,7 @@ def test_create_conversation_rest_flattened_error(transport: str = "rest"): def test_create_conversation_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3328,7 +3748,7 @@ def test_create_conversation_rest_error(): ) def test_list_conversations_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3379,7 +3799,7 @@ def test_list_conversations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3388,7 +3808,7 @@ def test_list_conversations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3405,7 +3825,7 @@ def test_list_conversations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3447,7 +3867,7 @@ def test_list_conversations_rest_required_fields( def test_list_conversations_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_conversations._get_unset_required_fields({}) @@ -3466,7 +3886,7 @@ def test_list_conversations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversations_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -3524,7 +3944,7 @@ def test_list_conversations_rest_bad_request( transport: str = "rest", request_type=conversation.ListConversationsRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3546,7 +3966,7 @@ def test_list_conversations_rest_bad_request( def test_list_conversations_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3586,7 +4006,7 @@ def test_list_conversations_rest_flattened(): def test_list_conversations_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3601,7 +4021,7 @@ def test_list_conversations_rest_flattened_error(transport: str = "rest"): def test_list_conversations_rest_pager(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3671,7 +4091,7 @@ def test_list_conversations_rest_pager(transport: str = "rest"): ) def test_get_conversation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3733,7 +4153,7 @@ def test_get_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3742,7 +4162,7 @@ def test_get_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3751,7 +4171,7 @@ def test_get_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3793,7 +4213,7 @@ def test_get_conversation_rest_required_fields( def test_get_conversation_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_conversation._get_unset_required_fields({}) @@ -3803,7 +4223,7 @@ def test_get_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -3861,7 +4281,7 @@ def test_get_conversation_rest_bad_request( transport: str = "rest", request_type=conversation.GetConversationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3883,7 +4303,7 @@ def test_get_conversation_rest_bad_request( def test_get_conversation_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3923,7 +4343,7 @@ def test_get_conversation_rest_flattened(): def test_get_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3938,7 +4358,7 @@ def test_get_conversation_rest_flattened_error(transport: str = "rest"): def test_get_conversation_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3951,7 +4371,7 @@ def test_get_conversation_rest_error(): ) def test_complete_conversation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4013,7 +4433,7 @@ def test_complete_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4022,7 +4442,7 @@ def test_complete_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4031,7 +4451,7 @@ def test_complete_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4074,7 +4494,7 @@ def test_complete_conversation_rest_required_fields( def test_complete_conversation_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.complete_conversation._get_unset_required_fields({}) @@ -4084,7 +4504,7 @@ def test_complete_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_complete_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -4142,7 +4562,7 @@ def test_complete_conversation_rest_bad_request( transport: str = "rest", request_type=conversation.CompleteConversationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4164,7 +4584,7 @@ def test_complete_conversation_rest_bad_request( def test_complete_conversation_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4205,7 +4625,7 @@ def test_complete_conversation_rest_flattened(): def test_complete_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4220,7 +4640,7 @@ def test_complete_conversation_rest_flattened_error(transport: str = "rest"): def test_complete_conversation_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4233,7 +4653,7 @@ def test_complete_conversation_rest_error(): ) def test_list_messages_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4284,7 +4704,7 @@ def test_list_messages_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_messages._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4293,7 +4713,7 @@ def test_list_messages_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_messages._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4310,7 +4730,7 @@ def test_list_messages_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4352,7 +4772,7 @@ def test_list_messages_rest_required_fields( def test_list_messages_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_messages._get_unset_required_fields({}) @@ -4371,7 +4791,7 @@ def test_list_messages_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_messages_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -4429,7 +4849,7 @@ def test_list_messages_rest_bad_request( transport: str = "rest", request_type=conversation.ListMessagesRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4451,7 +4871,7 @@ def test_list_messages_rest_bad_request( def test_list_messages_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4493,7 +4913,7 @@ def test_list_messages_rest_flattened(): def test_list_messages_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4508,7 +4928,7 @@ def test_list_messages_rest_flattened_error(transport: str = "rest"): def test_list_messages_rest_pager(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4576,7 +4996,7 @@ def test_list_messages_rest_pager(transport: str = "rest"): ) def test_suggest_conversation_summary_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4631,7 +5051,7 @@ def test_suggest_conversation_summary_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_conversation_summary._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4640,7 +5060,7 @@ def test_suggest_conversation_summary_rest_required_fields( jsonified_request["conversation"] = "conversation_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_conversation_summary._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4649,7 +5069,7 @@ def test_suggest_conversation_summary_rest_required_fields( assert jsonified_request["conversation"] == "conversation_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4694,7 +5114,7 @@ def test_suggest_conversation_summary_rest_required_fields( def test_suggest_conversation_summary_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.suggest_conversation_summary._get_unset_required_fields({}) @@ -4704,7 +5124,7 @@ def test_suggest_conversation_summary_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_suggest_conversation_summary_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -4765,7 +5185,7 @@ def test_suggest_conversation_summary_rest_bad_request( request_type=gcd_conversation.SuggestConversationSummaryRequest, ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4787,7 +5207,7 @@ def test_suggest_conversation_summary_rest_bad_request( def test_suggest_conversation_summary_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4831,7 +5251,7 @@ def test_suggest_conversation_summary_rest_flattened(): def test_suggest_conversation_summary_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4846,7 +5266,7 @@ def test_suggest_conversation_summary_rest_flattened_error(transport: str = "res def test_suggest_conversation_summary_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4859,7 +5279,7 @@ def test_suggest_conversation_summary_rest_error(): ) def test_generate_stateless_summary_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4911,21 +5331,21 @@ def test_generate_stateless_summary_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_stateless_summary._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_stateless_summary._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4970,7 +5390,7 @@ def test_generate_stateless_summary_rest_required_fields( def test_generate_stateless_summary_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_stateless_summary._get_unset_required_fields({}) @@ -4988,7 +5408,7 @@ def test_generate_stateless_summary_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_stateless_summary_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -5048,7 +5468,7 @@ def test_generate_stateless_summary_rest_bad_request( transport: str = "rest", request_type=conversation.GenerateStatelessSummaryRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5070,7 +5490,7 @@ def test_generate_stateless_summary_rest_bad_request( def test_generate_stateless_summary_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5083,7 +5503,7 @@ def test_generate_stateless_summary_rest_error(): ) def test_search_knowledge_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5134,7 +5554,7 @@ def test_search_knowledge_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_knowledge._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5143,7 +5563,7 @@ def test_search_knowledge_rest_required_fields( jsonified_request["conversationProfile"] = "conversation_profile_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_knowledge._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5152,7 +5572,7 @@ def test_search_knowledge_rest_required_fields( assert jsonified_request["conversationProfile"] == "conversation_profile_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5195,7 +5615,7 @@ def test_search_knowledge_rest_required_fields( def test_search_knowledge_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search_knowledge._get_unset_required_fields({}) @@ -5213,7 +5633,7 @@ def test_search_knowledge_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_knowledge_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -5271,7 +5691,7 @@ def test_search_knowledge_rest_bad_request( transport: str = "rest", request_type=conversation.SearchKnowledgeRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5293,24 +5713,24 @@ def test_search_knowledge_rest_bad_request( def test_search_knowledge_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationsClient( @@ -5320,7 +5740,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5331,16 +5751,17 @@ 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 = ConversationsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationsClient( @@ -5352,7 +5773,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ConversationsClient(transport=transport) assert client.transport is transport @@ -5361,13 +5782,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ConversationsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5384,7 +5805,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5398,7 +5819,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ConversationsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5406,7 +5827,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5418,7 +5839,7 @@ def test_conversations_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ConversationsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5430,7 +5851,7 @@ def test_conversations_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConversationsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5474,7 +5895,7 @@ def test_conversations_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5496,7 +5917,7 @@ def test_conversations_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationsTransport() adc.assert_called_once() @@ -5504,7 +5925,7 @@ def test_conversations_base_transport_with_adc(): def test_conversations_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ConversationsClient() adc.assert_called_once_with( scopes=None, @@ -5527,7 +5948,7 @@ def test_conversations_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5577,7 +5998,7 @@ def test_conversations_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5608,7 +6029,7 @@ def test_conversations_transport_create_channel(transport_class, grpc_helpers): ], ) def test_conversations_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5646,7 +6067,7 @@ def test_conversations_grpc_transport_client_cert_source_for_mtls(transport_clas def test_conversations_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5666,7 +6087,7 @@ def test_conversations_http_transport_client_cert_source_for_mtls(): ) def test_conversations_host_no_port(transport_name): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -5689,7 +6110,7 @@ def test_conversations_host_no_port(transport_name): ) def test_conversations_host_with_port(transport_name): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -5709,8 +6130,8 @@ def test_conversations_host_with_port(transport_name): ], ) def test_conversations_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ConversationsClient( credentials=creds1, transport=transport_name, @@ -5793,7 +6214,7 @@ def test_conversations_transport_channel_mtls_with_client_cert_source(transport_ mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6203,7 +6624,7 @@ def test_client_with_default_client_info(): transports.ConversationsTransport, "_prep_wrapped_messages" ) as prep: client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6213,7 +6634,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ConversationsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6222,7 +6643,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6237,7 +6658,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6267,7 +6688,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -6295,7 +6716,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6323,7 +6744,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6351,7 +6772,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6381,7 +6802,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6409,7 +6830,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6439,7 +6860,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6467,7 +6888,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6495,7 +6916,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6521,7 +6942,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6546,7 +6967,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6570,7 +6991,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6599,7 +7020,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6626,7 +7047,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6644,7 +7065,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6660,7 +7081,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6685,7 +7106,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6711,7 +7132,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6740,7 +7161,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6769,7 +7190,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6787,7 +7208,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6805,7 +7226,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6830,7 +7251,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6856,7 +7277,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6885,7 +7306,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6914,7 +7335,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6932,7 +7353,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6950,7 +7371,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6975,7 +7396,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7001,7 +7422,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7030,7 +7451,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7059,7 +7480,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7077,7 +7498,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7095,7 +7516,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7120,7 +7541,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7145,7 +7566,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials()) + client = ConversationsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7172,7 +7593,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = ConversationsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = ConversationsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7200,7 +7623,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7218,7 +7641,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7242,7 +7665,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7259,7 +7682,7 @@ def test_client_ctx(): ] for transport in transports: client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7290,7 +7713,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_documents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_documents.py index 23bde19f0ba3..8c355faaaeff 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_documents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_documents.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -84,6 +84,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -108,6 +131,247 @@ def test__get_default_mtls_endpoint(): assert DocumentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert DocumentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DocumentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DocumentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DocumentsClient._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 DocumentsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DocumentsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DocumentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentsClient._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 DocumentsClient._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 DocumentsClient._get_client_cert_source(None, False) is None + assert ( + DocumentsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + DocumentsClient._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 ( + DocumentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DocumentsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DocumentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsClient), +) +@mock.patch.object( + DocumentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DocumentsClient._DEFAULT_UNIVERSE + default_endpoint = DocumentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DocumentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DocumentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DocumentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DocumentsClient._get_api_endpoint(None, None, default_universe, "always") + == DocumentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DocumentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DocumentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentsClient._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 ( + DocumentsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DocumentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DocumentsClient._get_universe_domain(None, None) + == DocumentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DocumentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DocumentsClient, transports.DocumentsGrpcTransport, "grpc"), + (DocumentsClient, transports.DocumentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -117,7 +381,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_documents_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -169,7 +433,7 @@ def test_documents_client_service_account_always_use_jwt( ], ) def test_documents_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -218,17 +482,21 @@ def test_documents_client_get_transport_class(): ], ) @mock.patch.object( - DocumentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentsClient) + DocumentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsClient), ) @mock.patch.object( DocumentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsAsyncClient), ) def test_documents_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(DocumentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -263,7 +531,9 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -293,15 +563,23 @@ def test_documents_client_client_options(client_class, transport_class, transpor # 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") @@ -311,7 +589,9 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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", @@ -329,7 +609,9 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -361,12 +643,14 @@ def test_documents_client_client_options(client_class, transport_class, transpor ], ) @mock.patch.object( - DocumentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentsClient) + DocumentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsClient), ) @mock.patch.object( DocumentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_documents_client_mtls_env_auto( @@ -389,7 +673,9 @@ def test_documents_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 @@ -421,7 +707,9 @@ def test_documents_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 @@ -455,7 +743,9 @@ def test_documents_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, @@ -541,6 +831,116 @@ def test_documents_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", [DocumentsClient, DocumentsAsyncClient]) +@mock.patch.object( + DocumentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsClient), +) +@mock.patch.object( + DocumentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsAsyncClient), +) +def test_documents_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DocumentsClient._DEFAULT_UNIVERSE + default_endpoint = DocumentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -567,7 +967,9 @@ def test_documents_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, @@ -602,7 +1004,9 @@ def test_documents_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, @@ -655,7 +1059,9 @@ def test_documents_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, @@ -672,8 +1078,8 @@ def test_documents_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -705,7 +1111,7 @@ def test_documents_client_create_channel_credentials_file( ) def test_list_documents(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -735,7 +1141,7 @@ def test_list_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -752,7 +1158,7 @@ async def test_list_documents_async( transport: str = "grpc_asyncio", request_type=document.ListDocumentsRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -787,7 +1193,7 @@ async def test_list_documents_async_from_dict(): def test_list_documents_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -817,7 +1223,7 @@ def test_list_documents_field_headers(): @pytest.mark.asyncio async def test_list_documents_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -848,7 +1254,7 @@ async def test_list_documents_field_headers_async(): def test_list_documents_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -872,7 +1278,7 @@ def test_list_documents_flattened(): def test_list_documents_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -887,7 +1293,7 @@ def test_list_documents_flattened_error(): @pytest.mark.asyncio async def test_list_documents_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -916,7 +1322,7 @@ async def test_list_documents_flattened_async(): @pytest.mark.asyncio async def test_list_documents_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -930,7 +1336,7 @@ async def test_list_documents_flattened_error_async(): def test_list_documents_pager(transport_name: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -980,7 +1386,7 @@ def test_list_documents_pager(transport_name: str = "grpc"): def test_list_documents_pages(transport_name: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1022,7 +1428,7 @@ def test_list_documents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_documents_async_pager(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1072,7 +1478,7 @@ async def test_list_documents_async_pager(): @pytest.mark.asyncio async def test_list_documents_async_pages(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1127,7 +1533,7 @@ async def test_list_documents_async_pages(): ) def test_get_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1168,7 +1574,7 @@ def test_get_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1185,7 +1591,7 @@ async def test_get_document_async( transport: str = "grpc_asyncio", request_type=document.GetDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1230,7 +1636,7 @@ async def test_get_document_async_from_dict(): def test_get_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1260,7 +1666,7 @@ def test_get_document_field_headers(): @pytest.mark.asyncio async def test_get_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1289,7 +1695,7 @@ async def test_get_document_field_headers_async(): def test_get_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1313,7 +1719,7 @@ def test_get_document_flattened(): def test_get_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1328,7 +1734,7 @@ def test_get_document_flattened_error(): @pytest.mark.asyncio async def test_get_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1355,7 +1761,7 @@ async def test_get_document_flattened_async(): @pytest.mark.asyncio async def test_get_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1376,7 +1782,7 @@ async def test_get_document_flattened_error_async(): ) def test_create_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1403,7 +1809,7 @@ def test_create_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1420,7 +1826,7 @@ async def test_create_document_async( transport: str = "grpc_asyncio", request_type=gcd_document.CreateDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1452,7 +1858,7 @@ async def test_create_document_async_from_dict(): def test_create_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1482,7 +1888,7 @@ def test_create_document_field_headers(): @pytest.mark.asyncio async def test_create_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1513,7 +1919,7 @@ async def test_create_document_field_headers_async(): def test_create_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1541,7 +1947,7 @@ def test_create_document_flattened(): def test_create_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1557,7 +1963,7 @@ def test_create_document_flattened_error(): @pytest.mark.asyncio async def test_create_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1590,7 +1996,7 @@ async def test_create_document_flattened_async(): @pytest.mark.asyncio async def test_create_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1612,7 +2018,7 @@ async def test_create_document_flattened_error_async(): ) def test_import_documents(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1639,7 +2045,7 @@ def test_import_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1656,7 +2062,7 @@ async def test_import_documents_async( transport: str = "grpc_asyncio", request_type=document.ImportDocumentsRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1688,7 +2094,7 @@ async def test_import_documents_async_from_dict(): def test_import_documents_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1718,7 +2124,7 @@ def test_import_documents_field_headers(): @pytest.mark.asyncio async def test_import_documents_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1756,7 +2162,7 @@ async def test_import_documents_field_headers_async(): ) def test_delete_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1783,7 +2189,7 @@ def test_delete_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1800,7 +2206,7 @@ async def test_delete_document_async( transport: str = "grpc_asyncio", request_type=document.DeleteDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1832,7 +2238,7 @@ async def test_delete_document_async_from_dict(): def test_delete_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1862,7 +2268,7 @@ def test_delete_document_field_headers(): @pytest.mark.asyncio async def test_delete_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1893,7 +2299,7 @@ async def test_delete_document_field_headers_async(): def test_delete_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1917,7 +2323,7 @@ def test_delete_document_flattened(): def test_delete_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1932,7 +2338,7 @@ def test_delete_document_flattened_error(): @pytest.mark.asyncio async def test_delete_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1961,7 +2367,7 @@ async def test_delete_document_flattened_async(): @pytest.mark.asyncio async def test_delete_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1982,7 +2388,7 @@ async def test_delete_document_flattened_error_async(): ) def test_update_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2009,7 +2415,7 @@ def test_update_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2026,7 +2432,7 @@ async def test_update_document_async( transport: str = "grpc_asyncio", request_type=gcd_document.UpdateDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2058,7 +2464,7 @@ async def test_update_document_async_from_dict(): def test_update_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2088,7 +2494,7 @@ def test_update_document_field_headers(): @pytest.mark.asyncio async def test_update_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2119,7 +2525,7 @@ async def test_update_document_field_headers_async(): def test_update_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2147,7 +2553,7 @@ def test_update_document_flattened(): def test_update_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2163,7 +2569,7 @@ def test_update_document_flattened_error(): @pytest.mark.asyncio async def test_update_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2196,7 +2602,7 @@ async def test_update_document_flattened_async(): @pytest.mark.asyncio async def test_update_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2218,7 +2624,7 @@ async def test_update_document_flattened_error_async(): ) def test_reload_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2245,7 +2651,7 @@ def test_reload_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2262,7 +2668,7 @@ async def test_reload_document_async( transport: str = "grpc_asyncio", request_type=document.ReloadDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2294,7 +2700,7 @@ async def test_reload_document_async_from_dict(): def test_reload_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2324,7 +2730,7 @@ def test_reload_document_field_headers(): @pytest.mark.asyncio async def test_reload_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2355,7 +2761,7 @@ async def test_reload_document_field_headers_async(): def test_reload_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2381,7 +2787,7 @@ def test_reload_document_flattened(): def test_reload_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2397,7 +2803,7 @@ def test_reload_document_flattened_error(): @pytest.mark.asyncio async def test_reload_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2428,7 +2834,7 @@ async def test_reload_document_flattened_async(): @pytest.mark.asyncio async def test_reload_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2450,7 +2856,7 @@ async def test_reload_document_flattened_error_async(): ) def test_export_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2477,7 +2883,7 @@ def test_export_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2494,7 +2900,7 @@ async def test_export_document_async( transport: str = "grpc_asyncio", request_type=document.ExportDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2526,7 +2932,7 @@ async def test_export_document_async_from_dict(): def test_export_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2556,7 +2962,7 @@ def test_export_document_field_headers(): @pytest.mark.asyncio async def test_export_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2594,7 +3000,7 @@ async def test_export_document_field_headers_async(): ) def test_list_documents_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2645,7 +3051,7 @@ def test_list_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2654,7 +3060,7 @@ def test_list_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2671,7 +3077,7 @@ def test_list_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2713,7 +3119,7 @@ def test_list_documents_rest_required_fields( def test_list_documents_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_documents._get_unset_required_fields({}) @@ -2732,7 +3138,7 @@ def test_list_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_documents_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -2786,7 +3192,7 @@ def test_list_documents_rest_bad_request( transport: str = "rest", request_type=document.ListDocumentsRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2808,7 +3214,7 @@ def test_list_documents_rest_bad_request( def test_list_documents_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2850,7 +3256,7 @@ def test_list_documents_rest_flattened(): def test_list_documents_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2865,7 +3271,7 @@ def test_list_documents_rest_flattened_error(transport: str = "rest"): def test_list_documents_rest_pager(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2933,7 +3339,7 @@ def test_list_documents_rest_pager(transport: str = "rest"): ) def test_get_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2993,7 +3399,7 @@ def test_get_document_rest_required_fields(request_type=document.GetDocumentRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3002,7 +3408,7 @@ def test_get_document_rest_required_fields(request_type=document.GetDocumentRequ jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3011,7 +3417,7 @@ def test_get_document_rest_required_fields(request_type=document.GetDocumentRequ assert jsonified_request["name"] == "name_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3053,7 +3459,7 @@ def test_get_document_rest_required_fields(request_type=document.GetDocumentRequ def test_get_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_document._get_unset_required_fields({}) @@ -3063,7 +3469,7 @@ def test_get_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -3115,7 +3521,7 @@ def test_get_document_rest_bad_request( transport: str = "rest", request_type=document.GetDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3137,7 +3543,7 @@ def test_get_document_rest_bad_request( def test_get_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3181,7 +3587,7 @@ def test_get_document_rest_flattened(): def test_get_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3196,7 +3602,7 @@ def test_get_document_rest_flattened_error(transport: str = "rest"): def test_get_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3209,7 +3615,7 @@ def test_get_document_rest_error(): ) def test_create_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3346,7 +3752,7 @@ def test_create_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3355,7 +3761,7 @@ def test_create_document_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3364,7 +3770,7 @@ def test_create_document_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3404,7 +3810,7 @@ def test_create_document_rest_required_fields( def test_create_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_document._get_unset_required_fields({}) @@ -3422,7 +3828,7 @@ def test_create_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -3480,7 +3886,7 @@ def test_create_document_rest_bad_request( transport: str = "rest", request_type=gcd_document.CreateDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3502,7 +3908,7 @@ def test_create_document_rest_bad_request( def test_create_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3543,7 +3949,7 @@ def test_create_document_rest_flattened(): def test_create_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3559,7 +3965,7 @@ def test_create_document_rest_flattened_error(transport: str = "rest"): def test_create_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3572,7 +3978,7 @@ def test_create_document_rest_error(): ) def test_import_documents_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3618,7 +4024,7 @@ def test_import_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3627,7 +4033,7 @@ def test_import_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3636,7 +4042,7 @@ def test_import_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3676,7 +4082,7 @@ def test_import_documents_rest_required_fields( def test_import_documents_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_documents._get_unset_required_fields({}) @@ -3694,7 +4100,7 @@ def test_import_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_documents_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -3752,7 +4158,7 @@ def test_import_documents_rest_bad_request( transport: str = "rest", request_type=document.ImportDocumentsRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3774,7 +4180,7 @@ def test_import_documents_rest_bad_request( def test_import_documents_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3787,7 +4193,7 @@ def test_import_documents_rest_error(): ) def test_delete_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3833,7 +4239,7 @@ def test_delete_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3842,7 +4248,7 @@ def test_delete_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3851,7 +4257,7 @@ def test_delete_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3890,7 +4296,7 @@ def test_delete_document_rest_required_fields( def test_delete_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_document._get_unset_required_fields({}) @@ -3900,7 +4306,7 @@ def test_delete_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -3956,7 +4362,7 @@ def test_delete_document_rest_bad_request( transport: str = "rest", request_type=document.DeleteDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3978,7 +4384,7 @@ def test_delete_document_rest_bad_request( def test_delete_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4020,7 +4426,7 @@ def test_delete_document_rest_flattened(): def test_delete_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4035,7 +4441,7 @@ def test_delete_document_rest_flattened_error(transport: str = "rest"): def test_delete_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4048,7 +4454,7 @@ def test_delete_document_rest_error(): ) def test_update_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4188,14 +4594,14 @@ def test_update_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -4204,7 +4610,7 @@ def test_update_document_rest_required_fields( # verify required fields with non-default values are left alone client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4244,7 +4650,7 @@ def test_update_document_rest_required_fields( def test_update_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_document._get_unset_required_fields({}) @@ -4254,7 +4660,7 @@ def test_update_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -4312,7 +4718,7 @@ def test_update_document_rest_bad_request( transport: str = "rest", request_type=gcd_document.UpdateDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4338,7 +4744,7 @@ def test_update_document_rest_bad_request( def test_update_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4383,7 +4789,7 @@ def test_update_document_rest_flattened(): def test_update_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4399,7 +4805,7 @@ def test_update_document_rest_flattened_error(transport: str = "rest"): def test_update_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4412,7 +4818,7 @@ def test_update_document_rest_error(): ) def test_reload_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4458,7 +4864,7 @@ def test_reload_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reload_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4467,7 +4873,7 @@ def test_reload_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reload_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4476,7 +4882,7 @@ def test_reload_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4516,7 +4922,7 @@ def test_reload_document_rest_required_fields( def test_reload_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.reload_document._get_unset_required_fields({}) @@ -4526,7 +4932,7 @@ def test_reload_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_reload_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -4582,7 +4988,7 @@ def test_reload_document_rest_bad_request( transport: str = "rest", request_type=document.ReloadDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4604,7 +5010,7 @@ def test_reload_document_rest_bad_request( def test_reload_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4646,7 +5052,7 @@ def test_reload_document_rest_flattened(): def test_reload_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4662,7 +5068,7 @@ def test_reload_document_rest_flattened_error(transport: str = "rest"): def test_reload_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4675,7 +5081,7 @@ def test_reload_document_rest_error(): ) def test_export_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4721,7 +5127,7 @@ def test_export_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4730,7 +5136,7 @@ def test_export_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4739,7 +5145,7 @@ def test_export_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4779,7 +5185,7 @@ def test_export_document_rest_required_fields( def test_export_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.export_document._get_unset_required_fields({}) @@ -4789,7 +5195,7 @@ def test_export_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_export_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -4845,7 +5251,7 @@ def test_export_document_rest_bad_request( transport: str = "rest", request_type=document.ExportDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4867,24 +5273,24 @@ def test_export_document_rest_bad_request( def test_export_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentsClient( @@ -4894,7 +5300,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4905,16 +5311,17 @@ 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 = DocumentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentsClient( @@ -4926,7 +5333,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DocumentsClient(transport=transport) assert client.transport is transport @@ -4935,13 +5342,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DocumentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4958,7 +5365,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4972,7 +5379,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DocumentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4980,7 +5387,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4992,7 +5399,7 @@ def test_documents_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DocumentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5004,7 +5411,7 @@ def test_documents_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DocumentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5053,7 +5460,7 @@ def test_documents_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.documents.transports.DocumentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5075,7 +5482,7 @@ def test_documents_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.documents.transports.DocumentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentsTransport() adc.assert_called_once() @@ -5083,7 +5490,7 @@ def test_documents_base_transport_with_adc(): def test_documents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DocumentsClient() adc.assert_called_once_with( scopes=None, @@ -5106,7 +5513,7 @@ def test_documents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5156,7 +5563,7 @@ def test_documents_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5184,7 +5591,7 @@ def test_documents_transport_create_channel(transport_class, grpc_helpers): [transports.DocumentsGrpcTransport, transports.DocumentsGrpcAsyncIOTransport], ) def test_documents_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5222,7 +5629,7 @@ def test_documents_grpc_transport_client_cert_source_for_mtls(transport_class): def test_documents_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5234,7 +5641,7 @@ def test_documents_http_transport_client_cert_source_for_mtls(): def test_documents_rest_lro_client(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5259,7 +5666,7 @@ def test_documents_rest_lro_client(): ) def test_documents_host_no_port(transport_name): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -5282,7 +5689,7 @@ def test_documents_host_no_port(transport_name): ) def test_documents_host_with_port(transport_name): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -5302,8 +5709,8 @@ def test_documents_host_with_port(transport_name): ], ) def test_documents_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DocumentsClient( credentials=creds1, transport=transport_name, @@ -5383,7 +5790,7 @@ def test_documents_transport_channel_mtls_with_client_cert_source(transport_clas mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5458,7 +5865,7 @@ def test_documents_transport_channel_mtls_with_adc(transport_class): def test_documents_grpc_lro_client(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5475,7 +5882,7 @@ def test_documents_grpc_lro_client(): def test_documents_grpc_lro_async_client(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -5626,7 +6033,7 @@ def test_client_with_default_client_info(): transports.DocumentsTransport, "_prep_wrapped_messages" ) as prep: client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5636,7 +6043,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5645,7 +6052,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5660,7 +6067,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5690,7 +6097,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -5718,7 +6125,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5746,7 +6153,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -5774,7 +6181,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5804,7 +6211,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -5832,7 +6239,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5862,7 +6269,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -5890,7 +6297,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5918,7 +6325,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -5944,7 +6351,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5969,7 +6376,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5993,7 +6400,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6022,7 +6429,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6049,7 +6456,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6067,7 +6474,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6083,7 +6490,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6108,7 +6515,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6134,7 +6541,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6163,7 +6570,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6192,7 +6599,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6210,7 +6617,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6228,7 +6635,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6253,7 +6660,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6279,7 +6686,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6308,7 +6715,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6337,7 +6744,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6355,7 +6762,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6373,7 +6780,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6398,7 +6805,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6424,7 +6831,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6453,7 +6860,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6482,7 +6889,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6500,7 +6907,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6518,7 +6925,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6543,7 +6950,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6568,7 +6975,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = DocumentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = DocumentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -6595,7 +7002,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = DocumentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = DocumentsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -6623,7 +7030,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6641,7 +7048,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6665,7 +7072,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -6682,7 +7089,7 @@ def test_client_ctx(): ] for transport in transports: client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -6713,7 +7120,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_entity_types.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_entity_types.py index 23511236acd0..e83359374696 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_entity_types.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_entity_types.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -81,6 +81,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -107,6 +130,251 @@ def test__get_default_mtls_endpoint(): assert EntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert EntityTypesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EntityTypesClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EntityTypesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EntityTypesClient._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 EntityTypesClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EntityTypesClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EntityTypesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EntityTypesClient._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 EntityTypesClient._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 EntityTypesClient._get_client_cert_source(None, False) is None + assert ( + EntityTypesClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + EntityTypesClient._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 ( + EntityTypesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + EntityTypesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesClient), +) +@mock.patch.object( + EntityTypesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EntityTypesClient._DEFAULT_UNIVERSE + default_endpoint = EntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + EntityTypesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EntityTypesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EntityTypesClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + EntityTypesClient._get_api_endpoint(None, None, default_universe, "always") + == EntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EntityTypesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EntityTypesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + EntityTypesClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EntityTypesClient._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 ( + EntityTypesClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + EntityTypesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + EntityTypesClient._get_universe_domain(None, None) + == EntityTypesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EntityTypesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (EntityTypesClient, transports.EntityTypesGrpcTransport, "grpc"), + (EntityTypesClient, transports.EntityTypesRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -116,7 +384,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_entity_types_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -168,7 +436,7 @@ def test_entity_types_client_service_account_always_use_jwt( ], ) def test_entity_types_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -217,19 +485,23 @@ def test_entity_types_client_get_transport_class(): ], ) @mock.patch.object( - EntityTypesClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EntityTypesClient) + EntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesClient), ) @mock.patch.object( EntityTypesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EntityTypesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesAsyncClient), ) def test_entity_types_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(EntityTypesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -264,7 +536,9 @@ def test_entity_types_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, @@ -294,15 +568,23 @@ def test_entity_types_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") @@ -312,7 +594,9 @@ def test_entity_types_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", @@ -330,7 +614,9 @@ def test_entity_types_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, @@ -362,12 +648,14 @@ def test_entity_types_client_client_options( ], ) @mock.patch.object( - EntityTypesClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EntityTypesClient) + EntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesClient), ) @mock.patch.object( EntityTypesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EntityTypesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_entity_types_client_mtls_env_auto( @@ -390,7 +678,9 @@ def test_entity_types_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 @@ -422,7 +712,9 @@ def test_entity_types_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 @@ -456,7 +748,9 @@ def test_entity_types_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, @@ -542,6 +836,116 @@ def test_entity_types_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", [EntityTypesClient, EntityTypesAsyncClient]) +@mock.patch.object( + EntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesClient), +) +@mock.patch.object( + EntityTypesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesAsyncClient), +) +def test_entity_types_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EntityTypesClient._DEFAULT_UNIVERSE + default_endpoint = EntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EntityTypesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -568,7 +972,9 @@ def test_entity_types_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, @@ -603,7 +1009,9 @@ def test_entity_types_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, @@ -656,7 +1064,9 @@ def test_entity_types_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, @@ -673,8 +1083,8 @@ def test_entity_types_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -706,7 +1116,7 @@ def test_entity_types_client_create_channel_credentials_file( ) def test_list_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -738,7 +1148,7 @@ def test_list_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -757,7 +1167,7 @@ async def test_list_entity_types_async( transport: str = "grpc_asyncio", request_type=entity_type.ListEntityTypesRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -794,7 +1204,7 @@ async def test_list_entity_types_async_from_dict(): def test_list_entity_types_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -826,7 +1236,7 @@ def test_list_entity_types_field_headers(): @pytest.mark.asyncio async def test_list_entity_types_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -859,7 +1269,7 @@ async def test_list_entity_types_field_headers_async(): def test_list_entity_types_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -889,7 +1299,7 @@ def test_list_entity_types_flattened(): def test_list_entity_types_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -905,7 +1315,7 @@ def test_list_entity_types_flattened_error(): @pytest.mark.asyncio async def test_list_entity_types_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -940,7 +1350,7 @@ async def test_list_entity_types_flattened_async(): @pytest.mark.asyncio async def test_list_entity_types_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -955,7 +1365,7 @@ async def test_list_entity_types_flattened_error_async(): def test_list_entity_types_pager(transport_name: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1007,7 +1417,7 @@ def test_list_entity_types_pager(transport_name: str = "grpc"): def test_list_entity_types_pages(transport_name: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1051,7 +1461,7 @@ def test_list_entity_types_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_entity_types_async_pager(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1103,7 +1513,7 @@ async def test_list_entity_types_async_pager(): @pytest.mark.asyncio async def test_list_entity_types_async_pages(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1160,7 +1570,7 @@ async def test_list_entity_types_async_pages(): ) def test_get_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1201,7 +1611,7 @@ def test_get_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1218,7 +1628,7 @@ async def test_get_entity_type_async( transport: str = "grpc_asyncio", request_type=entity_type.GetEntityTypeRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1264,7 +1674,7 @@ async def test_get_entity_type_async_from_dict(): def test_get_entity_type_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1294,7 +1704,7 @@ def test_get_entity_type_field_headers(): @pytest.mark.asyncio async def test_get_entity_type_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1325,7 +1735,7 @@ async def test_get_entity_type_field_headers_async(): def test_get_entity_type_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1353,7 +1763,7 @@ def test_get_entity_type_flattened(): def test_get_entity_type_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1369,7 +1779,7 @@ def test_get_entity_type_flattened_error(): @pytest.mark.asyncio async def test_get_entity_type_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1402,7 +1812,7 @@ async def test_get_entity_type_flattened_async(): @pytest.mark.asyncio async def test_get_entity_type_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1424,7 +1834,7 @@ async def test_get_entity_type_flattened_error_async(): ) def test_create_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1467,7 +1877,7 @@ def test_create_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1487,7 +1897,7 @@ async def test_create_entity_type_async( request_type=gcd_entity_type.CreateEntityTypeRequest, ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1535,7 +1945,7 @@ async def test_create_entity_type_async_from_dict(): def test_create_entity_type_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1567,7 +1977,7 @@ def test_create_entity_type_field_headers(): @pytest.mark.asyncio async def test_create_entity_type_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1600,7 +2010,7 @@ async def test_create_entity_type_field_headers_async(): def test_create_entity_type_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1634,7 +2044,7 @@ def test_create_entity_type_flattened(): def test_create_entity_type_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1651,7 +2061,7 @@ def test_create_entity_type_flattened_error(): @pytest.mark.asyncio async def test_create_entity_type_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1690,7 +2100,7 @@ async def test_create_entity_type_flattened_async(): @pytest.mark.asyncio async def test_create_entity_type_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1713,7 +2123,7 @@ async def test_create_entity_type_flattened_error_async(): ) def test_update_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1756,7 +2166,7 @@ def test_update_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1776,7 +2186,7 @@ async def test_update_entity_type_async( request_type=gcd_entity_type.UpdateEntityTypeRequest, ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1824,7 +2234,7 @@ async def test_update_entity_type_async_from_dict(): def test_update_entity_type_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1856,7 +2266,7 @@ def test_update_entity_type_field_headers(): @pytest.mark.asyncio async def test_update_entity_type_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1889,7 +2299,7 @@ async def test_update_entity_type_field_headers_async(): def test_update_entity_type_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1919,7 +2329,7 @@ def test_update_entity_type_flattened(): def test_update_entity_type_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1935,7 +2345,7 @@ def test_update_entity_type_flattened_error(): @pytest.mark.asyncio async def test_update_entity_type_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1970,7 +2380,7 @@ async def test_update_entity_type_flattened_async(): @pytest.mark.asyncio async def test_update_entity_type_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1992,7 +2402,7 @@ async def test_update_entity_type_flattened_error_async(): ) def test_delete_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2021,7 +2431,7 @@ def test_delete_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2040,7 +2450,7 @@ async def test_delete_entity_type_async( transport: str = "grpc_asyncio", request_type=entity_type.DeleteEntityTypeRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2072,7 +2482,7 @@ async def test_delete_entity_type_async_from_dict(): def test_delete_entity_type_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2104,7 +2514,7 @@ def test_delete_entity_type_field_headers(): @pytest.mark.asyncio async def test_delete_entity_type_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2135,7 +2545,7 @@ async def test_delete_entity_type_field_headers_async(): def test_delete_entity_type_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2161,7 +2571,7 @@ def test_delete_entity_type_flattened(): def test_delete_entity_type_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2176,7 +2586,7 @@ def test_delete_entity_type_flattened_error(): @pytest.mark.asyncio async def test_delete_entity_type_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2205,7 +2615,7 @@ async def test_delete_entity_type_flattened_async(): @pytest.mark.asyncio async def test_delete_entity_type_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2226,7 +2636,7 @@ async def test_delete_entity_type_flattened_error_async(): ) def test_batch_update_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2255,7 +2665,7 @@ def test_batch_update_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2275,7 +2685,7 @@ async def test_batch_update_entity_types_async( request_type=entity_type.BatchUpdateEntityTypesRequest, ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2309,7 +2719,7 @@ async def test_batch_update_entity_types_async_from_dict(): def test_batch_update_entity_types_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2341,7 +2751,7 @@ def test_batch_update_entity_types_field_headers(): @pytest.mark.asyncio async def test_batch_update_entity_types_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2381,7 +2791,7 @@ async def test_batch_update_entity_types_field_headers_async(): ) def test_batch_delete_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2410,7 +2820,7 @@ def test_batch_delete_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2430,7 +2840,7 @@ async def test_batch_delete_entity_types_async( request_type=entity_type.BatchDeleteEntityTypesRequest, ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2464,7 +2874,7 @@ async def test_batch_delete_entity_types_async_from_dict(): def test_batch_delete_entity_types_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2496,7 +2906,7 @@ def test_batch_delete_entity_types_field_headers(): @pytest.mark.asyncio async def test_batch_delete_entity_types_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2529,7 +2939,7 @@ async def test_batch_delete_entity_types_field_headers_async(): def test_batch_delete_entity_types_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2559,7 +2969,7 @@ def test_batch_delete_entity_types_flattened(): def test_batch_delete_entity_types_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2575,7 +2985,7 @@ def test_batch_delete_entity_types_flattened_error(): @pytest.mark.asyncio async def test_batch_delete_entity_types_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2610,7 +3020,7 @@ async def test_batch_delete_entity_types_flattened_async(): @pytest.mark.asyncio async def test_batch_delete_entity_types_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2632,7 +3042,7 @@ async def test_batch_delete_entity_types_flattened_error_async(): ) def test_batch_create_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2661,7 +3071,7 @@ def test_batch_create_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2680,7 +3090,7 @@ async def test_batch_create_entities_async( transport: str = "grpc_asyncio", request_type=entity_type.BatchCreateEntitiesRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2714,7 +3124,7 @@ async def test_batch_create_entities_async_from_dict(): def test_batch_create_entities_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2746,7 +3156,7 @@ def test_batch_create_entities_field_headers(): @pytest.mark.asyncio async def test_batch_create_entities_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2779,7 +3189,7 @@ async def test_batch_create_entities_field_headers_async(): def test_batch_create_entities_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2813,7 +3223,7 @@ def test_batch_create_entities_flattened(): def test_batch_create_entities_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2830,7 +3240,7 @@ def test_batch_create_entities_flattened_error(): @pytest.mark.asyncio async def test_batch_create_entities_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2869,7 +3279,7 @@ async def test_batch_create_entities_flattened_async(): @pytest.mark.asyncio async def test_batch_create_entities_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2892,7 +3302,7 @@ async def test_batch_create_entities_flattened_error_async(): ) def test_batch_update_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2921,7 +3331,7 @@ def test_batch_update_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2940,7 +3350,7 @@ async def test_batch_update_entities_async( transport: str = "grpc_asyncio", request_type=entity_type.BatchUpdateEntitiesRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2974,7 +3384,7 @@ async def test_batch_update_entities_async_from_dict(): def test_batch_update_entities_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3006,7 +3416,7 @@ def test_batch_update_entities_field_headers(): @pytest.mark.asyncio async def test_batch_update_entities_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3039,7 +3449,7 @@ async def test_batch_update_entities_field_headers_async(): def test_batch_update_entities_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3073,7 +3483,7 @@ def test_batch_update_entities_flattened(): def test_batch_update_entities_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3090,7 +3500,7 @@ def test_batch_update_entities_flattened_error(): @pytest.mark.asyncio async def test_batch_update_entities_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3129,7 +3539,7 @@ async def test_batch_update_entities_flattened_async(): @pytest.mark.asyncio async def test_batch_update_entities_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3152,7 +3562,7 @@ async def test_batch_update_entities_flattened_error_async(): ) def test_batch_delete_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3181,7 +3591,7 @@ def test_batch_delete_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3200,7 +3610,7 @@ async def test_batch_delete_entities_async( transport: str = "grpc_asyncio", request_type=entity_type.BatchDeleteEntitiesRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3234,7 +3644,7 @@ async def test_batch_delete_entities_async_from_dict(): def test_batch_delete_entities_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3266,7 +3676,7 @@ def test_batch_delete_entities_field_headers(): @pytest.mark.asyncio async def test_batch_delete_entities_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3299,7 +3709,7 @@ async def test_batch_delete_entities_field_headers_async(): def test_batch_delete_entities_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3333,7 +3743,7 @@ def test_batch_delete_entities_flattened(): def test_batch_delete_entities_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3350,7 +3760,7 @@ def test_batch_delete_entities_flattened_error(): @pytest.mark.asyncio async def test_batch_delete_entities_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3389,7 +3799,7 @@ async def test_batch_delete_entities_flattened_async(): @pytest.mark.asyncio async def test_batch_delete_entities_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3412,7 +3822,7 @@ async def test_batch_delete_entities_flattened_error_async(): ) def test_list_entity_types_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3463,7 +3873,7 @@ def test_list_entity_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3472,7 +3882,7 @@ def test_list_entity_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_entity_types._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3489,7 +3899,7 @@ def test_list_entity_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3531,7 +3941,7 @@ def test_list_entity_types_rest_required_fields( def test_list_entity_types_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_entity_types._get_unset_required_fields({}) @@ -3550,7 +3960,7 @@ def test_list_entity_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_entity_types_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -3608,7 +4018,7 @@ def test_list_entity_types_rest_bad_request( transport: str = "rest", request_type=entity_type.ListEntityTypesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3630,7 +4040,7 @@ def test_list_entity_types_rest_bad_request( def test_list_entity_types_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3672,7 +4082,7 @@ def test_list_entity_types_rest_flattened(): def test_list_entity_types_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3688,7 +4098,7 @@ def test_list_entity_types_rest_flattened_error(transport: str = "rest"): def test_list_entity_types_rest_pager(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3758,7 +4168,7 @@ def test_list_entity_types_rest_pager(transport: str = "rest"): ) def test_get_entity_type_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3820,7 +4230,7 @@ def test_get_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3829,7 +4239,7 @@ def test_get_entity_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_entity_type._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("language_code",)) @@ -3840,7 +4250,7 @@ def test_get_entity_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3882,7 +4292,7 @@ def test_get_entity_type_rest_required_fields( def test_get_entity_type_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_entity_type._get_unset_required_fields({}) @@ -3892,7 +4302,7 @@ def test_get_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_entity_type_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -3950,7 +4360,7 @@ def test_get_entity_type_rest_bad_request( transport: str = "rest", request_type=entity_type.GetEntityTypeRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3972,7 +4382,7 @@ def test_get_entity_type_rest_bad_request( def test_get_entity_type_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4014,7 +4424,7 @@ def test_get_entity_type_rest_flattened(): def test_get_entity_type_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4030,7 +4440,7 @@ def test_get_entity_type_rest_flattened_error(transport: str = "rest"): def test_get_entity_type_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4043,7 +4453,7 @@ def test_get_entity_type_rest_error(): ) def test_create_entity_type_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4182,7 +4592,7 @@ def test_create_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4191,7 +4601,7 @@ def test_create_entity_type_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_entity_type._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("language_code",)) @@ -4202,7 +4612,7 @@ def test_create_entity_type_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4245,7 +4655,7 @@ def test_create_entity_type_rest_required_fields( def test_create_entity_type_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_entity_type._get_unset_required_fields({}) @@ -4263,7 +4673,7 @@ def test_create_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_entity_type_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -4321,7 +4731,7 @@ def test_create_entity_type_rest_bad_request( transport: str = "rest", request_type=gcd_entity_type.CreateEntityTypeRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4343,7 +4753,7 @@ def test_create_entity_type_rest_bad_request( def test_create_entity_type_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4386,7 +4796,7 @@ def test_create_entity_type_rest_flattened(): def test_create_entity_type_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4403,7 +4813,7 @@ def test_create_entity_type_rest_flattened_error(transport: str = "rest"): def test_create_entity_type_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4416,7 +4826,7 @@ def test_create_entity_type_rest_error(): ) def test_update_entity_type_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4556,14 +4966,14 @@ def test_update_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_entity_type._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4577,7 +4987,7 @@ def test_update_entity_type_rest_required_fields( # verify required fields with non-default values are left alone client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4620,7 +5030,7 @@ def test_update_entity_type_rest_required_fields( def test_update_entity_type_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_entity_type._get_unset_required_fields({}) @@ -4638,7 +5048,7 @@ def test_update_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_entity_type_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -4696,7 +5106,7 @@ def test_update_entity_type_rest_bad_request( transport: str = "rest", request_type=gcd_entity_type.UpdateEntityTypeRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4720,7 +5130,7 @@ def test_update_entity_type_rest_bad_request( def test_update_entity_type_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4765,7 +5175,7 @@ def test_update_entity_type_rest_flattened(): def test_update_entity_type_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4781,7 +5191,7 @@ def test_update_entity_type_rest_flattened_error(transport: str = "rest"): def test_update_entity_type_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4794,7 +5204,7 @@ def test_update_entity_type_rest_error(): ) def test_delete_entity_type_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4840,7 +5250,7 @@ def test_delete_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4849,7 +5259,7 @@ def test_delete_entity_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4858,7 +5268,7 @@ def test_delete_entity_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4897,7 +5307,7 @@ def test_delete_entity_type_rest_required_fields( def test_delete_entity_type_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_entity_type._get_unset_required_fields({}) @@ -4907,7 +5317,7 @@ def test_delete_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_entity_type_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -4957,7 +5367,7 @@ def test_delete_entity_type_rest_bad_request( transport: str = "rest", request_type=entity_type.DeleteEntityTypeRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4979,7 +5389,7 @@ def test_delete_entity_type_rest_bad_request( def test_delete_entity_type_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5018,7 +5428,7 @@ def test_delete_entity_type_rest_flattened(): def test_delete_entity_type_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5033,7 +5443,7 @@ def test_delete_entity_type_rest_flattened_error(transport: str = "rest"): def test_delete_entity_type_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5046,7 +5456,7 @@ def test_delete_entity_type_rest_error(): ) def test_batch_update_entity_types_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5092,7 +5502,7 @@ def test_batch_update_entity_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5101,7 +5511,7 @@ def test_batch_update_entity_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5110,7 +5520,7 @@ def test_batch_update_entity_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5150,7 +5560,7 @@ def test_batch_update_entity_types_rest_required_fields( def test_batch_update_entity_types_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_update_entity_types._get_unset_required_fields({}) @@ -5160,7 +5570,7 @@ def test_batch_update_entity_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_update_entity_types_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -5220,7 +5630,7 @@ def test_batch_update_entity_types_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchUpdateEntityTypesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5242,7 +5652,7 @@ def test_batch_update_entity_types_rest_bad_request( def test_batch_update_entity_types_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5255,7 +5665,7 @@ def test_batch_update_entity_types_rest_error(): ) def test_batch_delete_entity_types_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5302,7 +5712,7 @@ def test_batch_delete_entity_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5312,7 +5722,7 @@ def test_batch_delete_entity_types_rest_required_fields( jsonified_request["entityTypeNames"] = "entity_type_names_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5323,7 +5733,7 @@ def test_batch_delete_entity_types_rest_required_fields( assert jsonified_request["entityTypeNames"] == "entity_type_names_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5363,7 +5773,7 @@ def test_batch_delete_entity_types_rest_required_fields( def test_batch_delete_entity_types_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_delete_entity_types._get_unset_required_fields({}) @@ -5381,7 +5791,7 @@ def test_batch_delete_entity_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_delete_entity_types_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -5441,7 +5851,7 @@ def test_batch_delete_entity_types_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchDeleteEntityTypesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5463,7 +5873,7 @@ def test_batch_delete_entity_types_rest_bad_request( def test_batch_delete_entity_types_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5504,7 +5914,7 @@ def test_batch_delete_entity_types_rest_flattened(): def test_batch_delete_entity_types_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5520,7 +5930,7 @@ def test_batch_delete_entity_types_rest_flattened_error(transport: str = "rest") def test_batch_delete_entity_types_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5533,7 +5943,7 @@ def test_batch_delete_entity_types_rest_error(): ) def test_batch_create_entities_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5579,7 +5989,7 @@ def test_batch_create_entities_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_create_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5588,7 +5998,7 @@ def test_batch_create_entities_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_create_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5597,7 +6007,7 @@ def test_batch_create_entities_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5637,7 +6047,7 @@ def test_batch_create_entities_rest_required_fields( def test_batch_create_entities_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_create_entities._get_unset_required_fields({}) @@ -5655,7 +6065,7 @@ def test_batch_create_entities_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_create_entities_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -5715,7 +6125,7 @@ def test_batch_create_entities_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchCreateEntitiesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5737,7 +6147,7 @@ def test_batch_create_entities_rest_bad_request( def test_batch_create_entities_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5779,7 +6189,7 @@ def test_batch_create_entities_rest_flattened(): def test_batch_create_entities_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5796,7 +6206,7 @@ def test_batch_create_entities_rest_flattened_error(transport: str = "rest"): def test_batch_create_entities_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5809,7 +6219,7 @@ def test_batch_create_entities_rest_error(): ) def test_batch_update_entities_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5855,7 +6265,7 @@ def test_batch_update_entities_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5864,7 +6274,7 @@ def test_batch_update_entities_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5873,7 +6283,7 @@ def test_batch_update_entities_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5913,7 +6323,7 @@ def test_batch_update_entities_rest_required_fields( def test_batch_update_entities_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_update_entities._get_unset_required_fields({}) @@ -5931,7 +6341,7 @@ def test_batch_update_entities_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_update_entities_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -5991,7 +6401,7 @@ def test_batch_update_entities_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchUpdateEntitiesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6013,7 +6423,7 @@ def test_batch_update_entities_rest_bad_request( def test_batch_update_entities_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6055,7 +6465,7 @@ def test_batch_update_entities_rest_flattened(): def test_batch_update_entities_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6072,7 +6482,7 @@ def test_batch_update_entities_rest_flattened_error(transport: str = "rest"): def test_batch_update_entities_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6085,7 +6495,7 @@ def test_batch_update_entities_rest_error(): ) def test_batch_delete_entities_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6132,7 +6542,7 @@ def test_batch_delete_entities_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6142,7 +6552,7 @@ def test_batch_delete_entities_rest_required_fields( jsonified_request["entityValues"] = "entity_values_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6153,7 +6563,7 @@ def test_batch_delete_entities_rest_required_fields( assert jsonified_request["entityValues"] == "entity_values_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6193,7 +6603,7 @@ def test_batch_delete_entities_rest_required_fields( def test_batch_delete_entities_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_delete_entities._get_unset_required_fields({}) @@ -6211,7 +6621,7 @@ def test_batch_delete_entities_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_delete_entities_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -6271,7 +6681,7 @@ def test_batch_delete_entities_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchDeleteEntitiesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6293,7 +6703,7 @@ def test_batch_delete_entities_rest_bad_request( def test_batch_delete_entities_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6335,7 +6745,7 @@ def test_batch_delete_entities_rest_flattened(): def test_batch_delete_entities_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6352,24 +6762,24 @@ def test_batch_delete_entities_rest_flattened_error(transport: str = "rest"): def test_batch_delete_entities_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EntityTypesClient( @@ -6379,7 +6789,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -6390,16 +6800,17 @@ 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 = EntityTypesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EntityTypesClient( @@ -6411,7 +6822,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EntityTypesClient(transport=transport) assert client.transport is transport @@ -6420,13 +6831,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EntityTypesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -6443,7 +6854,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -6457,7 +6868,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = EntityTypesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -6465,7 +6876,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -6477,7 +6888,7 @@ def test_entity_types_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EntityTypesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -6489,7 +6900,7 @@ def test_entity_types_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EntityTypesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6540,7 +6951,7 @@ def test_entity_types_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EntityTypesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6562,7 +6973,7 @@ def test_entity_types_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EntityTypesTransport() adc.assert_called_once() @@ -6570,7 +6981,7 @@ def test_entity_types_base_transport_with_adc(): def test_entity_types_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EntityTypesClient() adc.assert_called_once_with( scopes=None, @@ -6593,7 +7004,7 @@ def test_entity_types_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -6643,7 +7054,7 @@ def test_entity_types_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6671,7 +7082,7 @@ def test_entity_types_transport_create_channel(transport_class, grpc_helpers): [transports.EntityTypesGrpcTransport, transports.EntityTypesGrpcAsyncIOTransport], ) def test_entity_types_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6709,7 +7120,7 @@ def test_entity_types_grpc_transport_client_cert_source_for_mtls(transport_class def test_entity_types_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -6721,7 +7132,7 @@ def test_entity_types_http_transport_client_cert_source_for_mtls(): def test_entity_types_rest_lro_client(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -6746,7 +7157,7 @@ def test_entity_types_rest_lro_client(): ) def test_entity_types_host_no_port(transport_name): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -6769,7 +7180,7 @@ def test_entity_types_host_no_port(transport_name): ) def test_entity_types_host_with_port(transport_name): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -6789,8 +7200,8 @@ def test_entity_types_host_with_port(transport_name): ], ) def test_entity_types_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EntityTypesClient( credentials=creds1, transport=transport_name, @@ -6876,7 +7287,7 @@ def test_entity_types_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6951,7 +7362,7 @@ def test_entity_types_transport_channel_mtls_with_adc(transport_class): def test_entity_types_grpc_lro_client(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -6968,7 +7379,7 @@ def test_entity_types_grpc_lro_client(): def test_entity_types_grpc_lro_async_client(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -7116,7 +7527,7 @@ def test_client_with_default_client_info(): transports.EntityTypesTransport, "_prep_wrapped_messages" ) as prep: client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7126,7 +7537,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EntityTypesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7135,7 +7546,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -7150,7 +7561,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7180,7 +7591,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -7208,7 +7619,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7236,7 +7647,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -7264,7 +7675,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7294,7 +7705,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -7322,7 +7733,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7352,7 +7763,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -7380,7 +7791,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7408,7 +7819,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -7434,7 +7845,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7459,7 +7870,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7483,7 +7894,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7512,7 +7923,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7539,7 +7950,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7557,7 +7968,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7573,7 +7984,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7598,7 +8009,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7624,7 +8035,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7653,7 +8064,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7682,7 +8093,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7700,7 +8111,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7718,7 +8129,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7743,7 +8154,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7769,7 +8180,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7798,7 +8209,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7827,7 +8238,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7845,7 +8256,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7863,7 +8274,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7888,7 +8299,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7914,7 +8325,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7943,7 +8354,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7972,7 +8383,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7990,7 +8401,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8008,7 +8419,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8033,7 +8444,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8058,7 +8469,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = EntityTypesClient(credentials=ga_credentials.AnonymousCredentials()) + client = EntityTypesClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -8085,7 +8496,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = EntityTypesAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = EntityTypesAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -8113,7 +8526,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8131,7 +8544,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8155,7 +8568,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -8172,7 +8585,7 @@ def test_client_ctx(): ] for transport in transports: client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -8203,7 +8616,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_environments.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_environments.py index 633438c70022..f47a11874b0e 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_environments.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_environments.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -70,6 +70,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -96,6 +119,255 @@ def test__get_default_mtls_endpoint(): assert EnvironmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert EnvironmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EnvironmentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EnvironmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EnvironmentsClient._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 EnvironmentsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EnvironmentsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EnvironmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EnvironmentsClient._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 EnvironmentsClient._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 EnvironmentsClient._get_client_cert_source(None, False) is None + assert ( + EnvironmentsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + EnvironmentsClient._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 ( + EnvironmentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + EnvironmentsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EnvironmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsClient), +) +@mock.patch.object( + EnvironmentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EnvironmentsClient._DEFAULT_UNIVERSE + default_endpoint = EnvironmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EnvironmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + EnvironmentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EnvironmentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EnvironmentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + EnvironmentsClient._get_api_endpoint(None, None, default_universe, "always") + == EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EnvironmentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EnvironmentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + EnvironmentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EnvironmentsClient._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 ( + EnvironmentsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + EnvironmentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + EnvironmentsClient._get_universe_domain(None, None) + == EnvironmentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EnvironmentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (EnvironmentsClient, transports.EnvironmentsGrpcTransport, "grpc"), + (EnvironmentsClient, transports.EnvironmentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -105,7 +377,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_environments_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -157,7 +429,7 @@ def test_environments_client_service_account_always_use_jwt( ], ) def test_environments_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -206,19 +478,23 @@ def test_environments_client_get_transport_class(): ], ) @mock.patch.object( - EnvironmentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EnvironmentsClient) + EnvironmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsClient), ) @mock.patch.object( EnvironmentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EnvironmentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsAsyncClient), ) def test_environments_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(EnvironmentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -253,7 +529,9 @@ def test_environments_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 +561,23 @@ def test_environments_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 +587,9 @@ def test_environments_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 +607,9 @@ def test_environments_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 +641,14 @@ def test_environments_client_client_options( ], ) @mock.patch.object( - EnvironmentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EnvironmentsClient) + EnvironmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsClient), ) @mock.patch.object( EnvironmentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EnvironmentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_environments_client_mtls_env_auto( @@ -379,7 +671,9 @@ def test_environments_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 +705,9 @@ def test_environments_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 +741,9 @@ def test_environments_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 +829,116 @@ def test_environments_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", [EnvironmentsClient, EnvironmentsAsyncClient]) +@mock.patch.object( + EnvironmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsClient), +) +@mock.patch.object( + EnvironmentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsAsyncClient), +) +def test_environments_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EnvironmentsClient._DEFAULT_UNIVERSE + default_endpoint = EnvironmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EnvironmentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -557,7 +965,9 @@ def test_environments_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, @@ -597,7 +1007,9 @@ def test_environments_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, @@ -655,7 +1067,9 @@ def test_environments_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, @@ -672,8 +1086,8 @@ def test_environments_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -705,7 +1119,7 @@ def test_environments_client_create_channel_credentials_file( ) def test_list_environments(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -737,7 +1151,7 @@ def test_list_environments_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -756,7 +1170,7 @@ async def test_list_environments_async( transport: str = "grpc_asyncio", request_type=environment.ListEnvironmentsRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -793,7 +1207,7 @@ async def test_list_environments_async_from_dict(): def test_list_environments_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -825,7 +1239,7 @@ def test_list_environments_field_headers(): @pytest.mark.asyncio async def test_list_environments_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -858,7 +1272,7 @@ async def test_list_environments_field_headers_async(): def test_list_environments_flattened(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -884,7 +1298,7 @@ def test_list_environments_flattened(): def test_list_environments_flattened_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -899,7 +1313,7 @@ def test_list_environments_flattened_error(): @pytest.mark.asyncio async def test_list_environments_flattened_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -930,7 +1344,7 @@ async def test_list_environments_flattened_async(): @pytest.mark.asyncio async def test_list_environments_flattened_error_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -944,7 +1358,7 @@ async def test_list_environments_flattened_error_async(): def test_list_environments_pager(transport_name: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -996,7 +1410,7 @@ def test_list_environments_pager(transport_name: str = "grpc"): def test_list_environments_pages(transport_name: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1040,7 +1454,7 @@ def test_list_environments_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_environments_async_pager(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1092,7 +1506,7 @@ async def test_list_environments_async_pager(): @pytest.mark.asyncio async def test_list_environments_async_pages(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1149,7 +1563,7 @@ async def test_list_environments_async_pages(): ) def test_get_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1185,7 +1599,7 @@ def test_get_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1202,7 +1616,7 @@ async def test_get_environment_async( transport: str = "grpc_asyncio", request_type=environment.GetEnvironmentRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1243,7 +1657,7 @@ async def test_get_environment_async_from_dict(): def test_get_environment_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1273,7 +1687,7 @@ def test_get_environment_field_headers(): @pytest.mark.asyncio async def test_get_environment_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1311,7 +1725,7 @@ async def test_get_environment_field_headers_async(): ) def test_create_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1349,7 +1763,7 @@ def test_create_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1368,7 +1782,7 @@ async def test_create_environment_async( transport: str = "grpc_asyncio", request_type=environment.CreateEnvironmentRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1411,7 +1825,7 @@ async def test_create_environment_async_from_dict(): def test_create_environment_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1443,7 +1857,7 @@ def test_create_environment_field_headers(): @pytest.mark.asyncio async def test_create_environment_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1483,7 +1897,7 @@ async def test_create_environment_field_headers_async(): ) def test_update_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1521,7 +1935,7 @@ def test_update_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1540,7 +1954,7 @@ async def test_update_environment_async( transport: str = "grpc_asyncio", request_type=environment.UpdateEnvironmentRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1583,7 +1997,7 @@ async def test_update_environment_async_from_dict(): def test_update_environment_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1615,7 +2029,7 @@ def test_update_environment_field_headers(): @pytest.mark.asyncio async def test_update_environment_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1655,7 +2069,7 @@ async def test_update_environment_field_headers_async(): ) def test_delete_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1684,7 +2098,7 @@ def test_delete_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1703,7 +2117,7 @@ async def test_delete_environment_async( transport: str = "grpc_asyncio", request_type=environment.DeleteEnvironmentRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1735,7 +2149,7 @@ async def test_delete_environment_async_from_dict(): def test_delete_environment_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1767,7 +2181,7 @@ def test_delete_environment_field_headers(): @pytest.mark.asyncio async def test_delete_environment_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1805,7 +2219,7 @@ async def test_delete_environment_field_headers_async(): ) def test_get_environment_history(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1839,7 +2253,7 @@ def test_get_environment_history_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1859,7 +2273,7 @@ async def test_get_environment_history_async( request_type=environment.GetEnvironmentHistoryRequest, ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1898,7 +2312,7 @@ async def test_get_environment_history_async_from_dict(): def test_get_environment_history_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1930,7 +2344,7 @@ def test_get_environment_history_field_headers(): @pytest.mark.asyncio async def test_get_environment_history_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1963,7 +2377,7 @@ async def test_get_environment_history_field_headers_async(): def test_get_environment_history_pager(transport_name: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2015,7 +2429,7 @@ def test_get_environment_history_pager(transport_name: str = "grpc"): def test_get_environment_history_pages(transport_name: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2059,7 +2473,7 @@ def test_get_environment_history_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_get_environment_history_async_pager(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2113,7 +2527,7 @@ async def test_get_environment_history_async_pager(): @pytest.mark.asyncio async def test_get_environment_history_async_pages(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2170,7 +2584,7 @@ async def test_get_environment_history_async_pages(): ) def test_list_environments_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2221,7 +2635,7 @@ def test_list_environments_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_environments._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2230,7 +2644,7 @@ def test_list_environments_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_environments._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2246,7 +2660,7 @@ def test_list_environments_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2288,7 +2702,7 @@ def test_list_environments_rest_required_fields( def test_list_environments_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_environments._get_unset_required_fields({}) @@ -2306,7 +2720,7 @@ def test_list_environments_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_environments_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -2364,7 +2778,7 @@ def test_list_environments_rest_bad_request( transport: str = "rest", request_type=environment.ListEnvironmentsRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2386,7 +2800,7 @@ def test_list_environments_rest_bad_request( def test_list_environments_rest_flattened(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2427,7 +2841,7 @@ def test_list_environments_rest_flattened(): def test_list_environments_rest_flattened_error(transport: str = "rest"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2442,7 +2856,7 @@ def test_list_environments_rest_flattened_error(transport: str = "rest"): def test_list_environments_rest_pager(transport: str = "rest"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2512,7 +2926,7 @@ def test_list_environments_rest_pager(transport: str = "rest"): ) def test_get_environment_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2569,7 +2983,7 @@ def test_get_environment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2578,7 +2992,7 @@ def test_get_environment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2587,7 +3001,7 @@ def test_get_environment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2629,7 +3043,7 @@ def test_get_environment_rest_required_fields( def test_get_environment_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_environment._get_unset_required_fields({}) @@ -2639,7 +3053,7 @@ def test_get_environment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_environment_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -2697,7 +3111,7 @@ def test_get_environment_rest_bad_request( transport: str = "rest", request_type=environment.GetEnvironmentRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2719,7 +3133,7 @@ def test_get_environment_rest_bad_request( def test_get_environment_rest_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2732,7 +3146,7 @@ def test_get_environment_rest_error(): ) def test_create_environment_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2884,7 +3298,7 @@ def test_create_environment_rest_required_fields( assert "environmentId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2896,7 +3310,7 @@ def test_create_environment_rest_required_fields( jsonified_request["environmentId"] = "environment_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_environment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("environment_id",)) @@ -2909,7 +3323,7 @@ def test_create_environment_rest_required_fields( assert jsonified_request["environmentId"] == "environment_id_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2958,7 +3372,7 @@ def test_create_environment_rest_required_fields( def test_create_environment_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_environment._get_unset_required_fields({}) @@ -2977,7 +3391,7 @@ def test_create_environment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_environment_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -3035,7 +3449,7 @@ def test_create_environment_rest_bad_request( transport: str = "rest", request_type=environment.CreateEnvironmentRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3057,7 +3471,7 @@ def test_create_environment_rest_bad_request( def test_create_environment_rest_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3070,7 +3484,7 @@ def test_create_environment_rest_error(): ) def test_update_environment_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3221,14 +3635,14 @@ def test_update_environment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_environment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3242,7 +3656,7 @@ def test_update_environment_rest_required_fields( # verify required fields with non-default values are left alone client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3285,7 +3699,7 @@ def test_update_environment_rest_required_fields( def test_update_environment_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_environment._get_unset_required_fields({}) @@ -3308,7 +3722,7 @@ def test_update_environment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_environment_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -3366,7 +3780,7 @@ def test_update_environment_rest_bad_request( transport: str = "rest", request_type=environment.UpdateEnvironmentRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3390,7 +3804,7 @@ def test_update_environment_rest_bad_request( def test_update_environment_rest_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3403,7 +3817,7 @@ def test_update_environment_rest_error(): ) def test_delete_environment_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3449,7 +3863,7 @@ def test_delete_environment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3458,7 +3872,7 @@ def test_delete_environment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3467,7 +3881,7 @@ def test_delete_environment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3506,7 +3920,7 @@ def test_delete_environment_rest_required_fields( def test_delete_environment_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_environment._get_unset_required_fields({}) @@ -3516,7 +3930,7 @@ def test_delete_environment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_environment_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -3566,7 +3980,7 @@ def test_delete_environment_rest_bad_request( transport: str = "rest", request_type=environment.DeleteEnvironmentRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3588,7 +4002,7 @@ def test_delete_environment_rest_bad_request( def test_delete_environment_rest_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3601,7 +4015,7 @@ def test_delete_environment_rest_error(): ) def test_get_environment_history_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3654,7 +4068,7 @@ def test_get_environment_history_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_environment_history._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3663,7 +4077,7 @@ def test_get_environment_history_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_environment_history._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3679,7 +4093,7 @@ def test_get_environment_history_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3721,7 +4135,7 @@ def test_get_environment_history_rest_required_fields( def test_get_environment_history_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_environment_history._get_unset_required_fields({}) @@ -3739,7 +4153,7 @@ def test_get_environment_history_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_environment_history_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -3797,7 +4211,7 @@ def test_get_environment_history_rest_bad_request( transport: str = "rest", request_type=environment.GetEnvironmentHistoryRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3819,7 +4233,7 @@ def test_get_environment_history_rest_bad_request( def test_get_environment_history_rest_pager(transport: str = "rest"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3881,17 +4295,17 @@ def test_get_environment_history_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EnvironmentsClient( @@ -3901,7 +4315,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3912,16 +4326,17 @@ 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 = EnvironmentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EnvironmentsClient( @@ -3933,7 +4348,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EnvironmentsClient(transport=transport) assert client.transport is transport @@ -3942,13 +4357,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EnvironmentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3965,7 +4380,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3979,7 +4394,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = EnvironmentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3987,7 +4402,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3999,7 +4414,7 @@ def test_environments_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EnvironmentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4011,7 +4426,7 @@ def test_environments_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EnvironmentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4053,7 +4468,7 @@ def test_environments_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EnvironmentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4075,7 +4490,7 @@ def test_environments_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EnvironmentsTransport() adc.assert_called_once() @@ -4083,7 +4498,7 @@ def test_environments_base_transport_with_adc(): def test_environments_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EnvironmentsClient() adc.assert_called_once_with( scopes=None, @@ -4106,7 +4521,7 @@ def test_environments_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4156,7 +4571,7 @@ def test_environments_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4184,7 +4599,7 @@ def test_environments_transport_create_channel(transport_class, grpc_helpers): [transports.EnvironmentsGrpcTransport, transports.EnvironmentsGrpcAsyncIOTransport], ) def test_environments_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4222,7 +4637,7 @@ def test_environments_grpc_transport_client_cert_source_for_mtls(transport_class def test_environments_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4242,7 +4657,7 @@ def test_environments_http_transport_client_cert_source_for_mtls(): ) def test_environments_host_no_port(transport_name): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4265,7 +4680,7 @@ def test_environments_host_no_port(transport_name): ) def test_environments_host_with_port(transport_name): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4285,8 +4700,8 @@ def test_environments_host_with_port(transport_name): ], ) def test_environments_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EnvironmentsClient( credentials=creds1, transport=transport_name, @@ -4360,7 +4775,7 @@ def test_environments_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4609,7 +5024,7 @@ def test_client_with_default_client_info(): transports.EnvironmentsTransport, "_prep_wrapped_messages" ) as prep: client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4619,7 +5034,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EnvironmentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4628,7 +5043,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4643,7 +5058,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4673,7 +5088,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4701,7 +5116,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4729,7 +5144,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4757,7 +5172,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4787,7 +5202,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4815,7 +5230,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4845,7 +5260,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4873,7 +5288,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4901,7 +5316,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4927,7 +5342,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4952,7 +5367,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4976,7 +5391,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5005,7 +5420,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5032,7 +5447,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5050,7 +5465,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5066,7 +5481,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5091,7 +5506,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5117,7 +5532,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5146,7 +5561,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5175,7 +5590,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5193,7 +5608,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5211,7 +5626,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5236,7 +5651,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5262,7 +5677,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5291,7 +5706,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5320,7 +5735,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5338,7 +5753,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5356,7 +5771,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5381,7 +5796,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5407,7 +5822,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5436,7 +5851,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5465,7 +5880,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5483,7 +5898,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5501,7 +5916,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5526,7 +5941,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5551,7 +5966,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = EnvironmentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5578,7 +5993,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = EnvironmentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = EnvironmentsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5606,7 +6023,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5624,7 +6041,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5648,7 +6065,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5665,7 +6082,7 @@ def test_client_ctx(): ] for transport in transports: client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5696,7 +6113,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_fulfillments.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_fulfillments.py index c00b45280442..85ae97b4888d 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_fulfillments.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_fulfillments.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -69,6 +69,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -95,6 +118,255 @@ def test__get_default_mtls_endpoint(): assert FulfillmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert FulfillmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert FulfillmentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert FulfillmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + FulfillmentsClient._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 FulfillmentsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert FulfillmentsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert FulfillmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + FulfillmentsClient._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 FulfillmentsClient._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 FulfillmentsClient._get_client_cert_source(None, False) is None + assert ( + FulfillmentsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + FulfillmentsClient._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 ( + FulfillmentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + FulfillmentsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + FulfillmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsClient), +) +@mock.patch.object( + FulfillmentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = FulfillmentsClient._DEFAULT_UNIVERSE + default_endpoint = FulfillmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = FulfillmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + FulfillmentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + FulfillmentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + FulfillmentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + FulfillmentsClient._get_api_endpoint(None, None, default_universe, "always") + == FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + FulfillmentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + FulfillmentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + FulfillmentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + FulfillmentsClient._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 ( + FulfillmentsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + FulfillmentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + FulfillmentsClient._get_universe_domain(None, None) + == FulfillmentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + FulfillmentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (FulfillmentsClient, transports.FulfillmentsGrpcTransport, "grpc"), + (FulfillmentsClient, transports.FulfillmentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -104,7 +376,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_fulfillments_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -156,7 +428,7 @@ def test_fulfillments_client_service_account_always_use_jwt( ], ) def test_fulfillments_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -205,19 +477,23 @@ def test_fulfillments_client_get_transport_class(): ], ) @mock.patch.object( - FulfillmentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(FulfillmentsClient) + FulfillmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsClient), ) @mock.patch.object( FulfillmentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(FulfillmentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsAsyncClient), ) def test_fulfillments_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(FulfillmentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -252,7 +528,9 @@ def test_fulfillments_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, @@ -282,15 +560,23 @@ def test_fulfillments_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") @@ -300,7 +586,9 @@ def test_fulfillments_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", @@ -318,7 +606,9 @@ def test_fulfillments_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, @@ -350,12 +640,14 @@ def test_fulfillments_client_client_options( ], ) @mock.patch.object( - FulfillmentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(FulfillmentsClient) + FulfillmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsClient), ) @mock.patch.object( FulfillmentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(FulfillmentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_fulfillments_client_mtls_env_auto( @@ -378,7 +670,9 @@ def test_fulfillments_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 @@ -410,7 +704,9 @@ def test_fulfillments_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 @@ -444,7 +740,9 @@ def test_fulfillments_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, @@ -530,6 +828,116 @@ def test_fulfillments_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", [FulfillmentsClient, FulfillmentsAsyncClient]) +@mock.patch.object( + FulfillmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsClient), +) +@mock.patch.object( + FulfillmentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsAsyncClient), +) +def test_fulfillments_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = FulfillmentsClient._DEFAULT_UNIVERSE + default_endpoint = FulfillmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = FulfillmentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -556,7 +964,9 @@ def test_fulfillments_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, @@ -596,7 +1006,9 @@ def test_fulfillments_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, @@ -654,7 +1066,9 @@ def test_fulfillments_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, @@ -671,8 +1085,8 @@ def test_fulfillments_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -704,7 +1118,7 @@ def test_fulfillments_client_create_channel_credentials_file( ) def test_get_fulfillment(request_type, transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -738,7 +1152,7 @@ def test_get_fulfillment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -755,7 +1169,7 @@ async def test_get_fulfillment_async( transport: str = "grpc_asyncio", request_type=fulfillment.GetFulfillmentRequest ): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -794,7 +1208,7 @@ async def test_get_fulfillment_async_from_dict(): def test_get_fulfillment_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -824,7 +1238,7 @@ def test_get_fulfillment_field_headers(): @pytest.mark.asyncio async def test_get_fulfillment_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -855,7 +1269,7 @@ async def test_get_fulfillment_field_headers_async(): def test_get_fulfillment_flattened(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -879,7 +1293,7 @@ def test_get_fulfillment_flattened(): def test_get_fulfillment_flattened_error(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -894,7 +1308,7 @@ def test_get_fulfillment_flattened_error(): @pytest.mark.asyncio async def test_get_fulfillment_flattened_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -923,7 +1337,7 @@ async def test_get_fulfillment_flattened_async(): @pytest.mark.asyncio async def test_get_fulfillment_flattened_error_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -944,7 +1358,7 @@ async def test_get_fulfillment_flattened_error_async(): ) def test_update_fulfillment(request_type, transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -980,7 +1394,7 @@ def test_update_fulfillment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1000,7 +1414,7 @@ async def test_update_fulfillment_async( request_type=gcd_fulfillment.UpdateFulfillmentRequest, ): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1041,7 +1455,7 @@ async def test_update_fulfillment_async_from_dict(): def test_update_fulfillment_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1073,7 +1487,7 @@ def test_update_fulfillment_field_headers(): @pytest.mark.asyncio async def test_update_fulfillment_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1106,7 +1520,7 @@ async def test_update_fulfillment_field_headers_async(): def test_update_fulfillment_flattened(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1136,7 +1550,7 @@ def test_update_fulfillment_flattened(): def test_update_fulfillment_flattened_error(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1152,7 +1566,7 @@ def test_update_fulfillment_flattened_error(): @pytest.mark.asyncio async def test_update_fulfillment_flattened_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1187,7 +1601,7 @@ async def test_update_fulfillment_flattened_async(): @pytest.mark.asyncio async def test_update_fulfillment_flattened_error_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1209,7 +1623,7 @@ async def test_update_fulfillment_flattened_error_async(): ) def test_get_fulfillment_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1264,7 +1678,7 @@ def test_get_fulfillment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_fulfillment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1273,7 +1687,7 @@ def test_get_fulfillment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_fulfillment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1282,7 +1696,7 @@ def test_get_fulfillment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1324,7 +1738,7 @@ def test_get_fulfillment_rest_required_fields( def test_get_fulfillment_rest_unset_required_fields(): transport = transports.FulfillmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_fulfillment._get_unset_required_fields({}) @@ -1334,7 +1748,7 @@ def test_get_fulfillment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_fulfillment_rest_interceptors(null_interceptor): transport = transports.FulfillmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FulfillmentsRestInterceptor(), @@ -1392,7 +1806,7 @@ def test_get_fulfillment_rest_bad_request( transport: str = "rest", request_type=fulfillment.GetFulfillmentRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1414,7 +1828,7 @@ def test_get_fulfillment_rest_bad_request( def test_get_fulfillment_rest_flattened(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1455,7 +1869,7 @@ def test_get_fulfillment_rest_flattened(): def test_get_fulfillment_rest_flattened_error(transport: str = "rest"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1470,7 +1884,7 @@ def test_get_fulfillment_rest_flattened_error(transport: str = "rest"): def test_get_fulfillment_rest_error(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -1483,7 +1897,7 @@ def test_get_fulfillment_rest_error(): ) def test_update_fulfillment_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1617,14 +2031,14 @@ def test_update_fulfillment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_fulfillment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_fulfillment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -1633,7 +2047,7 @@ def test_update_fulfillment_rest_required_fields( # verify required fields with non-default values are left alone client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1676,7 +2090,7 @@ def test_update_fulfillment_rest_required_fields( def test_update_fulfillment_rest_unset_required_fields(): transport = transports.FulfillmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_fulfillment._get_unset_required_fields({}) @@ -1694,7 +2108,7 @@ def test_update_fulfillment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_fulfillment_rest_interceptors(null_interceptor): transport = transports.FulfillmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FulfillmentsRestInterceptor(), @@ -1752,7 +2166,7 @@ def test_update_fulfillment_rest_bad_request( transport: str = "rest", request_type=gcd_fulfillment.UpdateFulfillmentRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1774,7 +2188,7 @@ def test_update_fulfillment_rest_bad_request( def test_update_fulfillment_rest_flattened(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1817,7 +2231,7 @@ def test_update_fulfillment_rest_flattened(): def test_update_fulfillment_rest_flattened_error(transport: str = "rest"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1833,24 +2247,24 @@ def test_update_fulfillment_rest_flattened_error(transport: str = "rest"): def test_update_fulfillment_rest_error(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = FulfillmentsClient( @@ -1860,7 +2274,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1871,16 +2285,17 @@ 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 = FulfillmentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = FulfillmentsClient( @@ -1892,7 +2307,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = FulfillmentsClient(transport=transport) assert client.transport is transport @@ -1901,13 +2316,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.FulfillmentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1924,7 +2339,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1938,7 +2353,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = FulfillmentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1946,7 +2361,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1958,7 +2373,7 @@ def test_fulfillments_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.FulfillmentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1970,7 +2385,7 @@ def test_fulfillments_base_transport(): ) as Transport: Transport.return_value = None transport = transports.FulfillmentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -2008,7 +2423,7 @@ def test_fulfillments_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.FulfillmentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2030,7 +2445,7 @@ def test_fulfillments_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.FulfillmentsTransport() adc.assert_called_once() @@ -2038,7 +2453,7 @@ def test_fulfillments_base_transport_with_adc(): def test_fulfillments_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) FulfillmentsClient() adc.assert_called_once_with( scopes=None, @@ -2061,7 +2476,7 @@ def test_fulfillments_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2111,7 +2526,7 @@ def test_fulfillments_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2139,7 +2554,7 @@ def test_fulfillments_transport_create_channel(transport_class, grpc_helpers): [transports.FulfillmentsGrpcTransport, transports.FulfillmentsGrpcAsyncIOTransport], ) def test_fulfillments_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2177,7 +2592,7 @@ def test_fulfillments_grpc_transport_client_cert_source_for_mtls(transport_class def test_fulfillments_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -2197,7 +2612,7 @@ def test_fulfillments_http_transport_client_cert_source_for_mtls(): ) def test_fulfillments_host_no_port(transport_name): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -2220,7 +2635,7 @@ def test_fulfillments_host_no_port(transport_name): ) def test_fulfillments_host_with_port(transport_name): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -2240,8 +2655,8 @@ def test_fulfillments_host_with_port(transport_name): ], ) def test_fulfillments_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = FulfillmentsClient( credentials=creds1, transport=transport_name, @@ -2303,7 +2718,7 @@ def test_fulfillments_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2506,7 +2921,7 @@ def test_client_with_default_client_info(): transports.FulfillmentsTransport, "_prep_wrapped_messages" ) as prep: client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2516,7 +2931,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = FulfillmentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2525,7 +2940,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2540,7 +2955,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2570,7 +2985,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -2598,7 +3013,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2626,7 +3041,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2654,7 +3069,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2684,7 +3099,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2712,7 +3127,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2742,7 +3157,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2770,7 +3185,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2798,7 +3213,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2824,7 +3239,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2849,7 +3264,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2873,7 +3288,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2902,7 +3317,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2929,7 +3344,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -2947,7 +3362,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -2963,7 +3378,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2988,7 +3403,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3014,7 +3429,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3043,7 +3458,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3072,7 +3487,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3090,7 +3505,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3108,7 +3523,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3133,7 +3548,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3159,7 +3574,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3188,7 +3603,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3217,7 +3632,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3235,7 +3650,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3253,7 +3668,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3278,7 +3693,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3304,7 +3719,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3333,7 +3748,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3362,7 +3777,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3380,7 +3795,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3398,7 +3813,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3423,7 +3838,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3448,7 +3863,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = FulfillmentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = FulfillmentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -3475,7 +3890,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = FulfillmentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = FulfillmentsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -3503,7 +3920,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3521,7 +3938,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3545,7 +3962,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3562,7 +3979,7 @@ def test_client_ctx(): ] for transport in transports: client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3593,7 +4010,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_intents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_intents.py index 05c0d33122c8..bdd7ac920966 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_intents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_intents.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -82,6 +82,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -105,6 +128,238 @@ def test__get_default_mtls_endpoint(): assert IntentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert IntentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert IntentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert IntentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + IntentsClient._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 IntentsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert IntentsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert IntentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + IntentsClient._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 IntentsClient._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 IntentsClient._get_client_cert_source(None, False) is None + assert ( + IntentsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + IntentsClient._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 ( + IntentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + IntentsClient._get_client_cert_source(mock_provided_cert_source, "true") + is mock_provided_cert_source + ) + + +@mock.patch.object( + IntentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsClient), +) +@mock.patch.object( + IntentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = IntentsClient._DEFAULT_UNIVERSE + default_endpoint = IntentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = IntentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + IntentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + IntentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == IntentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + IntentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + IntentsClient._get_api_endpoint(None, None, default_universe, "always") + == IntentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + IntentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == IntentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + IntentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + IntentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + IntentsClient._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 ( + IntentsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + IntentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + IntentsClient._get_universe_domain(None, None) + == IntentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + IntentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (IntentsClient, transports.IntentsGrpcTransport, "grpc"), + (IntentsClient, transports.IntentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -114,7 +369,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_intents_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -164,7 +419,7 @@ def test_intents_client_service_account_always_use_jwt(transport_class, transpor ], ) def test_intents_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -209,15 +464,21 @@ def test_intents_client_get_transport_class(): ], ) @mock.patch.object( - IntentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IntentsClient) + IntentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsClient), ) @mock.patch.object( - IntentsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IntentsAsyncClient) + IntentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsAsyncClient), ) def test_intents_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(IntentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -252,7 +513,9 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -282,15 +545,23 @@ def test_intents_client_client_options(client_class, transport_class, transport_ # 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") @@ -300,7 +571,9 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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", @@ -318,7 +591,9 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -350,10 +625,14 @@ def test_intents_client_client_options(client_class, transport_class, transport_ ], ) @mock.patch.object( - IntentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IntentsClient) + IntentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsClient), ) @mock.patch.object( - IntentsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IntentsAsyncClient) + IntentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_intents_client_mtls_env_auto( @@ -376,7 +655,9 @@ def test_intents_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 @@ -408,7 +689,9 @@ def test_intents_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 @@ -442,7 +725,9 @@ def test_intents_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, @@ -526,6 +811,116 @@ def test_intents_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", [IntentsClient, IntentsAsyncClient]) +@mock.patch.object( + IntentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsClient), +) +@mock.patch.object( + IntentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsAsyncClient), +) +def test_intents_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = IntentsClient._DEFAULT_UNIVERSE + default_endpoint = IntentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = IntentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -548,7 +943,9 @@ def test_intents_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, @@ -583,7 +980,9 @@ def test_intents_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, @@ -636,7 +1035,9 @@ def test_intents_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, @@ -653,8 +1054,8 @@ def test_intents_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -686,7 +1087,7 @@ def test_intents_client_create_channel_credentials_file( ) def test_list_intents(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -716,7 +1117,7 @@ def test_list_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -733,7 +1134,7 @@ async def test_list_intents_async( transport: str = "grpc_asyncio", request_type=intent.ListIntentsRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -768,7 +1169,7 @@ async def test_list_intents_async_from_dict(): def test_list_intents_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -798,7 +1199,7 @@ def test_list_intents_field_headers(): @pytest.mark.asyncio async def test_list_intents_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -829,7 +1230,7 @@ async def test_list_intents_field_headers_async(): def test_list_intents_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -857,7 +1258,7 @@ def test_list_intents_flattened(): def test_list_intents_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -873,7 +1274,7 @@ def test_list_intents_flattened_error(): @pytest.mark.asyncio async def test_list_intents_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -906,7 +1307,7 @@ async def test_list_intents_flattened_async(): @pytest.mark.asyncio async def test_list_intents_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -921,7 +1322,7 @@ async def test_list_intents_flattened_error_async(): def test_list_intents_pager(transport_name: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -971,7 +1372,7 @@ def test_list_intents_pager(transport_name: str = "grpc"): def test_list_intents_pages(transport_name: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1013,7 +1414,7 @@ def test_list_intents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_intents_async_pager(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1063,7 +1464,7 @@ async def test_list_intents_async_pager(): @pytest.mark.asyncio async def test_list_intents_async_pages(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1118,7 +1519,7 @@ async def test_list_intents_async_pages(): ) def test_get_intent(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1178,7 +1579,7 @@ def test_get_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1195,7 +1596,7 @@ async def test_get_intent_async( transport: str = "grpc_asyncio", request_type=intent.GetIntentRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1260,7 +1661,7 @@ async def test_get_intent_async_from_dict(): def test_get_intent_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1290,7 +1691,7 @@ def test_get_intent_field_headers(): @pytest.mark.asyncio async def test_get_intent_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1319,7 +1720,7 @@ async def test_get_intent_field_headers_async(): def test_get_intent_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1347,7 +1748,7 @@ def test_get_intent_flattened(): def test_get_intent_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1363,7 +1764,7 @@ def test_get_intent_flattened_error(): @pytest.mark.asyncio async def test_get_intent_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1394,7 +1795,7 @@ async def test_get_intent_flattened_async(): @pytest.mark.asyncio async def test_get_intent_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1416,7 +1817,7 @@ async def test_get_intent_flattened_error_async(): ) def test_create_intent(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1478,7 +1879,7 @@ def test_create_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1495,7 +1896,7 @@ async def test_create_intent_async( transport: str = "grpc_asyncio", request_type=gcd_intent.CreateIntentRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1564,7 +1965,7 @@ async def test_create_intent_async_from_dict(): def test_create_intent_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1594,7 +1995,7 @@ def test_create_intent_field_headers(): @pytest.mark.asyncio async def test_create_intent_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1623,7 +2024,7 @@ async def test_create_intent_field_headers_async(): def test_create_intent_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1655,7 +2056,7 @@ def test_create_intent_flattened(): def test_create_intent_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1672,7 +2073,7 @@ def test_create_intent_flattened_error(): @pytest.mark.asyncio async def test_create_intent_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1707,7 +2108,7 @@ async def test_create_intent_flattened_async(): @pytest.mark.asyncio async def test_create_intent_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1730,7 +2131,7 @@ async def test_create_intent_flattened_error_async(): ) def test_update_intent(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1792,7 +2193,7 @@ def test_update_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1809,7 +2210,7 @@ async def test_update_intent_async( transport: str = "grpc_asyncio", request_type=gcd_intent.UpdateIntentRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1878,7 +2279,7 @@ async def test_update_intent_async_from_dict(): def test_update_intent_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1908,7 +2309,7 @@ def test_update_intent_field_headers(): @pytest.mark.asyncio async def test_update_intent_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1937,7 +2338,7 @@ async def test_update_intent_field_headers_async(): def test_update_intent_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1969,7 +2370,7 @@ def test_update_intent_flattened(): def test_update_intent_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1986,7 +2387,7 @@ def test_update_intent_flattened_error(): @pytest.mark.asyncio async def test_update_intent_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2021,7 +2422,7 @@ async def test_update_intent_flattened_async(): @pytest.mark.asyncio async def test_update_intent_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2044,7 +2445,7 @@ async def test_update_intent_flattened_error_async(): ) def test_delete_intent(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2071,7 +2472,7 @@ def test_delete_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2088,7 +2489,7 @@ async def test_delete_intent_async( transport: str = "grpc_asyncio", request_type=intent.DeleteIntentRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2118,7 +2519,7 @@ async def test_delete_intent_async_from_dict(): def test_delete_intent_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2148,7 +2549,7 @@ def test_delete_intent_field_headers(): @pytest.mark.asyncio async def test_delete_intent_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2177,7 +2578,7 @@ async def test_delete_intent_field_headers_async(): def test_delete_intent_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2201,7 +2602,7 @@ def test_delete_intent_flattened(): def test_delete_intent_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2216,7 +2617,7 @@ def test_delete_intent_flattened_error(): @pytest.mark.asyncio async def test_delete_intent_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2243,7 +2644,7 @@ async def test_delete_intent_flattened_async(): @pytest.mark.asyncio async def test_delete_intent_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2264,7 +2665,7 @@ async def test_delete_intent_flattened_error_async(): ) def test_batch_update_intents(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2293,7 +2694,7 @@ def test_batch_update_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2312,7 +2713,7 @@ async def test_batch_update_intents_async( transport: str = "grpc_asyncio", request_type=intent.BatchUpdateIntentsRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2346,7 +2747,7 @@ async def test_batch_update_intents_async_from_dict(): def test_batch_update_intents_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2378,7 +2779,7 @@ def test_batch_update_intents_field_headers(): @pytest.mark.asyncio async def test_batch_update_intents_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2411,7 +2812,7 @@ async def test_batch_update_intents_field_headers_async(): def test_batch_update_intents_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2444,7 +2845,7 @@ def test_batch_update_intents_flattened(): def test_batch_update_intents_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2463,7 +2864,7 @@ def test_batch_update_intents_flattened_error(): @pytest.mark.asyncio async def test_batch_update_intents_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2501,7 +2902,7 @@ async def test_batch_update_intents_flattened_async(): @pytest.mark.asyncio async def test_batch_update_intents_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2526,7 +2927,7 @@ async def test_batch_update_intents_flattened_error_async(): ) def test_batch_delete_intents(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2555,7 +2956,7 @@ def test_batch_delete_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2574,7 +2975,7 @@ async def test_batch_delete_intents_async( transport: str = "grpc_asyncio", request_type=intent.BatchDeleteIntentsRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2608,7 +3009,7 @@ async def test_batch_delete_intents_async_from_dict(): def test_batch_delete_intents_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2640,7 +3041,7 @@ def test_batch_delete_intents_field_headers(): @pytest.mark.asyncio async def test_batch_delete_intents_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2673,7 +3074,7 @@ async def test_batch_delete_intents_field_headers_async(): def test_batch_delete_intents_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2703,7 +3104,7 @@ def test_batch_delete_intents_flattened(): def test_batch_delete_intents_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2719,7 +3120,7 @@ def test_batch_delete_intents_flattened_error(): @pytest.mark.asyncio async def test_batch_delete_intents_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2754,7 +3155,7 @@ async def test_batch_delete_intents_flattened_async(): @pytest.mark.asyncio async def test_batch_delete_intents_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2776,7 +3177,7 @@ async def test_batch_delete_intents_flattened_error_async(): ) def test_list_intents_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2825,7 +3226,7 @@ def test_list_intents_rest_required_fields(request_type=intent.ListIntentsReques # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2834,7 +3235,7 @@ def test_list_intents_rest_required_fields(request_type=intent.ListIntentsReques jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_intents._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2852,7 +3253,7 @@ def test_list_intents_rest_required_fields(request_type=intent.ListIntentsReques assert jsonified_request["parent"] == "parent_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2894,7 +3295,7 @@ def test_list_intents_rest_required_fields(request_type=intent.ListIntentsReques def test_list_intents_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_intents._get_unset_required_fields({}) @@ -2914,7 +3315,7 @@ def test_list_intents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_intents_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -2968,7 +3369,7 @@ def test_list_intents_rest_bad_request( transport: str = "rest", request_type=intent.ListIntentsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2990,7 +3391,7 @@ def test_list_intents_rest_bad_request( def test_list_intents_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3031,7 +3432,7 @@ def test_list_intents_rest_flattened(): def test_list_intents_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3047,7 +3448,7 @@ def test_list_intents_rest_flattened_error(transport: str = "rest"): def test_list_intents_rest_pager(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3115,7 +3516,7 @@ def test_list_intents_rest_pager(transport: str = "rest"): ) def test_get_intent_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3194,7 +3595,7 @@ def test_get_intent_rest_required_fields(request_type=intent.GetIntentRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3203,7 +3604,7 @@ def test_get_intent_rest_required_fields(request_type=intent.GetIntentRequest): jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_intent._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3219,7 +3620,7 @@ def test_get_intent_rest_required_fields(request_type=intent.GetIntentRequest): assert jsonified_request["name"] == "name_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3261,7 +3662,7 @@ def test_get_intent_rest_required_fields(request_type=intent.GetIntentRequest): def test_get_intent_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_intent._get_unset_required_fields({}) @@ -3279,7 +3680,7 @@ def test_get_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_intent_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -3331,7 +3732,7 @@ def test_get_intent_rest_bad_request( transport: str = "rest", request_type=intent.GetIntentRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3353,7 +3754,7 @@ def test_get_intent_rest_bad_request( def test_get_intent_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3394,7 +3795,7 @@ def test_get_intent_rest_flattened(): def test_get_intent_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3410,7 +3811,7 @@ def test_get_intent_rest_flattened_error(transport: str = "rest"): def test_get_intent_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3423,7 +3824,7 @@ def test_get_intent_rest_error(): ) def test_create_intent_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3737,7 +4138,7 @@ def test_create_intent_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3746,7 +4147,7 @@ def test_create_intent_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_intent._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3762,7 +4163,7 @@ def test_create_intent_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3805,7 +4206,7 @@ def test_create_intent_rest_required_fields( def test_create_intent_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_intent._get_unset_required_fields({}) @@ -3828,7 +4229,7 @@ def test_create_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_intent_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -3880,7 +4281,7 @@ def test_create_intent_rest_bad_request( transport: str = "rest", request_type=gcd_intent.CreateIntentRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3902,7 +4303,7 @@ def test_create_intent_rest_bad_request( def test_create_intent_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3944,7 +4345,7 @@ def test_create_intent_rest_flattened(): def test_create_intent_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3961,7 +4362,7 @@ def test_create_intent_rest_flattened_error(transport: str = "rest"): def test_create_intent_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3974,7 +4375,7 @@ def test_create_intent_rest_error(): ) def test_update_intent_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4287,14 +4688,14 @@ def test_update_intent_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_intent._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4309,7 +4710,7 @@ def test_update_intent_rest_required_fields( # verify required fields with non-default values are left alone client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4352,7 +4753,7 @@ def test_update_intent_rest_required_fields( def test_update_intent_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_intent._get_unset_required_fields({}) @@ -4371,7 +4772,7 @@ def test_update_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_intent_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -4423,7 +4824,7 @@ def test_update_intent_rest_bad_request( transport: str = "rest", request_type=gcd_intent.UpdateIntentRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4445,7 +4846,7 @@ def test_update_intent_rest_bad_request( def test_update_intent_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4488,7 +4889,7 @@ def test_update_intent_rest_flattened(): def test_update_intent_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4505,7 +4906,7 @@ def test_update_intent_rest_flattened_error(transport: str = "rest"): def test_update_intent_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4518,7 +4919,7 @@ def test_update_intent_rest_error(): ) def test_delete_intent_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4562,7 +4963,7 @@ def test_delete_intent_rest_required_fields(request_type=intent.DeleteIntentRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4571,7 +4972,7 @@ def test_delete_intent_rest_required_fields(request_type=intent.DeleteIntentRequ jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4580,7 +4981,7 @@ def test_delete_intent_rest_required_fields(request_type=intent.DeleteIntentRequ assert jsonified_request["name"] == "name_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4619,7 +5020,7 @@ def test_delete_intent_rest_required_fields(request_type=intent.DeleteIntentRequ def test_delete_intent_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_intent._get_unset_required_fields({}) @@ -4629,7 +5030,7 @@ def test_delete_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_intent_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -4675,7 +5076,7 @@ def test_delete_intent_rest_bad_request( transport: str = "rest", request_type=intent.DeleteIntentRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4697,7 +5098,7 @@ def test_delete_intent_rest_bad_request( def test_delete_intent_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4735,7 +5136,7 @@ def test_delete_intent_rest_flattened(): def test_delete_intent_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4750,7 +5151,7 @@ def test_delete_intent_rest_flattened_error(transport: str = "rest"): def test_delete_intent_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4763,7 +5164,7 @@ def test_delete_intent_rest_error(): ) def test_batch_update_intents_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4809,7 +5210,7 @@ def test_batch_update_intents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4818,7 +5219,7 @@ def test_batch_update_intents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4827,7 +5228,7 @@ def test_batch_update_intents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4867,7 +5268,7 @@ def test_batch_update_intents_rest_required_fields( def test_batch_update_intents_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_update_intents._get_unset_required_fields({}) @@ -4877,7 +5278,7 @@ def test_batch_update_intents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_update_intents_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -4935,7 +5336,7 @@ def test_batch_update_intents_rest_bad_request( transport: str = "rest", request_type=intent.BatchUpdateIntentsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4957,7 +5358,7 @@ def test_batch_update_intents_rest_bad_request( def test_batch_update_intents_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4997,7 +5398,7 @@ def test_batch_update_intents_rest_flattened(): def test_batch_update_intents_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5016,7 +5417,7 @@ def test_batch_update_intents_rest_flattened_error(transport: str = "rest"): def test_batch_update_intents_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5029,7 +5430,7 @@ def test_batch_update_intents_rest_error(): ) def test_batch_delete_intents_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5075,7 +5476,7 @@ def test_batch_delete_intents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5084,7 +5485,7 @@ def test_batch_delete_intents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5093,7 +5494,7 @@ def test_batch_delete_intents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5133,7 +5534,7 @@ def test_batch_delete_intents_rest_required_fields( def test_batch_delete_intents_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_delete_intents._get_unset_required_fields({}) @@ -5151,7 +5552,7 @@ def test_batch_delete_intents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_delete_intents_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -5209,7 +5610,7 @@ def test_batch_delete_intents_rest_bad_request( transport: str = "rest", request_type=intent.BatchDeleteIntentsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5231,7 +5632,7 @@ def test_batch_delete_intents_rest_bad_request( def test_batch_delete_intents_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5272,7 +5673,7 @@ def test_batch_delete_intents_rest_flattened(): def test_batch_delete_intents_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5288,24 +5689,24 @@ def test_batch_delete_intents_rest_flattened_error(transport: str = "rest"): def test_batch_delete_intents_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = IntentsClient( @@ -5315,7 +5716,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5326,16 +5727,17 @@ 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 = IntentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = IntentsClient( @@ -5347,7 +5749,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = IntentsClient(transport=transport) assert client.transport is transport @@ -5356,13 +5758,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.IntentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5379,7 +5781,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5393,7 +5795,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = IntentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5401,7 +5803,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5413,7 +5815,7 @@ def test_intents_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.IntentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5425,7 +5827,7 @@ def test_intents_base_transport(): ) as Transport: Transport.return_value = None transport = transports.IntentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5473,7 +5875,7 @@ def test_intents_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.intents.transports.IntentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.IntentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5495,7 +5897,7 @@ def test_intents_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.intents.transports.IntentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.IntentsTransport() adc.assert_called_once() @@ -5503,7 +5905,7 @@ def test_intents_base_transport_with_adc(): def test_intents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) IntentsClient() adc.assert_called_once_with( scopes=None, @@ -5526,7 +5928,7 @@ def test_intents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5576,7 +5978,7 @@ def test_intents_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5604,7 +6006,7 @@ def test_intents_transport_create_channel(transport_class, grpc_helpers): [transports.IntentsGrpcTransport, transports.IntentsGrpcAsyncIOTransport], ) def test_intents_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5642,7 +6044,7 @@ def test_intents_grpc_transport_client_cert_source_for_mtls(transport_class): def test_intents_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5654,7 +6056,7 @@ def test_intents_http_transport_client_cert_source_for_mtls(): def test_intents_rest_lro_client(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5679,7 +6081,7 @@ def test_intents_rest_lro_client(): ) def test_intents_host_no_port(transport_name): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -5702,7 +6104,7 @@ def test_intents_host_no_port(transport_name): ) def test_intents_host_with_port(transport_name): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -5722,8 +6124,8 @@ def test_intents_host_with_port(transport_name): ], ) def test_intents_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = IntentsClient( credentials=creds1, transport=transport_name, @@ -5800,7 +6202,7 @@ def test_intents_transport_channel_mtls_with_client_cert_source(transport_class) mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5875,7 +6277,7 @@ def test_intents_transport_channel_mtls_with_adc(transport_class): def test_intents_grpc_lro_client(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5892,7 +6294,7 @@ def test_intents_grpc_lro_client(): def test_intents_grpc_lro_async_client(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -6066,7 +6468,7 @@ def test_client_with_default_client_info(): transports.IntentsTransport, "_prep_wrapped_messages" ) as prep: client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6076,7 +6478,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = IntentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6085,7 +6487,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6100,7 +6502,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6130,7 +6532,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -6158,7 +6560,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6186,7 +6588,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6214,7 +6616,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6244,7 +6646,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6272,7 +6674,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6302,7 +6704,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6330,7 +6732,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6358,7 +6760,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6384,7 +6786,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6409,7 +6811,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6433,7 +6835,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6462,7 +6864,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6489,7 +6891,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6507,7 +6909,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6523,7 +6925,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6548,7 +6950,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6574,7 +6976,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6603,7 +7005,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6632,7 +7034,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6650,7 +7052,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6668,7 +7070,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6693,7 +7095,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6719,7 +7121,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6748,7 +7150,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6777,7 +7179,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6795,7 +7197,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6813,7 +7215,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6838,7 +7240,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6864,7 +7266,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6893,7 +7295,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6922,7 +7324,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6940,7 +7342,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6958,7 +7360,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6983,7 +7385,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7008,7 +7410,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = IntentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = IntentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7035,7 +7437,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = IntentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = IntentsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7063,7 +7465,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7081,7 +7483,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7105,7 +7507,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7122,7 +7524,7 @@ def test_client_ctx(): ] for transport in transports: client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7153,7 +7555,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py index 5b907f6502f6..2ca60385ed18 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_knowledge_bases.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -70,6 +70,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -99,6 +122,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert KnowledgeBasesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert KnowledgeBasesClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert KnowledgeBasesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + KnowledgeBasesClient._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 KnowledgeBasesClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert KnowledgeBasesClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert KnowledgeBasesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + KnowledgeBasesClient._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 KnowledgeBasesClient._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 KnowledgeBasesClient._get_client_cert_source(None, False) is None + assert ( + KnowledgeBasesClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + KnowledgeBasesClient._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 ( + KnowledgeBasesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + KnowledgeBasesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + KnowledgeBasesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesClient), +) +@mock.patch.object( + KnowledgeBasesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = KnowledgeBasesClient._DEFAULT_UNIVERSE + default_endpoint = KnowledgeBasesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = KnowledgeBasesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + KnowledgeBasesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + KnowledgeBasesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + KnowledgeBasesClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + KnowledgeBasesClient._get_api_endpoint(None, None, default_universe, "always") + == KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + KnowledgeBasesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + KnowledgeBasesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + KnowledgeBasesClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + KnowledgeBasesClient._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 ( + KnowledgeBasesClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + KnowledgeBasesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + KnowledgeBasesClient._get_universe_domain(None, None) + == KnowledgeBasesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + KnowledgeBasesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (KnowledgeBasesClient, transports.KnowledgeBasesGrpcTransport, "grpc"), + (KnowledgeBasesClient, transports.KnowledgeBasesRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -108,7 +392,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_knowledge_bases_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -160,7 +444,7 @@ def test_knowledge_bases_client_service_account_always_use_jwt( ], ) def test_knowledge_bases_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -210,20 +494,22 @@ def test_knowledge_bases_client_get_transport_class(): ) @mock.patch.object( KnowledgeBasesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(KnowledgeBasesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesClient), ) @mock.patch.object( KnowledgeBasesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(KnowledgeBasesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesAsyncClient), ) def test_knowledge_bases_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(KnowledgeBasesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -258,7 +544,9 @@ def test_knowledge_bases_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, @@ -288,15 +576,23 @@ def test_knowledge_bases_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") @@ -306,7 +602,9 @@ def test_knowledge_bases_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", @@ -324,7 +622,9 @@ def test_knowledge_bases_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, @@ -357,13 +657,13 @@ def test_knowledge_bases_client_client_options( ) @mock.patch.object( KnowledgeBasesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(KnowledgeBasesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesClient), ) @mock.patch.object( KnowledgeBasesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(KnowledgeBasesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_knowledge_bases_client_mtls_env_auto( @@ -386,7 +686,9 @@ def test_knowledge_bases_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 @@ -418,7 +720,9 @@ def test_knowledge_bases_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 @@ -452,7 +756,9 @@ def test_knowledge_bases_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, @@ -542,6 +848,118 @@ def test_knowledge_bases_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", [KnowledgeBasesClient, KnowledgeBasesAsyncClient] +) +@mock.patch.object( + KnowledgeBasesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesClient), +) +@mock.patch.object( + KnowledgeBasesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesAsyncClient), +) +def test_knowledge_bases_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = KnowledgeBasesClient._DEFAULT_UNIVERSE + default_endpoint = KnowledgeBasesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = KnowledgeBasesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -568,7 +986,9 @@ def test_knowledge_bases_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, @@ -608,7 +1028,9 @@ def test_knowledge_bases_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, @@ -668,7 +1090,9 @@ def test_knowledge_bases_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, @@ -685,8 +1109,8 @@ def test_knowledge_bases_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -718,7 +1142,7 @@ def test_knowledge_bases_client_create_channel_credentials_file( ) def test_list_knowledge_bases(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -750,7 +1174,7 @@ def test_list_knowledge_bases_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -770,7 +1194,7 @@ async def test_list_knowledge_bases_async( request_type=knowledge_base.ListKnowledgeBasesRequest, ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -807,7 +1231,7 @@ async def test_list_knowledge_bases_async_from_dict(): def test_list_knowledge_bases_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -839,7 +1263,7 @@ def test_list_knowledge_bases_field_headers(): @pytest.mark.asyncio async def test_list_knowledge_bases_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -872,7 +1296,7 @@ async def test_list_knowledge_bases_field_headers_async(): def test_list_knowledge_bases_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -898,7 +1322,7 @@ def test_list_knowledge_bases_flattened(): def test_list_knowledge_bases_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -913,7 +1337,7 @@ def test_list_knowledge_bases_flattened_error(): @pytest.mark.asyncio async def test_list_knowledge_bases_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -944,7 +1368,7 @@ async def test_list_knowledge_bases_flattened_async(): @pytest.mark.asyncio async def test_list_knowledge_bases_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -958,7 +1382,7 @@ async def test_list_knowledge_bases_flattened_error_async(): def test_list_knowledge_bases_pager(transport_name: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1010,7 +1434,7 @@ def test_list_knowledge_bases_pager(transport_name: str = "grpc"): def test_list_knowledge_bases_pages(transport_name: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1054,7 +1478,7 @@ def test_list_knowledge_bases_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_knowledge_bases_async_pager(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1106,7 +1530,7 @@ async def test_list_knowledge_bases_async_pager(): @pytest.mark.asyncio async def test_list_knowledge_bases_async_pages(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1163,7 +1587,7 @@ async def test_list_knowledge_bases_async_pages(): ) def test_get_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1199,7 +1623,7 @@ def test_get_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1218,7 +1642,7 @@ async def test_get_knowledge_base_async( transport: str = "grpc_asyncio", request_type=knowledge_base.GetKnowledgeBaseRequest ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1259,7 +1683,7 @@ async def test_get_knowledge_base_async_from_dict(): def test_get_knowledge_base_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1291,7 +1715,7 @@ def test_get_knowledge_base_field_headers(): @pytest.mark.asyncio async def test_get_knowledge_base_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1324,7 +1748,7 @@ async def test_get_knowledge_base_field_headers_async(): def test_get_knowledge_base_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1350,7 +1774,7 @@ def test_get_knowledge_base_flattened(): def test_get_knowledge_base_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1365,7 +1789,7 @@ def test_get_knowledge_base_flattened_error(): @pytest.mark.asyncio async def test_get_knowledge_base_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1396,7 +1820,7 @@ async def test_get_knowledge_base_flattened_async(): @pytest.mark.asyncio async def test_get_knowledge_base_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1417,7 +1841,7 @@ async def test_get_knowledge_base_flattened_error_async(): ) def test_create_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1453,7 +1877,7 @@ def test_create_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1473,7 +1897,7 @@ async def test_create_knowledge_base_async( request_type=gcd_knowledge_base.CreateKnowledgeBaseRequest, ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1514,7 +1938,7 @@ async def test_create_knowledge_base_async_from_dict(): def test_create_knowledge_base_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1546,7 +1970,7 @@ def test_create_knowledge_base_field_headers(): @pytest.mark.asyncio async def test_create_knowledge_base_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1579,7 +2003,7 @@ async def test_create_knowledge_base_field_headers_async(): def test_create_knowledge_base_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1609,7 +2033,7 @@ def test_create_knowledge_base_flattened(): def test_create_knowledge_base_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1625,7 +2049,7 @@ def test_create_knowledge_base_flattened_error(): @pytest.mark.asyncio async def test_create_knowledge_base_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1660,7 +2084,7 @@ async def test_create_knowledge_base_flattened_async(): @pytest.mark.asyncio async def test_create_knowledge_base_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1682,7 +2106,7 @@ async def test_create_knowledge_base_flattened_error_async(): ) def test_delete_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1711,7 +2135,7 @@ def test_delete_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1731,7 +2155,7 @@ async def test_delete_knowledge_base_async( request_type=knowledge_base.DeleteKnowledgeBaseRequest, ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1763,7 +2187,7 @@ async def test_delete_knowledge_base_async_from_dict(): def test_delete_knowledge_base_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1795,7 +2219,7 @@ def test_delete_knowledge_base_field_headers(): @pytest.mark.asyncio async def test_delete_knowledge_base_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1826,7 +2250,7 @@ async def test_delete_knowledge_base_field_headers_async(): def test_delete_knowledge_base_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1852,7 +2276,7 @@ def test_delete_knowledge_base_flattened(): def test_delete_knowledge_base_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1867,7 +2291,7 @@ def test_delete_knowledge_base_flattened_error(): @pytest.mark.asyncio async def test_delete_knowledge_base_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1896,7 +2320,7 @@ async def test_delete_knowledge_base_flattened_async(): @pytest.mark.asyncio async def test_delete_knowledge_base_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1917,7 +2341,7 @@ async def test_delete_knowledge_base_flattened_error_async(): ) def test_update_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1953,7 +2377,7 @@ def test_update_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1973,7 +2397,7 @@ async def test_update_knowledge_base_async( request_type=gcd_knowledge_base.UpdateKnowledgeBaseRequest, ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2014,7 +2438,7 @@ async def test_update_knowledge_base_async_from_dict(): def test_update_knowledge_base_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2046,7 +2470,7 @@ def test_update_knowledge_base_field_headers(): @pytest.mark.asyncio async def test_update_knowledge_base_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2079,7 +2503,7 @@ async def test_update_knowledge_base_field_headers_async(): def test_update_knowledge_base_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2109,7 +2533,7 @@ def test_update_knowledge_base_flattened(): def test_update_knowledge_base_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2125,7 +2549,7 @@ def test_update_knowledge_base_flattened_error(): @pytest.mark.asyncio async def test_update_knowledge_base_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2160,7 +2584,7 @@ async def test_update_knowledge_base_flattened_async(): @pytest.mark.asyncio async def test_update_knowledge_base_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2182,7 +2606,7 @@ async def test_update_knowledge_base_flattened_error_async(): ) def test_list_knowledge_bases_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2233,7 +2657,7 @@ def test_list_knowledge_bases_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_knowledge_bases._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2242,7 +2666,7 @@ def test_list_knowledge_bases_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_knowledge_bases._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2259,7 +2683,7 @@ def test_list_knowledge_bases_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2301,7 +2725,7 @@ def test_list_knowledge_bases_rest_required_fields( def test_list_knowledge_bases_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_knowledge_bases._get_unset_required_fields({}) @@ -2320,7 +2744,7 @@ def test_list_knowledge_bases_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_knowledge_bases_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -2378,7 +2802,7 @@ def test_list_knowledge_bases_rest_bad_request( transport: str = "rest", request_type=knowledge_base.ListKnowledgeBasesRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2400,7 +2824,7 @@ def test_list_knowledge_bases_rest_bad_request( def test_list_knowledge_bases_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2440,7 +2864,7 @@ def test_list_knowledge_bases_rest_flattened(): def test_list_knowledge_bases_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2455,7 +2879,7 @@ def test_list_knowledge_bases_rest_flattened_error(transport: str = "rest"): def test_list_knowledge_bases_rest_pager(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2525,7 +2949,7 @@ def test_list_knowledge_bases_rest_pager(transport: str = "rest"): ) def test_get_knowledge_base_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2580,7 +3004,7 @@ def test_get_knowledge_base_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2589,7 +3013,7 @@ def test_get_knowledge_base_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2598,7 +3022,7 @@ def test_get_knowledge_base_rest_required_fields( assert jsonified_request["name"] == "name_value" client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2640,7 +3064,7 @@ def test_get_knowledge_base_rest_required_fields( def test_get_knowledge_base_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_knowledge_base._get_unset_required_fields({}) @@ -2650,7 +3074,7 @@ def test_get_knowledge_base_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_knowledge_base_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -2708,7 +3132,7 @@ def test_get_knowledge_base_rest_bad_request( transport: str = "rest", request_type=knowledge_base.GetKnowledgeBaseRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2730,7 +3154,7 @@ def test_get_knowledge_base_rest_bad_request( def test_get_knowledge_base_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2770,7 +3194,7 @@ def test_get_knowledge_base_rest_flattened(): def test_get_knowledge_base_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2785,7 +3209,7 @@ def test_get_knowledge_base_rest_flattened_error(transport: str = "rest"): def test_get_knowledge_base_rest_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2798,7 +3222,7 @@ def test_get_knowledge_base_rest_error(): ) def test_create_knowledge_base_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2927,7 +3351,7 @@ def test_create_knowledge_base_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2936,7 +3360,7 @@ def test_create_knowledge_base_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2945,7 +3369,7 @@ def test_create_knowledge_base_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2988,7 +3412,7 @@ def test_create_knowledge_base_rest_required_fields( def test_create_knowledge_base_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_knowledge_base._get_unset_required_fields({}) @@ -3006,7 +3430,7 @@ def test_create_knowledge_base_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_knowledge_base_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -3064,7 +3488,7 @@ def test_create_knowledge_base_rest_bad_request( transport: str = "rest", request_type=gcd_knowledge_base.CreateKnowledgeBaseRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3086,7 +3510,7 @@ def test_create_knowledge_base_rest_bad_request( def test_create_knowledge_base_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3127,7 +3551,7 @@ def test_create_knowledge_base_rest_flattened(): def test_create_knowledge_base_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3143,7 +3567,7 @@ def test_create_knowledge_base_rest_flattened_error(transport: str = "rest"): def test_create_knowledge_base_rest_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3156,7 +3580,7 @@ def test_create_knowledge_base_rest_error(): ) def test_delete_knowledge_base_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3202,7 +3626,7 @@ def test_delete_knowledge_base_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3211,7 +3635,7 @@ def test_delete_knowledge_base_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_knowledge_base._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("force",)) @@ -3222,7 +3646,7 @@ def test_delete_knowledge_base_rest_required_fields( assert jsonified_request["name"] == "name_value" client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3261,7 +3685,7 @@ def test_delete_knowledge_base_rest_required_fields( def test_delete_knowledge_base_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_knowledge_base._get_unset_required_fields({}) @@ -3271,7 +3695,7 @@ def test_delete_knowledge_base_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_knowledge_base_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -3321,7 +3745,7 @@ def test_delete_knowledge_base_rest_bad_request( transport: str = "rest", request_type=knowledge_base.DeleteKnowledgeBaseRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3343,7 +3767,7 @@ def test_delete_knowledge_base_rest_bad_request( def test_delete_knowledge_base_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3381,7 +3805,7 @@ def test_delete_knowledge_base_rest_flattened(): def test_delete_knowledge_base_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3396,7 +3820,7 @@ def test_delete_knowledge_base_rest_flattened_error(transport: str = "rest"): def test_delete_knowledge_base_rest_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3409,7 +3833,7 @@ def test_delete_knowledge_base_rest_error(): ) def test_update_knowledge_base_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3539,14 +3963,14 @@ def test_update_knowledge_base_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_knowledge_base._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3555,7 +3979,7 @@ def test_update_knowledge_base_rest_required_fields( # verify required fields with non-default values are left alone client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3598,7 +4022,7 @@ def test_update_knowledge_base_rest_required_fields( def test_update_knowledge_base_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_knowledge_base._get_unset_required_fields({}) @@ -3608,7 +4032,7 @@ def test_update_knowledge_base_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_knowledge_base_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -3666,7 +4090,7 @@ def test_update_knowledge_base_rest_bad_request( transport: str = "rest", request_type=gcd_knowledge_base.UpdateKnowledgeBaseRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3690,7 +4114,7 @@ def test_update_knowledge_base_rest_bad_request( def test_update_knowledge_base_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3735,7 +4159,7 @@ def test_update_knowledge_base_rest_flattened(): def test_update_knowledge_base_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3751,24 +4175,24 @@ def test_update_knowledge_base_rest_flattened_error(transport: str = "rest"): def test_update_knowledge_base_rest_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = KnowledgeBasesClient( @@ -3778,7 +4202,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3789,16 +4213,17 @@ 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 = KnowledgeBasesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = KnowledgeBasesClient( @@ -3810,7 +4235,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = KnowledgeBasesClient(transport=transport) assert client.transport is transport @@ -3819,13 +4244,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.KnowledgeBasesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3842,7 +4267,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3856,7 +4281,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = KnowledgeBasesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3864,7 +4289,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3876,7 +4301,7 @@ def test_knowledge_bases_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.KnowledgeBasesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3888,7 +4313,7 @@ def test_knowledge_bases_base_transport(): ) as Transport: Transport.return_value = None transport = transports.KnowledgeBasesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3929,7 +4354,7 @@ def test_knowledge_bases_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.KnowledgeBasesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3951,7 +4376,7 @@ def test_knowledge_bases_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.KnowledgeBasesTransport() adc.assert_called_once() @@ -3959,7 +4384,7 @@ def test_knowledge_bases_base_transport_with_adc(): def test_knowledge_bases_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) KnowledgeBasesClient() adc.assert_called_once_with( scopes=None, @@ -3982,7 +4407,7 @@ def test_knowledge_bases_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4032,7 +4457,7 @@ def test_knowledge_bases_transport_create_channel(transport_class, grpc_helpers) ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4063,7 +4488,7 @@ def test_knowledge_bases_transport_create_channel(transport_class, grpc_helpers) ], ) def test_knowledge_bases_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4101,7 +4526,7 @@ def test_knowledge_bases_grpc_transport_client_cert_source_for_mtls(transport_cl def test_knowledge_bases_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4121,7 +4546,7 @@ def test_knowledge_bases_http_transport_client_cert_source_for_mtls(): ) def test_knowledge_bases_host_no_port(transport_name): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4144,7 +4569,7 @@ def test_knowledge_bases_host_no_port(transport_name): ) def test_knowledge_bases_host_with_port(transport_name): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4164,8 +4589,8 @@ def test_knowledge_bases_host_with_port(transport_name): ], ) def test_knowledge_bases_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = KnowledgeBasesClient( credentials=creds1, transport=transport_name, @@ -4241,7 +4666,7 @@ def test_knowledge_bases_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4450,7 +4875,7 @@ def test_client_with_default_client_info(): transports.KnowledgeBasesTransport, "_prep_wrapped_messages" ) as prep: client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4460,7 +4885,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = KnowledgeBasesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4469,7 +4894,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4484,7 +4909,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4514,7 +4939,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4542,7 +4967,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4570,7 +4995,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4598,7 +5023,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4628,7 +5053,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4656,7 +5081,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4686,7 +5111,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4714,7 +5139,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4742,7 +5167,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4768,7 +5193,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4793,7 +5218,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4817,7 +5242,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4846,7 +5271,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4873,7 +5298,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4891,7 +5316,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4907,7 +5332,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4932,7 +5357,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4958,7 +5383,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4987,7 +5412,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5016,7 +5441,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5034,7 +5459,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5052,7 +5477,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5077,7 +5502,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5103,7 +5528,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5132,7 +5557,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5161,7 +5586,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5179,7 +5604,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5197,7 +5622,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5222,7 +5647,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5248,7 +5673,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5277,7 +5702,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5306,7 +5731,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5324,7 +5749,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5342,7 +5767,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5367,7 +5792,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5392,7 +5817,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = KnowledgeBasesClient(credentials=ga_credentials.AnonymousCredentials()) + client = KnowledgeBasesClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5420,7 +5845,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5449,7 +5874,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5467,7 +5892,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5491,7 +5916,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5508,7 +5933,7 @@ def test_client_ctx(): ] for transport in transports: client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5539,7 +5964,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py index 7d672f1bcca4..ac91e05c1f4f 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_participants.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -74,6 +74,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -100,6 +123,255 @@ def test__get_default_mtls_endpoint(): assert ParticipantsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert ParticipantsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ParticipantsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ParticipantsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ParticipantsClient._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 ParticipantsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ParticipantsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ParticipantsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ParticipantsClient._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 ParticipantsClient._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 ParticipantsClient._get_client_cert_source(None, False) is None + assert ( + ParticipantsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + ParticipantsClient._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 ( + ParticipantsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ParticipantsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ParticipantsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsClient), +) +@mock.patch.object( + ParticipantsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ParticipantsClient._DEFAULT_UNIVERSE + default_endpoint = ParticipantsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ParticipantsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ParticipantsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ParticipantsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ParticipantsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ParticipantsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + ParticipantsClient._get_api_endpoint(None, None, default_universe, "always") + == ParticipantsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ParticipantsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ParticipantsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ParticipantsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ParticipantsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ParticipantsClient._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 ( + ParticipantsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ParticipantsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ParticipantsClient._get_universe_domain(None, None) + == ParticipantsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ParticipantsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (ParticipantsClient, transports.ParticipantsGrpcTransport, "grpc"), + (ParticipantsClient, transports.ParticipantsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -109,7 +381,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_participants_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -161,7 +433,7 @@ def test_participants_client_service_account_always_use_jwt( ], ) def test_participants_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -210,19 +482,23 @@ def test_participants_client_get_transport_class(): ], ) @mock.patch.object( - ParticipantsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ParticipantsClient) + ParticipantsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsClient), ) @mock.patch.object( ParticipantsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ParticipantsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsAsyncClient), ) def test_participants_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ParticipantsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -257,7 +533,9 @@ def test_participants_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, @@ -287,15 +565,23 @@ def test_participants_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") @@ -305,7 +591,9 @@ def test_participants_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", @@ -323,7 +611,9 @@ def test_participants_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, @@ -355,12 +645,14 @@ def test_participants_client_client_options( ], ) @mock.patch.object( - ParticipantsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ParticipantsClient) + ParticipantsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsClient), ) @mock.patch.object( ParticipantsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ParticipantsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_participants_client_mtls_env_auto( @@ -383,7 +675,9 @@ def test_participants_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 @@ -415,7 +709,9 @@ def test_participants_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 @@ -449,7 +745,9 @@ def test_participants_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, @@ -535,6 +833,116 @@ def test_participants_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", [ParticipantsClient, ParticipantsAsyncClient]) +@mock.patch.object( + ParticipantsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsClient), +) +@mock.patch.object( + ParticipantsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsAsyncClient), +) +def test_participants_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ParticipantsClient._DEFAULT_UNIVERSE + default_endpoint = ParticipantsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ParticipantsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -561,7 +969,9 @@ def test_participants_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, @@ -601,7 +1011,9 @@ def test_participants_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, @@ -659,7 +1071,9 @@ def test_participants_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, @@ -676,8 +1090,8 @@ def test_participants_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -709,7 +1123,7 @@ def test_participants_client_create_channel_credentials_file( ) def test_create_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -747,7 +1161,7 @@ def test_create_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -767,7 +1181,7 @@ async def test_create_participant_async( request_type=gcd_participant.CreateParticipantRequest, ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -810,7 +1224,7 @@ async def test_create_participant_async_from_dict(): def test_create_participant_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -842,7 +1256,7 @@ def test_create_participant_field_headers(): @pytest.mark.asyncio async def test_create_participant_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -875,7 +1289,7 @@ async def test_create_participant_field_headers_async(): def test_create_participant_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -905,7 +1319,7 @@ def test_create_participant_flattened(): def test_create_participant_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -921,7 +1335,7 @@ def test_create_participant_flattened_error(): @pytest.mark.asyncio async def test_create_participant_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -956,7 +1370,7 @@ async def test_create_participant_flattened_async(): @pytest.mark.asyncio async def test_create_participant_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -978,7 +1392,7 @@ async def test_create_participant_flattened_error_async(): ) def test_get_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1014,7 +1428,7 @@ def test_get_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1031,7 +1445,7 @@ async def test_get_participant_async( transport: str = "grpc_asyncio", request_type=participant.GetParticipantRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1072,7 +1486,7 @@ async def test_get_participant_async_from_dict(): def test_get_participant_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1102,7 +1516,7 @@ def test_get_participant_field_headers(): @pytest.mark.asyncio async def test_get_participant_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1133,7 +1547,7 @@ async def test_get_participant_field_headers_async(): def test_get_participant_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1157,7 +1571,7 @@ def test_get_participant_flattened(): def test_get_participant_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1172,7 +1586,7 @@ def test_get_participant_flattened_error(): @pytest.mark.asyncio async def test_get_participant_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1201,7 +1615,7 @@ async def test_get_participant_flattened_async(): @pytest.mark.asyncio async def test_get_participant_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1222,7 +1636,7 @@ async def test_get_participant_flattened_error_async(): ) def test_list_participants(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1254,7 +1668,7 @@ def test_list_participants_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1273,7 +1687,7 @@ async def test_list_participants_async( transport: str = "grpc_asyncio", request_type=participant.ListParticipantsRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1310,7 +1724,7 @@ async def test_list_participants_async_from_dict(): def test_list_participants_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1342,7 +1756,7 @@ def test_list_participants_field_headers(): @pytest.mark.asyncio async def test_list_participants_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1375,7 +1789,7 @@ async def test_list_participants_field_headers_async(): def test_list_participants_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1401,7 +1815,7 @@ def test_list_participants_flattened(): def test_list_participants_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1416,7 +1830,7 @@ def test_list_participants_flattened_error(): @pytest.mark.asyncio async def test_list_participants_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1447,7 +1861,7 @@ async def test_list_participants_flattened_async(): @pytest.mark.asyncio async def test_list_participants_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1461,7 +1875,7 @@ async def test_list_participants_flattened_error_async(): def test_list_participants_pager(transport_name: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1513,7 +1927,7 @@ def test_list_participants_pager(transport_name: str = "grpc"): def test_list_participants_pages(transport_name: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1557,7 +1971,7 @@ def test_list_participants_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_participants_async_pager(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1609,7 +2023,7 @@ async def test_list_participants_async_pager(): @pytest.mark.asyncio async def test_list_participants_async_pages(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1666,7 +2080,7 @@ async def test_list_participants_async_pages(): ) def test_update_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1704,7 +2118,7 @@ def test_update_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1724,7 +2138,7 @@ async def test_update_participant_async( request_type=gcd_participant.UpdateParticipantRequest, ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1767,7 +2181,7 @@ async def test_update_participant_async_from_dict(): def test_update_participant_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1799,7 +2213,7 @@ def test_update_participant_field_headers(): @pytest.mark.asyncio async def test_update_participant_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1832,7 +2246,7 @@ async def test_update_participant_field_headers_async(): def test_update_participant_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1862,7 +2276,7 @@ def test_update_participant_flattened(): def test_update_participant_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1878,7 +2292,7 @@ def test_update_participant_flattened_error(): @pytest.mark.asyncio async def test_update_participant_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1913,7 +2327,7 @@ async def test_update_participant_flattened_async(): @pytest.mark.asyncio async def test_update_participant_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1935,7 +2349,7 @@ async def test_update_participant_flattened_error_async(): ) def test_analyze_content(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1965,7 +2379,7 @@ def test_analyze_content_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1982,7 +2396,7 @@ async def test_analyze_content_async( transport: str = "grpc_asyncio", request_type=gcd_participant.AnalyzeContentRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2017,7 +2431,7 @@ async def test_analyze_content_async_from_dict(): def test_analyze_content_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2047,7 +2461,7 @@ def test_analyze_content_field_headers(): @pytest.mark.asyncio async def test_analyze_content_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2078,7 +2492,7 @@ async def test_analyze_content_field_headers_async(): def test_analyze_content_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2105,7 +2519,7 @@ def test_analyze_content_flattened(): def test_analyze_content_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2122,7 +2536,7 @@ def test_analyze_content_flattened_error(): @pytest.mark.asyncio async def test_analyze_content_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2154,7 +2568,7 @@ async def test_analyze_content_flattened_async(): @pytest.mark.asyncio async def test_analyze_content_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2177,7 +2591,7 @@ async def test_analyze_content_flattened_error_async(): ) def test_streaming_analyze_content(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2210,7 +2624,7 @@ async def test_streaming_analyze_content_async( request_type=participant.StreamingAnalyzeContentRequest, ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2254,7 +2668,7 @@ async def test_streaming_analyze_content_async_from_dict(): ) def test_suggest_articles(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2286,7 +2700,7 @@ def test_suggest_articles_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2303,7 +2717,7 @@ async def test_suggest_articles_async( transport: str = "grpc_asyncio", request_type=participant.SuggestArticlesRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2340,7 +2754,7 @@ async def test_suggest_articles_async_from_dict(): def test_suggest_articles_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2370,7 +2784,7 @@ def test_suggest_articles_field_headers(): @pytest.mark.asyncio async def test_suggest_articles_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2401,7 +2815,7 @@ async def test_suggest_articles_field_headers_async(): def test_suggest_articles_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2425,7 +2839,7 @@ def test_suggest_articles_flattened(): def test_suggest_articles_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2440,7 +2854,7 @@ def test_suggest_articles_flattened_error(): @pytest.mark.asyncio async def test_suggest_articles_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2469,7 +2883,7 @@ async def test_suggest_articles_flattened_async(): @pytest.mark.asyncio async def test_suggest_articles_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2490,7 +2904,7 @@ async def test_suggest_articles_flattened_error_async(): ) def test_suggest_faq_answers(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2524,7 +2938,7 @@ def test_suggest_faq_answers_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2543,7 +2957,7 @@ async def test_suggest_faq_answers_async( transport: str = "grpc_asyncio", request_type=participant.SuggestFaqAnswersRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2582,7 +2996,7 @@ async def test_suggest_faq_answers_async_from_dict(): def test_suggest_faq_answers_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2614,7 +3028,7 @@ def test_suggest_faq_answers_field_headers(): @pytest.mark.asyncio async def test_suggest_faq_answers_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2647,7 +3061,7 @@ async def test_suggest_faq_answers_field_headers_async(): def test_suggest_faq_answers_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2673,7 +3087,7 @@ def test_suggest_faq_answers_flattened(): def test_suggest_faq_answers_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2688,7 +3102,7 @@ def test_suggest_faq_answers_flattened_error(): @pytest.mark.asyncio async def test_suggest_faq_answers_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2719,7 +3133,7 @@ async def test_suggest_faq_answers_flattened_async(): @pytest.mark.asyncio async def test_suggest_faq_answers_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2740,7 +3154,7 @@ async def test_suggest_faq_answers_flattened_error_async(): ) def test_suggest_smart_replies(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2774,7 +3188,7 @@ def test_suggest_smart_replies_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2793,7 +3207,7 @@ async def test_suggest_smart_replies_async( transport: str = "grpc_asyncio", request_type=participant.SuggestSmartRepliesRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2832,7 +3246,7 @@ async def test_suggest_smart_replies_async_from_dict(): def test_suggest_smart_replies_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2864,7 +3278,7 @@ def test_suggest_smart_replies_field_headers(): @pytest.mark.asyncio async def test_suggest_smart_replies_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2897,7 +3311,7 @@ async def test_suggest_smart_replies_field_headers_async(): def test_suggest_smart_replies_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2923,7 +3337,7 @@ def test_suggest_smart_replies_flattened(): def test_suggest_smart_replies_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2938,7 +3352,7 @@ def test_suggest_smart_replies_flattened_error(): @pytest.mark.asyncio async def test_suggest_smart_replies_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2969,7 +3383,7 @@ async def test_suggest_smart_replies_flattened_async(): @pytest.mark.asyncio async def test_suggest_smart_replies_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2990,7 +3404,7 @@ async def test_suggest_smart_replies_flattened_error_async(): ) def test_create_participant_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3121,7 +3535,7 @@ def test_create_participant_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3130,7 +3544,7 @@ def test_create_participant_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3139,7 +3553,7 @@ def test_create_participant_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3182,7 +3596,7 @@ def test_create_participant_rest_required_fields( def test_create_participant_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_participant._get_unset_required_fields({}) @@ -3200,7 +3614,7 @@ def test_create_participant_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_participant_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -3258,7 +3672,7 @@ def test_create_participant_rest_bad_request( transport: str = "rest", request_type=gcd_participant.CreateParticipantRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3280,7 +3694,7 @@ def test_create_participant_rest_bad_request( def test_create_participant_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3323,7 +3737,7 @@ def test_create_participant_rest_flattened(): def test_create_participant_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3339,7 +3753,7 @@ def test_create_participant_rest_flattened_error(transport: str = "rest"): def test_create_participant_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3352,7 +3766,7 @@ def test_create_participant_rest_error(): ) def test_get_participant_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3411,7 +3825,7 @@ def test_get_participant_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3420,7 +3834,7 @@ def test_get_participant_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3429,7 +3843,7 @@ def test_get_participant_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3471,7 +3885,7 @@ def test_get_participant_rest_required_fields( def test_get_participant_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_participant._get_unset_required_fields({}) @@ -3481,7 +3895,7 @@ def test_get_participant_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_participant_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -3539,7 +3953,7 @@ def test_get_participant_rest_bad_request( transport: str = "rest", request_type=participant.GetParticipantRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3563,7 +3977,7 @@ def test_get_participant_rest_bad_request( def test_get_participant_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3607,7 +4021,7 @@ def test_get_participant_rest_flattened(): def test_get_participant_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3622,7 +4036,7 @@ def test_get_participant_rest_flattened_error(transport: str = "rest"): def test_get_participant_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3635,7 +4049,7 @@ def test_get_participant_rest_error(): ) def test_list_participants_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3686,7 +4100,7 @@ def test_list_participants_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_participants._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3695,7 +4109,7 @@ def test_list_participants_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_participants._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3711,7 +4125,7 @@ def test_list_participants_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3753,7 +4167,7 @@ def test_list_participants_rest_required_fields( def test_list_participants_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_participants._get_unset_required_fields({}) @@ -3771,7 +4185,7 @@ def test_list_participants_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_participants_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -3829,7 +4243,7 @@ def test_list_participants_rest_bad_request( transport: str = "rest", request_type=participant.ListParticipantsRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3851,7 +4265,7 @@ def test_list_participants_rest_bad_request( def test_list_participants_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3893,7 +4307,7 @@ def test_list_participants_rest_flattened(): def test_list_participants_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3908,7 +4322,7 @@ def test_list_participants_rest_flattened_error(transport: str = "rest"): def test_list_participants_rest_pager(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3978,7 +4392,7 @@ def test_list_participants_rest_pager(transport: str = "rest"): ) def test_update_participant_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4112,14 +4526,14 @@ def test_update_participant_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_participant._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -4128,7 +4542,7 @@ def test_update_participant_rest_required_fields( # verify required fields with non-default values are left alone client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4171,7 +4585,7 @@ def test_update_participant_rest_required_fields( def test_update_participant_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_participant._get_unset_required_fields({}) @@ -4189,7 +4603,7 @@ def test_update_participant_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_participant_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -4247,7 +4661,7 @@ def test_update_participant_rest_bad_request( transport: str = "rest", request_type=gcd_participant.UpdateParticipantRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4273,7 +4687,7 @@ def test_update_participant_rest_bad_request( def test_update_participant_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4320,7 +4734,7 @@ def test_update_participant_rest_flattened(): def test_update_participant_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4336,7 +4750,7 @@ def test_update_participant_rest_flattened_error(transport: str = "rest"): def test_update_participant_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4349,7 +4763,7 @@ def test_update_participant_rest_error(): ) def test_analyze_content_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4402,7 +4816,7 @@ def test_analyze_content_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).analyze_content._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4411,7 +4825,7 @@ def test_analyze_content_rest_required_fields( jsonified_request["participant"] = "participant_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).analyze_content._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4420,7 +4834,7 @@ def test_analyze_content_rest_required_fields( assert jsonified_request["participant"] == "participant_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4463,7 +4877,7 @@ def test_analyze_content_rest_required_fields( def test_analyze_content_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.analyze_content._get_unset_required_fields({}) @@ -4473,7 +4887,7 @@ def test_analyze_content_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_analyze_content_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -4531,7 +4945,7 @@ def test_analyze_content_rest_bad_request( transport: str = "rest", request_type=gcd_participant.AnalyzeContentRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4555,7 +4969,7 @@ def test_analyze_content_rest_bad_request( def test_analyze_content_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4599,7 +5013,7 @@ def test_analyze_content_rest_flattened(): def test_analyze_content_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4616,13 +5030,13 @@ def test_analyze_content_rest_flattened_error(transport: str = "rest"): def test_analyze_content_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_streaming_analyze_content_rest_no_http_options(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = participant.StreamingAnalyzeContentRequest() @@ -4640,7 +5054,7 @@ def test_streaming_analyze_content_rest_no_http_options(): ) def test_suggest_articles_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4695,7 +5109,7 @@ def test_suggest_articles_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_articles._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4704,7 +5118,7 @@ def test_suggest_articles_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_articles._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4713,7 +5127,7 @@ def test_suggest_articles_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4756,7 +5170,7 @@ def test_suggest_articles_rest_required_fields( def test_suggest_articles_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.suggest_articles._get_unset_required_fields({}) @@ -4766,7 +5180,7 @@ def test_suggest_articles_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_suggest_articles_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -4824,7 +5238,7 @@ def test_suggest_articles_rest_bad_request( transport: str = "rest", request_type=participant.SuggestArticlesRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4848,7 +5262,7 @@ def test_suggest_articles_rest_bad_request( def test_suggest_articles_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4892,7 +5306,7 @@ def test_suggest_articles_rest_flattened(): def test_suggest_articles_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4907,7 +5321,7 @@ def test_suggest_articles_rest_flattened_error(transport: str = "rest"): def test_suggest_articles_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4920,7 +5334,7 @@ def test_suggest_articles_rest_error(): ) def test_suggest_faq_answers_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4975,7 +5389,7 @@ def test_suggest_faq_answers_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_faq_answers._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4984,7 +5398,7 @@ def test_suggest_faq_answers_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_faq_answers._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4993,7 +5407,7 @@ def test_suggest_faq_answers_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5036,7 +5450,7 @@ def test_suggest_faq_answers_rest_required_fields( def test_suggest_faq_answers_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.suggest_faq_answers._get_unset_required_fields({}) @@ -5046,7 +5460,7 @@ def test_suggest_faq_answers_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_suggest_faq_answers_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -5104,7 +5518,7 @@ def test_suggest_faq_answers_rest_bad_request( transport: str = "rest", request_type=participant.SuggestFaqAnswersRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5128,7 +5542,7 @@ def test_suggest_faq_answers_rest_bad_request( def test_suggest_faq_answers_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5172,7 +5586,7 @@ def test_suggest_faq_answers_rest_flattened(): def test_suggest_faq_answers_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5187,7 +5601,7 @@ def test_suggest_faq_answers_rest_flattened_error(transport: str = "rest"): def test_suggest_faq_answers_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5200,7 +5614,7 @@ def test_suggest_faq_answers_rest_error(): ) def test_suggest_smart_replies_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5255,7 +5669,7 @@ def test_suggest_smart_replies_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_smart_replies._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5264,7 +5678,7 @@ def test_suggest_smart_replies_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_smart_replies._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5273,7 +5687,7 @@ def test_suggest_smart_replies_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5316,7 +5730,7 @@ def test_suggest_smart_replies_rest_required_fields( def test_suggest_smart_replies_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.suggest_smart_replies._get_unset_required_fields({}) @@ -5326,7 +5740,7 @@ def test_suggest_smart_replies_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_suggest_smart_replies_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -5384,7 +5798,7 @@ def test_suggest_smart_replies_rest_bad_request( transport: str = "rest", request_type=participant.SuggestSmartRepliesRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5408,7 +5822,7 @@ def test_suggest_smart_replies_rest_bad_request( def test_suggest_smart_replies_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5452,7 +5866,7 @@ def test_suggest_smart_replies_rest_flattened(): def test_suggest_smart_replies_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5467,13 +5881,13 @@ def test_suggest_smart_replies_rest_flattened_error(transport: str = "rest"): def test_suggest_smart_replies_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_streaming_analyze_content_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) # Since a `google.api.http` annotation is required for using a rest transport # method, this should error. @@ -5487,17 +5901,17 @@ def test_streaming_analyze_content_rest_error(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ParticipantsClient( @@ -5507,7 +5921,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5518,16 +5932,17 @@ 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 = ParticipantsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ParticipantsClient( @@ -5539,7 +5954,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ParticipantsClient(transport=transport) assert client.transport is transport @@ -5548,13 +5963,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ParticipantsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5571,7 +5986,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5585,7 +6000,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ParticipantsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5593,7 +6008,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5605,7 +6020,7 @@ def test_participants_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ParticipantsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5617,7 +6032,7 @@ def test_participants_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ParticipantsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5662,7 +6077,7 @@ def test_participants_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ParticipantsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5684,7 +6099,7 @@ def test_participants_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ParticipantsTransport() adc.assert_called_once() @@ -5692,7 +6107,7 @@ def test_participants_base_transport_with_adc(): def test_participants_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ParticipantsClient() adc.assert_called_once_with( scopes=None, @@ -5715,7 +6130,7 @@ def test_participants_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5765,7 +6180,7 @@ def test_participants_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5793,7 +6208,7 @@ def test_participants_transport_create_channel(transport_class, grpc_helpers): [transports.ParticipantsGrpcTransport, transports.ParticipantsGrpcAsyncIOTransport], ) def test_participants_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5831,7 +6246,7 @@ def test_participants_grpc_transport_client_cert_source_for_mtls(transport_class def test_participants_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5851,7 +6266,7 @@ def test_participants_http_transport_client_cert_source_for_mtls(): ) def test_participants_host_no_port(transport_name): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -5874,7 +6289,7 @@ def test_participants_host_no_port(transport_name): ) def test_participants_host_with_port(transport_name): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -5894,8 +6309,8 @@ def test_participants_host_with_port(transport_name): ], ) def test_participants_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ParticipantsClient( credentials=creds1, transport=transport_name, @@ -5978,7 +6393,7 @@ def test_participants_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6315,7 +6730,7 @@ def test_client_with_default_client_info(): transports.ParticipantsTransport, "_prep_wrapped_messages" ) as prep: client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6325,7 +6740,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ParticipantsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6334,7 +6749,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6349,7 +6764,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6379,7 +6794,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -6407,7 +6822,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6435,7 +6850,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6463,7 +6878,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6493,7 +6908,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6521,7 +6936,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6551,7 +6966,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6579,7 +6994,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6607,7 +7022,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6633,7 +7048,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6658,7 +7073,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6682,7 +7097,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6711,7 +7126,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6738,7 +7153,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6756,7 +7171,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6772,7 +7187,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6797,7 +7212,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6823,7 +7238,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6852,7 +7267,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6881,7 +7296,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6899,7 +7314,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6917,7 +7332,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6942,7 +7357,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6968,7 +7383,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6997,7 +7412,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7026,7 +7441,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7044,7 +7459,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7062,7 +7477,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7087,7 +7502,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7113,7 +7528,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7142,7 +7557,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7171,7 +7586,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7189,7 +7604,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7207,7 +7622,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7232,7 +7647,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7257,7 +7672,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = ParticipantsClient(credentials=ga_credentials.AnonymousCredentials()) + client = ParticipantsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7284,7 +7699,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = ParticipantsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = ParticipantsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7312,7 +7729,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7330,7 +7747,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7354,7 +7771,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7371,7 +7788,7 @@ def test_client_ctx(): ] for transport in transports: client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7402,7 +7819,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py index 6239e3a37993..4c3925153661 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_session_entity_types.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -73,6 +73,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -103,6 +126,279 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SessionEntityTypesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SessionEntityTypesClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SessionEntityTypesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SessionEntityTypesClient._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 SessionEntityTypesClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SessionEntityTypesClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SessionEntityTypesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SessionEntityTypesClient._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 SessionEntityTypesClient._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 SessionEntityTypesClient._get_client_cert_source(None, False) is None + assert ( + SessionEntityTypesClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + SessionEntityTypesClient._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 ( + SessionEntityTypesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SessionEntityTypesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SessionEntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesClient), +) +@mock.patch.object( + SessionEntityTypesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SessionEntityTypesClient._DEFAULT_UNIVERSE + default_endpoint = SessionEntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SessionEntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SessionEntityTypesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SessionEntityTypesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionEntityTypesClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SessionEntityTypesClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionEntityTypesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionEntityTypesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SessionEntityTypesClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SessionEntityTypesClient._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 ( + SessionEntityTypesClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SessionEntityTypesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SessionEntityTypesClient._get_universe_domain(None, None) + == SessionEntityTypesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SessionEntityTypesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SessionEntityTypesClient, transports.SessionEntityTypesGrpcTransport, "grpc"), + (SessionEntityTypesClient, transports.SessionEntityTypesRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -114,7 +410,7 @@ def test__get_default_mtls_endpoint(): def test_session_entity_types_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -168,7 +464,7 @@ def test_session_entity_types_client_service_account_always_use_jwt( def test_session_entity_types_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -218,20 +514,22 @@ def test_session_entity_types_client_get_transport_class(): ) @mock.patch.object( SessionEntityTypesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionEntityTypesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesClient), ) @mock.patch.object( SessionEntityTypesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionEntityTypesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesAsyncClient), ) def test_session_entity_types_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SessionEntityTypesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -266,7 +564,9 @@ def test_session_entity_types_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, @@ -296,15 +596,23 @@ def test_session_entity_types_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") @@ -314,7 +622,9 @@ def test_session_entity_types_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", @@ -332,7 +642,9 @@ def test_session_entity_types_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, @@ -385,13 +697,13 @@ def test_session_entity_types_client_client_options( ) @mock.patch.object( SessionEntityTypesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionEntityTypesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesClient), ) @mock.patch.object( SessionEntityTypesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionEntityTypesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_session_entity_types_client_mtls_env_auto( @@ -414,7 +726,9 @@ def test_session_entity_types_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 @@ -446,7 +760,9 @@ def test_session_entity_types_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 @@ -480,7 +796,9 @@ def test_session_entity_types_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, @@ -570,6 +888,118 @@ def test_session_entity_types_client_get_mtls_endpoint_and_cert_source(client_cl 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", [SessionEntityTypesClient, SessionEntityTypesAsyncClient] +) +@mock.patch.object( + SessionEntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesClient), +) +@mock.patch.object( + SessionEntityTypesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesAsyncClient), +) +def test_session_entity_types_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SessionEntityTypesClient._DEFAULT_UNIVERSE + default_endpoint = SessionEntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SessionEntityTypesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -596,7 +1026,9 @@ def test_session_entity_types_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, @@ -641,7 +1073,9 @@ def test_session_entity_types_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, @@ -701,7 +1135,9 @@ def test_session_entity_types_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, @@ -718,8 +1154,8 @@ def test_session_entity_types_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -751,7 +1187,7 @@ def test_session_entity_types_client_create_channel_credentials_file( ) def test_list_session_entity_types(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -783,7 +1219,7 @@ def test_list_session_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -803,7 +1239,7 @@ async def test_list_session_entity_types_async( request_type=session_entity_type.ListSessionEntityTypesRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -840,7 +1276,7 @@ async def test_list_session_entity_types_async_from_dict(): def test_list_session_entity_types_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -872,7 +1308,7 @@ def test_list_session_entity_types_field_headers(): @pytest.mark.asyncio async def test_list_session_entity_types_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -905,7 +1341,7 @@ async def test_list_session_entity_types_field_headers_async(): def test_list_session_entity_types_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -931,7 +1367,7 @@ def test_list_session_entity_types_flattened(): def test_list_session_entity_types_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -946,7 +1382,7 @@ def test_list_session_entity_types_flattened_error(): @pytest.mark.asyncio async def test_list_session_entity_types_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -977,7 +1413,7 @@ async def test_list_session_entity_types_flattened_async(): @pytest.mark.asyncio async def test_list_session_entity_types_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -991,7 +1427,7 @@ async def test_list_session_entity_types_flattened_error_async(): def test_list_session_entity_types_pager(transport_name: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1045,7 +1481,7 @@ def test_list_session_entity_types_pager(transport_name: str = "grpc"): def test_list_session_entity_types_pages(transport_name: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1089,7 +1525,7 @@ def test_list_session_entity_types_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_session_entity_types_async_pager(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1143,7 +1579,7 @@ async def test_list_session_entity_types_async_pager(): @pytest.mark.asyncio async def test_list_session_entity_types_async_pages(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1200,7 +1636,7 @@ async def test_list_session_entity_types_async_pages(): ) def test_get_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1237,7 +1673,7 @@ def test_get_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1257,7 +1693,7 @@ async def test_get_session_entity_type_async( request_type=session_entity_type.GetSessionEntityTypeRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1299,7 +1735,7 @@ async def test_get_session_entity_type_async_from_dict(): def test_get_session_entity_type_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1331,7 +1767,7 @@ def test_get_session_entity_type_field_headers(): @pytest.mark.asyncio async def test_get_session_entity_type_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1364,7 +1800,7 @@ async def test_get_session_entity_type_field_headers_async(): def test_get_session_entity_type_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1390,7 +1826,7 @@ def test_get_session_entity_type_flattened(): def test_get_session_entity_type_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1405,7 +1841,7 @@ def test_get_session_entity_type_flattened_error(): @pytest.mark.asyncio async def test_get_session_entity_type_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1436,7 +1872,7 @@ async def test_get_session_entity_type_flattened_async(): @pytest.mark.asyncio async def test_get_session_entity_type_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1457,7 +1893,7 @@ async def test_get_session_entity_type_flattened_error_async(): ) def test_create_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1494,7 +1930,7 @@ def test_create_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1514,7 +1950,7 @@ async def test_create_session_entity_type_async( request_type=gcd_session_entity_type.CreateSessionEntityTypeRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1556,7 +1992,7 @@ async def test_create_session_entity_type_async_from_dict(): def test_create_session_entity_type_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1588,7 +2024,7 @@ def test_create_session_entity_type_field_headers(): @pytest.mark.asyncio async def test_create_session_entity_type_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1621,7 +2057,7 @@ async def test_create_session_entity_type_field_headers_async(): def test_create_session_entity_type_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1653,7 +2089,7 @@ def test_create_session_entity_type_flattened(): def test_create_session_entity_type_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1671,7 +2107,7 @@ def test_create_session_entity_type_flattened_error(): @pytest.mark.asyncio async def test_create_session_entity_type_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1708,7 +2144,7 @@ async def test_create_session_entity_type_flattened_async(): @pytest.mark.asyncio async def test_create_session_entity_type_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1732,7 +2168,7 @@ async def test_create_session_entity_type_flattened_error_async(): ) def test_update_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1769,7 +2205,7 @@ def test_update_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1789,7 +2225,7 @@ async def test_update_session_entity_type_async( request_type=gcd_session_entity_type.UpdateSessionEntityTypeRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1831,7 +2267,7 @@ async def test_update_session_entity_type_async_from_dict(): def test_update_session_entity_type_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1863,7 +2299,7 @@ def test_update_session_entity_type_field_headers(): @pytest.mark.asyncio async def test_update_session_entity_type_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1896,7 +2332,7 @@ async def test_update_session_entity_type_field_headers_async(): def test_update_session_entity_type_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1928,7 +2364,7 @@ def test_update_session_entity_type_flattened(): def test_update_session_entity_type_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1946,7 +2382,7 @@ def test_update_session_entity_type_flattened_error(): @pytest.mark.asyncio async def test_update_session_entity_type_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1983,7 +2419,7 @@ async def test_update_session_entity_type_flattened_async(): @pytest.mark.asyncio async def test_update_session_entity_type_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2007,7 +2443,7 @@ async def test_update_session_entity_type_flattened_error_async(): ) def test_delete_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2036,7 +2472,7 @@ def test_delete_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2056,7 +2492,7 @@ async def test_delete_session_entity_type_async( request_type=session_entity_type.DeleteSessionEntityTypeRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2088,7 +2524,7 @@ async def test_delete_session_entity_type_async_from_dict(): def test_delete_session_entity_type_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2120,7 +2556,7 @@ def test_delete_session_entity_type_field_headers(): @pytest.mark.asyncio async def test_delete_session_entity_type_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2151,7 +2587,7 @@ async def test_delete_session_entity_type_field_headers_async(): def test_delete_session_entity_type_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2177,7 +2613,7 @@ def test_delete_session_entity_type_flattened(): def test_delete_session_entity_type_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2192,7 +2628,7 @@ def test_delete_session_entity_type_flattened_error(): @pytest.mark.asyncio async def test_delete_session_entity_type_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2221,7 +2657,7 @@ async def test_delete_session_entity_type_flattened_async(): @pytest.mark.asyncio async def test_delete_session_entity_type_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2242,7 +2678,7 @@ async def test_delete_session_entity_type_flattened_error_async(): ) def test_list_session_entity_types_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2295,7 +2731,7 @@ def test_list_session_entity_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_session_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2304,7 +2740,7 @@ def test_list_session_entity_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_session_entity_types._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2320,7 +2756,7 @@ def test_list_session_entity_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2364,7 +2800,7 @@ def test_list_session_entity_types_rest_required_fields( def test_list_session_entity_types_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_session_entity_types._get_unset_required_fields({}) @@ -2382,7 +2818,7 @@ def test_list_session_entity_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_session_entity_types_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -2443,7 +2879,7 @@ def test_list_session_entity_types_rest_bad_request( request_type=session_entity_type.ListSessionEntityTypesRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2465,7 +2901,7 @@ def test_list_session_entity_types_rest_bad_request( def test_list_session_entity_types_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2509,7 +2945,7 @@ def test_list_session_entity_types_rest_flattened(): def test_list_session_entity_types_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2524,7 +2960,7 @@ def test_list_session_entity_types_rest_flattened_error(transport: str = "rest") def test_list_session_entity_types_rest_pager(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2597,7 +3033,7 @@ def test_list_session_entity_types_rest_pager(transport: str = "rest"): ) def test_get_session_entity_type_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2655,7 +3091,7 @@ def test_get_session_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2664,7 +3100,7 @@ def test_get_session_entity_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2673,7 +3109,7 @@ def test_get_session_entity_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2715,7 +3151,7 @@ def test_get_session_entity_type_rest_required_fields( def test_get_session_entity_type_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_session_entity_type._get_unset_required_fields({}) @@ -2725,7 +3161,7 @@ def test_get_session_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_session_entity_type_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -2784,7 +3220,7 @@ def test_get_session_entity_type_rest_bad_request( request_type=session_entity_type.GetSessionEntityTypeRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2808,7 +3244,7 @@ def test_get_session_entity_type_rest_bad_request( def test_get_session_entity_type_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2852,7 +3288,7 @@ def test_get_session_entity_type_rest_flattened(): def test_get_session_entity_type_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2867,7 +3303,7 @@ def test_get_session_entity_type_rest_flattened_error(transport: str = "rest"): def test_get_session_entity_type_rest_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2880,7 +3316,7 @@ def test_get_session_entity_type_rest_error(): ) def test_create_session_entity_type_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3012,7 +3448,7 @@ def test_create_session_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3021,7 +3457,7 @@ def test_create_session_entity_type_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3030,7 +3466,7 @@ def test_create_session_entity_type_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3073,7 +3509,7 @@ def test_create_session_entity_type_rest_required_fields( def test_create_session_entity_type_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_session_entity_type._get_unset_required_fields({}) @@ -3091,7 +3527,7 @@ def test_create_session_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_session_entity_type_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -3150,7 +3586,7 @@ def test_create_session_entity_type_rest_bad_request( request_type=gcd_session_entity_type.CreateSessionEntityTypeRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3172,7 +3608,7 @@ def test_create_session_entity_type_rest_bad_request( def test_create_session_entity_type_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3217,7 +3653,7 @@ def test_create_session_entity_type_rest_flattened(): def test_create_session_entity_type_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3235,7 +3671,7 @@ def test_create_session_entity_type_rest_flattened_error(transport: str = "rest" def test_create_session_entity_type_rest_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3248,7 +3684,7 @@ def test_create_session_entity_type_rest_error(): ) def test_update_session_entity_type_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3383,14 +3819,14 @@ def test_update_session_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_session_entity_type._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3399,7 +3835,7 @@ def test_update_session_entity_type_rest_required_fields( # verify required fields with non-default values are left alone client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3442,7 +3878,7 @@ def test_update_session_entity_type_rest_required_fields( def test_update_session_entity_type_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_session_entity_type._get_unset_required_fields({}) @@ -3452,7 +3888,7 @@ def test_update_session_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_session_entity_type_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -3511,7 +3947,7 @@ def test_update_session_entity_type_rest_bad_request( request_type=gcd_session_entity_type.UpdateSessionEntityTypeRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3537,7 +3973,7 @@ def test_update_session_entity_type_rest_bad_request( def test_update_session_entity_type_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3586,7 +4022,7 @@ def test_update_session_entity_type_rest_flattened(): def test_update_session_entity_type_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3604,7 +4040,7 @@ def test_update_session_entity_type_rest_flattened_error(transport: str = "rest" def test_update_session_entity_type_rest_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3617,7 +4053,7 @@ def test_update_session_entity_type_rest_error(): ) def test_delete_session_entity_type_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3665,7 +4101,7 @@ def test_delete_session_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3674,7 +4110,7 @@ def test_delete_session_entity_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3683,7 +4119,7 @@ def test_delete_session_entity_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3722,7 +4158,7 @@ def test_delete_session_entity_type_rest_required_fields( def test_delete_session_entity_type_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_session_entity_type._get_unset_required_fields({}) @@ -3732,7 +4168,7 @@ def test_delete_session_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_session_entity_type_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -3783,7 +4219,7 @@ def test_delete_session_entity_type_rest_bad_request( request_type=session_entity_type.DeleteSessionEntityTypeRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3807,7 +4243,7 @@ def test_delete_session_entity_type_rest_bad_request( def test_delete_session_entity_type_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3849,7 +4285,7 @@ def test_delete_session_entity_type_rest_flattened(): def test_delete_session_entity_type_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3864,24 +4300,24 @@ def test_delete_session_entity_type_rest_flattened_error(transport: str = "rest" def test_delete_session_entity_type_rest_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionEntityTypesClient( @@ -3891,7 +4327,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3902,16 +4338,17 @@ 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 = SessionEntityTypesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionEntityTypesClient( @@ -3923,7 +4360,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SessionEntityTypesClient(transport=transport) assert client.transport is transport @@ -3932,13 +4369,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SessionEntityTypesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3955,7 +4392,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3969,7 +4406,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SessionEntityTypesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3977,7 +4414,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3989,7 +4426,7 @@ def test_session_entity_types_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SessionEntityTypesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4001,7 +4438,7 @@ def test_session_entity_types_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SessionEntityTypesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4042,7 +4479,7 @@ def test_session_entity_types_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SessionEntityTypesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4064,7 +4501,7 @@ def test_session_entity_types_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SessionEntityTypesTransport() adc.assert_called_once() @@ -4072,7 +4509,7 @@ def test_session_entity_types_base_transport_with_adc(): def test_session_entity_types_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SessionEntityTypesClient() adc.assert_called_once_with( scopes=None, @@ -4095,7 +4532,7 @@ def test_session_entity_types_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4145,7 +4582,7 @@ def test_session_entity_types_transport_create_channel(transport_class, grpc_hel ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4178,7 +4615,7 @@ def test_session_entity_types_transport_create_channel(transport_class, grpc_hel def test_session_entity_types_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4216,7 +4653,7 @@ def test_session_entity_types_grpc_transport_client_cert_source_for_mtls( def test_session_entity_types_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4236,7 +4673,7 @@ def test_session_entity_types_http_transport_client_cert_source_for_mtls(): ) def test_session_entity_types_host_no_port(transport_name): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4259,7 +4696,7 @@ def test_session_entity_types_host_no_port(transport_name): ) def test_session_entity_types_host_with_port(transport_name): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4279,8 +4716,8 @@ def test_session_entity_types_host_with_port(transport_name): ], ) def test_session_entity_types_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SessionEntityTypesClient( credentials=creds1, transport=transport_name, @@ -4356,7 +4793,7 @@ def test_session_entity_types_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4572,7 +5009,7 @@ def test_client_with_default_client_info(): transports.SessionEntityTypesTransport, "_prep_wrapped_messages" ) as prep: client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4582,7 +5019,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SessionEntityTypesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4591,7 +5028,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4606,7 +5043,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4636,7 +5073,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4664,7 +5101,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4692,7 +5129,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4720,7 +5157,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4750,7 +5187,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4778,7 +5215,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4808,7 +5245,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4836,7 +5273,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4864,7 +5301,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4890,7 +5327,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4915,7 +5352,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4939,7 +5376,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4968,7 +5405,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4995,7 +5432,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5013,7 +5450,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5029,7 +5466,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5054,7 +5491,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5080,7 +5517,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5109,7 +5546,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5138,7 +5575,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5156,7 +5593,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5174,7 +5611,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5199,7 +5636,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5225,7 +5662,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5254,7 +5691,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5283,7 +5720,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5301,7 +5738,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5319,7 +5756,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5344,7 +5781,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5370,7 +5807,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5399,7 +5836,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5428,7 +5865,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5446,7 +5883,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5464,7 +5901,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5489,7 +5926,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5514,7 +5951,9 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = SessionEntityTypesClient(credentials=ga_credentials.AnonymousCredentials()) + client = SessionEntityTypesClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5542,7 +5981,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5571,7 +6010,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5589,7 +6028,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5613,7 +6052,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5630,7 +6069,7 @@ def test_client_ctx(): ] for transport in transports: client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5664,7 +6103,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sessions.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sessions.py index 96efa98606ab..f52d0b6ebbac 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sessions.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_sessions.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -74,6 +74,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -98,6 +121,244 @@ def test__get_default_mtls_endpoint(): assert SessionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert SessionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SessionsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SessionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SessionsClient._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 SessionsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SessionsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SessionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SessionsClient._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 SessionsClient._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 SessionsClient._get_client_cert_source(None, False) is None + assert ( + SessionsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + SessionsClient._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 ( + SessionsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SessionsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SessionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsClient), +) +@mock.patch.object( + SessionsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SessionsClient._DEFAULT_UNIVERSE + default_endpoint = SessionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SessionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SessionsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SessionsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SessionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SessionsClient._get_api_endpoint(None, None, default_universe, "always") + == SessionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SessionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SessionsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SessionsClient._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 ( + SessionsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + SessionsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SessionsClient._get_universe_domain(None, None) + == SessionsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SessionsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SessionsClient, transports.SessionsGrpcTransport, "grpc"), + (SessionsClient, transports.SessionsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -107,7 +368,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_sessions_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -159,7 +420,7 @@ def test_sessions_client_service_account_always_use_jwt( ], ) def test_sessions_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -204,17 +465,21 @@ def test_sessions_client_get_transport_class(): ], ) @mock.patch.object( - SessionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SessionsClient) + SessionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsClient), ) @mock.patch.object( SessionsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsAsyncClient), ) def test_sessions_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(SessionsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -249,7 +514,9 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -279,15 +546,23 @@ def test_sessions_client_client_options(client_class, transport_class, transport # 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") @@ -297,7 +572,9 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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", @@ -315,7 +592,9 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -347,12 +626,14 @@ def test_sessions_client_client_options(client_class, transport_class, transport ], ) @mock.patch.object( - SessionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SessionsClient) + SessionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsClient), ) @mock.patch.object( SessionsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_sessions_client_mtls_env_auto( @@ -375,7 +656,9 @@ def test_sessions_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 @@ -407,7 +690,9 @@ def test_sessions_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 @@ -441,7 +726,9 @@ def test_sessions_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, @@ -527,6 +814,116 @@ def test_sessions_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", [SessionsClient, SessionsAsyncClient]) +@mock.patch.object( + SessionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsClient), +) +@mock.patch.object( + SessionsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsAsyncClient), +) +def test_sessions_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SessionsClient._DEFAULT_UNIVERSE + default_endpoint = SessionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SessionsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -549,7 +946,9 @@ def test_sessions_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, @@ -584,7 +983,9 @@ def test_sessions_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, @@ -637,7 +1038,9 @@ def test_sessions_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, @@ -654,8 +1057,8 @@ def test_sessions_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -687,7 +1090,7 @@ def test_sessions_client_create_channel_credentials_file( ) def test_detect_intent(request_type, transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -719,7 +1122,7 @@ def test_detect_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -736,7 +1139,7 @@ async def test_detect_intent_async( transport: str = "grpc_asyncio", request_type=gcd_session.DetectIntentRequest ): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -773,7 +1176,7 @@ async def test_detect_intent_async_from_dict(): def test_detect_intent_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -803,7 +1206,7 @@ def test_detect_intent_field_headers(): @pytest.mark.asyncio async def test_detect_intent_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -834,7 +1237,7 @@ async def test_detect_intent_field_headers_async(): def test_detect_intent_flattened(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -870,7 +1273,7 @@ def test_detect_intent_flattened(): def test_detect_intent_flattened_error(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -890,7 +1293,7 @@ def test_detect_intent_flattened_error(): @pytest.mark.asyncio async def test_detect_intent_flattened_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -931,7 +1334,7 @@ async def test_detect_intent_flattened_async(): @pytest.mark.asyncio async def test_detect_intent_flattened_error_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -957,7 +1360,7 @@ async def test_detect_intent_flattened_error_async(): ) def test_streaming_detect_intent(request_type, transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -989,7 +1392,7 @@ async def test_streaming_detect_intent_async( transport: str = "grpc_asyncio", request_type=session.StreamingDetectIntentRequest ): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1033,7 +1436,7 @@ async def test_streaming_detect_intent_async_from_dict(): ) def test_detect_intent_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1086,7 +1489,7 @@ def test_detect_intent_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).detect_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1095,7 +1498,7 @@ def test_detect_intent_rest_required_fields( jsonified_request["session"] = "session_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).detect_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1104,7 +1507,7 @@ def test_detect_intent_rest_required_fields( assert jsonified_request["session"] == "session_value" client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1147,7 +1550,7 @@ def test_detect_intent_rest_required_fields( def test_detect_intent_rest_unset_required_fields(): transport = transports.SessionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.detect_intent._get_unset_required_fields({}) @@ -1165,7 +1568,7 @@ def test_detect_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_detect_intent_rest_interceptors(null_interceptor): transport = transports.SessionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionsRestInterceptor(), ) client = SessionsClient(transport=transport) @@ -1221,7 +1624,7 @@ def test_detect_intent_rest_bad_request( transport: str = "rest", request_type=gcd_session.DetectIntentRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1243,7 +1646,7 @@ def test_detect_intent_rest_bad_request( def test_detect_intent_rest_flattened(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1290,7 +1693,7 @@ def test_detect_intent_rest_flattened(): def test_detect_intent_rest_flattened_error(transport: str = "rest"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1310,13 +1713,13 @@ def test_detect_intent_rest_flattened_error(transport: str = "rest"): def test_detect_intent_rest_error(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_streaming_detect_intent_rest_no_http_options(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = session.StreamingDetectIntentRequest() @@ -1327,7 +1730,7 @@ def test_streaming_detect_intent_rest_no_http_options(): def test_streaming_detect_intent_rest_error(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) # Since a `google.api.http` annotation is required for using a rest transport # method, this should error. @@ -1341,17 +1744,17 @@ def test_streaming_detect_intent_rest_error(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionsClient( @@ -1361,7 +1764,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1372,16 +1775,17 @@ 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 = SessionsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionsClient( @@ -1393,7 +1797,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SessionsClient(transport=transport) assert client.transport is transport @@ -1402,13 +1806,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SessionsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1425,7 +1829,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1439,7 +1843,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SessionsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1447,7 +1851,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1459,7 +1863,7 @@ def test_sessions_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SessionsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1471,7 +1875,7 @@ def test_sessions_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SessionsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1509,7 +1913,7 @@ def test_sessions_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.sessions.transports.SessionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SessionsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1531,7 +1935,7 @@ def test_sessions_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.sessions.transports.SessionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SessionsTransport() adc.assert_called_once() @@ -1539,7 +1943,7 @@ def test_sessions_base_transport_with_adc(): def test_sessions_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SessionsClient() adc.assert_called_once_with( scopes=None, @@ -1562,7 +1966,7 @@ def test_sessions_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1612,7 +2016,7 @@ def test_sessions_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1640,7 +2044,7 @@ def test_sessions_transport_create_channel(transport_class, grpc_helpers): [transports.SessionsGrpcTransport, transports.SessionsGrpcAsyncIOTransport], ) def test_sessions_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1678,7 +2082,7 @@ def test_sessions_grpc_transport_client_cert_source_for_mtls(transport_class): def test_sessions_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1698,7 +2102,7 @@ def test_sessions_http_transport_client_cert_source_for_mtls(): ) def test_sessions_host_no_port(transport_name): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -1721,7 +2125,7 @@ def test_sessions_host_no_port(transport_name): ) def test_sessions_host_with_port(transport_name): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -1741,8 +2145,8 @@ def test_sessions_host_with_port(transport_name): ], ) def test_sessions_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SessionsClient( credentials=creds1, transport=transport_name, @@ -1804,7 +2208,7 @@ def test_sessions_transport_channel_mtls_with_client_cert_source(transport_class mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2087,7 +2491,7 @@ def test_client_with_default_client_info(): transports.SessionsTransport, "_prep_wrapped_messages" ) as prep: client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2097,7 +2501,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SessionsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2106,7 +2510,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2121,7 +2525,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2151,7 +2555,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -2179,7 +2583,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2207,7 +2611,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2235,7 +2639,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2265,7 +2669,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2293,7 +2697,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2323,7 +2727,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2351,7 +2755,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2379,7 +2783,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2405,7 +2809,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2430,7 +2834,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2454,7 +2858,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2483,7 +2887,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2510,7 +2914,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -2528,7 +2932,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -2544,7 +2948,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2569,7 +2973,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2595,7 +2999,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2624,7 +3028,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2653,7 +3057,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2671,7 +3075,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2689,7 +3093,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2714,7 +3118,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2740,7 +3144,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2769,7 +3173,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2798,7 +3202,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2816,7 +3220,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2834,7 +3238,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2859,7 +3263,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2885,7 +3289,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2914,7 +3318,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2943,7 +3347,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -2961,7 +3365,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -2979,7 +3383,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3004,7 +3408,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3029,7 +3433,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = SessionsClient(credentials=ga_credentials.AnonymousCredentials()) + client = SessionsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -3056,7 +3460,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = SessionsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = SessionsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -3084,7 +3488,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3102,7 +3506,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3126,7 +3530,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3143,7 +3547,7 @@ def test_client_ctx(): ] for transport in transports: client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3174,7 +3578,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_versions.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_versions.py index 2f4bec122cb5..e3b91b4ac401 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_versions.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2/test_versions.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -71,6 +71,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -95,6 +118,244 @@ def test__get_default_mtls_endpoint(): assert VersionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert VersionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert VersionsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert VersionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + VersionsClient._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 VersionsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert VersionsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert VersionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + VersionsClient._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 VersionsClient._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 VersionsClient._get_client_cert_source(None, False) is None + assert ( + VersionsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + VersionsClient._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 ( + VersionsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + VersionsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + VersionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsClient), +) +@mock.patch.object( + VersionsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = VersionsClient._DEFAULT_UNIVERSE + default_endpoint = VersionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = VersionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + VersionsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + VersionsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == VersionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + VersionsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + VersionsClient._get_api_endpoint(None, None, default_universe, "always") + == VersionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + VersionsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == VersionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + VersionsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + VersionsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + VersionsClient._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 ( + VersionsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + VersionsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + VersionsClient._get_universe_domain(None, None) + == VersionsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + VersionsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (VersionsClient, transports.VersionsGrpcTransport, "grpc"), + (VersionsClient, transports.VersionsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -104,7 +365,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_versions_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -156,7 +417,7 @@ def test_versions_client_service_account_always_use_jwt( ], ) def test_versions_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -201,17 +462,21 @@ def test_versions_client_get_transport_class(): ], ) @mock.patch.object( - VersionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(VersionsClient) + VersionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsClient), ) @mock.patch.object( VersionsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(VersionsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsAsyncClient), ) def test_versions_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(VersionsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -246,7 +511,9 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -276,15 +543,23 @@ def test_versions_client_client_options(client_class, transport_class, transport # 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") @@ -294,7 +569,9 @@ def test_versions_client_client_options(client_class, transport_class, transport 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", @@ -312,7 +589,9 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -344,12 +623,14 @@ def test_versions_client_client_options(client_class, transport_class, transport ], ) @mock.patch.object( - VersionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(VersionsClient) + VersionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsClient), ) @mock.patch.object( VersionsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(VersionsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_versions_client_mtls_env_auto( @@ -372,7 +653,9 @@ def test_versions_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 @@ -404,7 +687,9 @@ def test_versions_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 @@ -438,7 +723,9 @@ def test_versions_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, @@ -524,6 +811,116 @@ def test_versions_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", [VersionsClient, VersionsAsyncClient]) +@mock.patch.object( + VersionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsClient), +) +@mock.patch.object( + VersionsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsAsyncClient), +) +def test_versions_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = VersionsClient._DEFAULT_UNIVERSE + default_endpoint = VersionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = VersionsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -546,7 +943,9 @@ def test_versions_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, @@ -581,7 +980,9 @@ def test_versions_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, @@ -634,7 +1035,9 @@ def test_versions_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, @@ -651,8 +1054,8 @@ def test_versions_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -684,7 +1087,7 @@ def test_versions_client_create_channel_credentials_file( ) def test_list_versions(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -714,7 +1117,7 @@ def test_list_versions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -731,7 +1134,7 @@ async def test_list_versions_async( transport: str = "grpc_asyncio", request_type=version.ListVersionsRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -766,7 +1169,7 @@ async def test_list_versions_async_from_dict(): def test_list_versions_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -796,7 +1199,7 @@ def test_list_versions_field_headers(): @pytest.mark.asyncio async def test_list_versions_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -827,7 +1230,7 @@ async def test_list_versions_field_headers_async(): def test_list_versions_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -851,7 +1254,7 @@ def test_list_versions_flattened(): def test_list_versions_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -866,7 +1269,7 @@ def test_list_versions_flattened_error(): @pytest.mark.asyncio async def test_list_versions_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -895,7 +1298,7 @@ async def test_list_versions_flattened_async(): @pytest.mark.asyncio async def test_list_versions_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -909,7 +1312,7 @@ async def test_list_versions_flattened_error_async(): def test_list_versions_pager(transport_name: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -959,7 +1362,7 @@ def test_list_versions_pager(transport_name: str = "grpc"): def test_list_versions_pages(transport_name: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1001,7 +1404,7 @@ def test_list_versions_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_versions_async_pager(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1051,7 +1454,7 @@ async def test_list_versions_async_pager(): @pytest.mark.asyncio async def test_list_versions_async_pages(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1106,7 +1509,7 @@ async def test_list_versions_async_pages(): ) def test_get_version(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1142,7 +1545,7 @@ def test_get_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1159,7 +1562,7 @@ async def test_get_version_async( transport: str = "grpc_asyncio", request_type=version.GetVersionRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1200,7 +1603,7 @@ async def test_get_version_async_from_dict(): def test_get_version_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1230,7 +1633,7 @@ def test_get_version_field_headers(): @pytest.mark.asyncio async def test_get_version_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1259,7 +1662,7 @@ async def test_get_version_field_headers_async(): def test_get_version_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1283,7 +1686,7 @@ def test_get_version_flattened(): def test_get_version_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1298,7 +1701,7 @@ def test_get_version_flattened_error(): @pytest.mark.asyncio async def test_get_version_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1325,7 +1728,7 @@ async def test_get_version_flattened_async(): @pytest.mark.asyncio async def test_get_version_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1346,7 +1749,7 @@ async def test_get_version_flattened_error_async(): ) def test_create_version(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1382,7 +1785,7 @@ def test_create_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1399,7 +1802,7 @@ async def test_create_version_async( transport: str = "grpc_asyncio", request_type=gcd_version.CreateVersionRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1440,7 +1843,7 @@ async def test_create_version_async_from_dict(): def test_create_version_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1470,7 +1873,7 @@ def test_create_version_field_headers(): @pytest.mark.asyncio async def test_create_version_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1499,7 +1902,7 @@ async def test_create_version_field_headers_async(): def test_create_version_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1527,7 +1930,7 @@ def test_create_version_flattened(): def test_create_version_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1543,7 +1946,7 @@ def test_create_version_flattened_error(): @pytest.mark.asyncio async def test_create_version_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1574,7 +1977,7 @@ async def test_create_version_flattened_async(): @pytest.mark.asyncio async def test_create_version_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1596,7 +1999,7 @@ async def test_create_version_flattened_error_async(): ) def test_update_version(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1632,7 +2035,7 @@ def test_update_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1649,7 +2052,7 @@ async def test_update_version_async( transport: str = "grpc_asyncio", request_type=gcd_version.UpdateVersionRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1690,7 +2093,7 @@ async def test_update_version_async_from_dict(): def test_update_version_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1720,7 +2123,7 @@ def test_update_version_field_headers(): @pytest.mark.asyncio async def test_update_version_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1749,7 +2152,7 @@ async def test_update_version_field_headers_async(): def test_update_version_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1777,7 +2180,7 @@ def test_update_version_flattened(): def test_update_version_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1793,7 +2196,7 @@ def test_update_version_flattened_error(): @pytest.mark.asyncio async def test_update_version_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1824,7 +2227,7 @@ async def test_update_version_flattened_async(): @pytest.mark.asyncio async def test_update_version_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1846,7 +2249,7 @@ async def test_update_version_flattened_error_async(): ) def test_delete_version(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1873,7 +2276,7 @@ def test_delete_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1890,7 +2293,7 @@ async def test_delete_version_async( transport: str = "grpc_asyncio", request_type=version.DeleteVersionRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1920,7 +2323,7 @@ async def test_delete_version_async_from_dict(): def test_delete_version_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1950,7 +2353,7 @@ def test_delete_version_field_headers(): @pytest.mark.asyncio async def test_delete_version_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1979,7 +2382,7 @@ async def test_delete_version_field_headers_async(): def test_delete_version_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2003,7 +2406,7 @@ def test_delete_version_flattened(): def test_delete_version_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2018,7 +2421,7 @@ def test_delete_version_flattened_error(): @pytest.mark.asyncio async def test_delete_version_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2045,7 +2448,7 @@ async def test_delete_version_flattened_async(): @pytest.mark.asyncio async def test_delete_version_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2066,7 +2469,7 @@ async def test_delete_version_flattened_error_async(): ) def test_list_versions_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2115,7 +2518,7 @@ def test_list_versions_rest_required_fields(request_type=version.ListVersionsReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_versions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2124,7 +2527,7 @@ def test_list_versions_rest_required_fields(request_type=version.ListVersionsReq jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_versions._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2140,7 +2543,7 @@ def test_list_versions_rest_required_fields(request_type=version.ListVersionsReq assert jsonified_request["parent"] == "parent_value" client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2182,7 +2585,7 @@ def test_list_versions_rest_required_fields(request_type=version.ListVersionsReq def test_list_versions_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_versions._get_unset_required_fields({}) @@ -2200,7 +2603,7 @@ def test_list_versions_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_versions_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -2254,7 +2657,7 @@ def test_list_versions_rest_bad_request( transport: str = "rest", request_type=version.ListVersionsRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2276,7 +2679,7 @@ def test_list_versions_rest_bad_request( def test_list_versions_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2316,7 +2719,7 @@ def test_list_versions_rest_flattened(): def test_list_versions_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2331,7 +2734,7 @@ def test_list_versions_rest_flattened_error(transport: str = "rest"): def test_list_versions_rest_pager(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2399,7 +2802,7 @@ def test_list_versions_rest_pager(transport: str = "rest"): ) def test_get_version_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2454,7 +2857,7 @@ def test_get_version_rest_required_fields(request_type=version.GetVersionRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2463,7 +2866,7 @@ def test_get_version_rest_required_fields(request_type=version.GetVersionRequest jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2472,7 +2875,7 @@ def test_get_version_rest_required_fields(request_type=version.GetVersionRequest assert jsonified_request["name"] == "name_value" client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2514,7 +2917,7 @@ def test_get_version_rest_required_fields(request_type=version.GetVersionRequest def test_get_version_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_version._get_unset_required_fields({}) @@ -2524,7 +2927,7 @@ def test_get_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_version_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -2576,7 +2979,7 @@ def test_get_version_rest_bad_request( transport: str = "rest", request_type=version.GetVersionRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2598,7 +3001,7 @@ def test_get_version_rest_bad_request( def test_get_version_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2638,7 +3041,7 @@ def test_get_version_rest_flattened(): def test_get_version_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2653,7 +3056,7 @@ def test_get_version_rest_flattened_error(transport: str = "rest"): def test_get_version_rest_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2666,7 +3069,7 @@ def test_get_version_rest_error(): ) def test_create_version_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2797,7 +3200,7 @@ def test_create_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2806,7 +3209,7 @@ def test_create_version_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2815,7 +3218,7 @@ def test_create_version_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2858,7 +3261,7 @@ def test_create_version_rest_required_fields( def test_create_version_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_version._get_unset_required_fields({}) @@ -2876,7 +3279,7 @@ def test_create_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_version_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -2930,7 +3333,7 @@ def test_create_version_rest_bad_request( transport: str = "rest", request_type=gcd_version.CreateVersionRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2952,7 +3355,7 @@ def test_create_version_rest_bad_request( def test_create_version_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2993,7 +3396,7 @@ def test_create_version_rest_flattened(): def test_create_version_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3009,7 +3412,7 @@ def test_create_version_rest_flattened_error(transport: str = "rest"): def test_create_version_rest_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3022,7 +3425,7 @@ def test_create_version_rest_error(): ) def test_update_version_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3152,14 +3555,14 @@ def test_update_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_version._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3168,7 +3571,7 @@ def test_update_version_rest_required_fields( # verify required fields with non-default values are left alone client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3211,7 +3614,7 @@ def test_update_version_rest_required_fields( def test_update_version_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_version._get_unset_required_fields({}) @@ -3229,7 +3632,7 @@ def test_update_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_version_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -3283,7 +3686,7 @@ def test_update_version_rest_bad_request( transport: str = "rest", request_type=gcd_version.UpdateVersionRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3305,7 +3708,7 @@ def test_update_version_rest_bad_request( def test_update_version_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3349,7 +3752,7 @@ def test_update_version_rest_flattened(): def test_update_version_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3365,7 +3768,7 @@ def test_update_version_rest_flattened_error(transport: str = "rest"): def test_update_version_rest_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3378,7 +3781,7 @@ def test_update_version_rest_error(): ) def test_delete_version_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3422,7 +3825,7 @@ def test_delete_version_rest_required_fields(request_type=version.DeleteVersionR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3431,7 +3834,7 @@ def test_delete_version_rest_required_fields(request_type=version.DeleteVersionR jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3440,7 +3843,7 @@ def test_delete_version_rest_required_fields(request_type=version.DeleteVersionR assert jsonified_request["name"] == "name_value" client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3479,7 +3882,7 @@ def test_delete_version_rest_required_fields(request_type=version.DeleteVersionR def test_delete_version_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_version._get_unset_required_fields({}) @@ -3489,7 +3892,7 @@ def test_delete_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_version_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -3535,7 +3938,7 @@ def test_delete_version_rest_bad_request( transport: str = "rest", request_type=version.DeleteVersionRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3557,7 +3960,7 @@ def test_delete_version_rest_bad_request( def test_delete_version_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3595,7 +3998,7 @@ def test_delete_version_rest_flattened(): def test_delete_version_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3610,24 +4013,24 @@ def test_delete_version_rest_flattened_error(transport: str = "rest"): def test_delete_version_rest_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = VersionsClient( @@ -3637,7 +4040,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3648,16 +4051,17 @@ 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 = VersionsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = VersionsClient( @@ -3669,7 +4073,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = VersionsClient(transport=transport) assert client.transport is transport @@ -3678,13 +4082,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.VersionsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3701,7 +4105,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3715,7 +4119,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = VersionsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3723,7 +4127,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3735,7 +4139,7 @@ def test_versions_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.VersionsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3747,7 +4151,7 @@ def test_versions_base_transport(): ) as Transport: Transport.return_value = None transport = transports.VersionsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3788,7 +4192,7 @@ def test_versions_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2.services.versions.transports.VersionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.VersionsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3810,7 +4214,7 @@ def test_versions_base_transport_with_adc(): "google.cloud.dialogflow_v2.services.versions.transports.VersionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.VersionsTransport() adc.assert_called_once() @@ -3818,7 +4222,7 @@ def test_versions_base_transport_with_adc(): def test_versions_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) VersionsClient() adc.assert_called_once_with( scopes=None, @@ -3841,7 +4245,7 @@ def test_versions_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -3891,7 +4295,7 @@ def test_versions_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3919,7 +4323,7 @@ def test_versions_transport_create_channel(transport_class, grpc_helpers): [transports.VersionsGrpcTransport, transports.VersionsGrpcAsyncIOTransport], ) def test_versions_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3957,7 +4361,7 @@ def test_versions_grpc_transport_client_cert_source_for_mtls(transport_class): def test_versions_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -3977,7 +4381,7 @@ def test_versions_http_transport_client_cert_source_for_mtls(): ) def test_versions_host_no_port(transport_name): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4000,7 +4404,7 @@ def test_versions_host_no_port(transport_name): ) def test_versions_host_with_port(transport_name): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4020,8 +4424,8 @@ def test_versions_host_with_port(transport_name): ], ) def test_versions_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = VersionsClient( credentials=creds1, transport=transport_name, @@ -4092,7 +4496,7 @@ def test_versions_transport_channel_mtls_with_client_cert_source(transport_class mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4298,7 +4702,7 @@ def test_client_with_default_client_info(): transports.VersionsTransport, "_prep_wrapped_messages" ) as prep: client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4308,7 +4712,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = VersionsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4317,7 +4721,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4332,7 +4736,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4362,7 +4766,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4390,7 +4794,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4418,7 +4822,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4446,7 +4850,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4476,7 +4880,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4504,7 +4908,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4534,7 +4938,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4562,7 +4966,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4590,7 +4994,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4616,7 +5020,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4641,7 +5045,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4665,7 +5069,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4694,7 +5098,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4721,7 +5125,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4739,7 +5143,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4755,7 +5159,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4780,7 +5184,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4806,7 +5210,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4835,7 +5239,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4864,7 +5268,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4882,7 +5286,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4900,7 +5304,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4925,7 +5329,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4951,7 +5355,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4980,7 +5384,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5009,7 +5413,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5027,7 +5431,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5045,7 +5449,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5070,7 +5474,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5096,7 +5500,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5125,7 +5529,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5154,7 +5558,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5172,7 +5576,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5190,7 +5594,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5215,7 +5619,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5240,7 +5644,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = VersionsClient(credentials=ga_credentials.AnonymousCredentials()) + client = VersionsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5267,7 +5671,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = VersionsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = VersionsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5295,7 +5699,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5313,7 +5717,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5337,7 +5741,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5354,7 +5758,7 @@ def test_client_ctx(): ] for transport in transports: client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5385,7 +5789,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_agents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_agents.py index 10a55b60c75c..adf62740e1c8 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_agents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_agents.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -82,6 +82,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -105,6 +128,237 @@ def test__get_default_mtls_endpoint(): assert AgentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert AgentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert AgentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert AgentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + AgentsClient._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 AgentsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert AgentsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert AgentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + AgentsClient._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 AgentsClient._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 AgentsClient._get_client_cert_source(None, False) is None + assert ( + AgentsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + AgentsClient._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 ( + AgentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + AgentsClient._get_client_cert_source(mock_provided_cert_source, "true") + is mock_provided_cert_source + ) + + +@mock.patch.object( + AgentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsClient), +) +@mock.patch.object( + AgentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = AgentsClient._DEFAULT_UNIVERSE + default_endpoint = AgentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AgentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + AgentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + AgentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == AgentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AgentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + AgentsClient._get_api_endpoint(None, None, default_universe, "always") + == AgentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AgentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == AgentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AgentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + AgentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + AgentsClient._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 ( + AgentsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + AgentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + AgentsClient._get_universe_domain(None, None) == AgentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + AgentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (AgentsClient, transports.AgentsGrpcTransport, "grpc"), + (AgentsClient, transports.AgentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -114,7 +368,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_agents_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -164,7 +418,7 @@ def test_agents_client_service_account_always_use_jwt(transport_class, transport ], ) def test_agents_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -209,15 +463,21 @@ def test_agents_client_get_transport_class(): ], ) @mock.patch.object( - AgentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AgentsClient) + AgentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsClient), ) @mock.patch.object( - AgentsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AgentsAsyncClient) + AgentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsAsyncClient), ) def test_agents_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(AgentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -252,7 +512,9 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -282,15 +544,23 @@ def test_agents_client_client_options(client_class, transport_class, transport_n # 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") @@ -300,7 +570,9 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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", @@ -318,7 +590,9 @@ def test_agents_client_client_options(client_class, transport_class, transport_n 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, @@ -350,10 +624,14 @@ def test_agents_client_client_options(client_class, transport_class, transport_n ], ) @mock.patch.object( - AgentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AgentsClient) + AgentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsClient), ) @mock.patch.object( - AgentsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AgentsAsyncClient) + AgentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_agents_client_mtls_env_auto( @@ -376,7 +654,9 @@ def test_agents_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 @@ -408,7 +688,9 @@ def test_agents_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 @@ -442,7 +724,9 @@ def test_agents_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, @@ -526,6 +810,116 @@ def test_agents_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", [AgentsClient, AgentsAsyncClient]) +@mock.patch.object( + AgentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsClient), +) +@mock.patch.object( + AgentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AgentsAsyncClient), +) +def test_agents_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = AgentsClient._DEFAULT_UNIVERSE + default_endpoint = AgentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AgentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -548,7 +942,9 @@ def test_agents_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, @@ -583,7 +979,9 @@ def test_agents_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, @@ -636,7 +1034,9 @@ def test_agents_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, @@ -653,8 +1053,8 @@ def test_agents_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -686,7 +1086,7 @@ def test_agents_client_create_channel_credentials_file( ) def test_get_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -740,7 +1140,7 @@ def test_get_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -757,7 +1157,7 @@ async def test_get_agent_async( transport: str = "grpc_asyncio", request_type=agent.GetAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -816,7 +1216,7 @@ async def test_get_agent_async_from_dict(): def test_get_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -846,7 +1246,7 @@ def test_get_agent_field_headers(): @pytest.mark.asyncio async def test_get_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -875,7 +1275,7 @@ async def test_get_agent_field_headers_async(): def test_get_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -899,7 +1299,7 @@ def test_get_agent_flattened(): def test_get_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -914,7 +1314,7 @@ def test_get_agent_flattened_error(): @pytest.mark.asyncio async def test_get_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -941,7 +1341,7 @@ async def test_get_agent_flattened_async(): @pytest.mark.asyncio async def test_get_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -962,7 +1362,7 @@ async def test_get_agent_flattened_error_async(): ) def test_set_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1016,7 +1416,7 @@ def test_set_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1033,7 +1433,7 @@ async def test_set_agent_async( transport: str = "grpc_asyncio", request_type=gcd_agent.SetAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1092,7 +1492,7 @@ async def test_set_agent_async_from_dict(): def test_set_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1122,7 +1522,7 @@ def test_set_agent_field_headers(): @pytest.mark.asyncio async def test_set_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1151,7 +1551,7 @@ async def test_set_agent_field_headers_async(): def test_set_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1175,7 +1575,7 @@ def test_set_agent_flattened(): def test_set_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1190,7 +1590,7 @@ def test_set_agent_flattened_error(): @pytest.mark.asyncio async def test_set_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1217,7 +1617,7 @@ async def test_set_agent_flattened_async(): @pytest.mark.asyncio async def test_set_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1238,7 +1638,7 @@ async def test_set_agent_flattened_error_async(): ) def test_delete_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1265,7 +1665,7 @@ def test_delete_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1282,7 +1682,7 @@ async def test_delete_agent_async( transport: str = "grpc_asyncio", request_type=agent.DeleteAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1312,7 +1712,7 @@ async def test_delete_agent_async_from_dict(): def test_delete_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1342,7 +1742,7 @@ def test_delete_agent_field_headers(): @pytest.mark.asyncio async def test_delete_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1371,7 +1771,7 @@ async def test_delete_agent_field_headers_async(): def test_delete_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1395,7 +1795,7 @@ def test_delete_agent_flattened(): def test_delete_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1410,7 +1810,7 @@ def test_delete_agent_flattened_error(): @pytest.mark.asyncio async def test_delete_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1437,7 +1837,7 @@ async def test_delete_agent_flattened_async(): @pytest.mark.asyncio async def test_delete_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1458,7 +1858,7 @@ async def test_delete_agent_flattened_error_async(): ) def test_search_agents(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1488,7 +1888,7 @@ def test_search_agents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1505,7 +1905,7 @@ async def test_search_agents_async( transport: str = "grpc_asyncio", request_type=agent.SearchAgentsRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1540,7 +1940,7 @@ async def test_search_agents_async_from_dict(): def test_search_agents_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1570,7 +1970,7 @@ def test_search_agents_field_headers(): @pytest.mark.asyncio async def test_search_agents_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1601,7 +2001,7 @@ async def test_search_agents_field_headers_async(): def test_search_agents_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1625,7 +2025,7 @@ def test_search_agents_flattened(): def test_search_agents_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1640,7 +2040,7 @@ def test_search_agents_flattened_error(): @pytest.mark.asyncio async def test_search_agents_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1669,7 +2069,7 @@ async def test_search_agents_flattened_async(): @pytest.mark.asyncio async def test_search_agents_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1683,7 +2083,7 @@ async def test_search_agents_flattened_error_async(): def test_search_agents_pager(transport_name: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1733,7 +2133,7 @@ def test_search_agents_pager(transport_name: str = "grpc"): def test_search_agents_pages(transport_name: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1775,7 +2175,7 @@ def test_search_agents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_search_agents_async_pager(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1825,7 +2225,7 @@ async def test_search_agents_async_pager(): @pytest.mark.asyncio async def test_search_agents_async_pages(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1880,7 +2280,7 @@ async def test_search_agents_async_pages(): ) def test_train_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1907,7 +2307,7 @@ def test_train_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1924,7 +2324,7 @@ async def test_train_agent_async( transport: str = "grpc_asyncio", request_type=agent.TrainAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1956,7 +2356,7 @@ async def test_train_agent_async_from_dict(): def test_train_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1986,7 +2386,7 @@ def test_train_agent_field_headers(): @pytest.mark.asyncio async def test_train_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2017,7 +2417,7 @@ async def test_train_agent_field_headers_async(): def test_train_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2041,7 +2441,7 @@ def test_train_agent_flattened(): def test_train_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2056,7 +2456,7 @@ def test_train_agent_flattened_error(): @pytest.mark.asyncio async def test_train_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2085,7 +2485,7 @@ async def test_train_agent_flattened_async(): @pytest.mark.asyncio async def test_train_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2106,7 +2506,7 @@ async def test_train_agent_flattened_error_async(): ) def test_export_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2133,7 +2533,7 @@ def test_export_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2150,7 +2550,7 @@ async def test_export_agent_async( transport: str = "grpc_asyncio", request_type=agent.ExportAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2182,7 +2582,7 @@ async def test_export_agent_async_from_dict(): def test_export_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2212,7 +2612,7 @@ def test_export_agent_field_headers(): @pytest.mark.asyncio async def test_export_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2243,7 +2643,7 @@ async def test_export_agent_field_headers_async(): def test_export_agent_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2267,7 +2667,7 @@ def test_export_agent_flattened(): def test_export_agent_flattened_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2282,7 +2682,7 @@ def test_export_agent_flattened_error(): @pytest.mark.asyncio async def test_export_agent_flattened_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2311,7 +2711,7 @@ async def test_export_agent_flattened_async(): @pytest.mark.asyncio async def test_export_agent_flattened_error_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2332,7 +2732,7 @@ async def test_export_agent_flattened_error_async(): ) def test_import_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2359,7 +2759,7 @@ def test_import_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2376,7 +2776,7 @@ async def test_import_agent_async( transport: str = "grpc_asyncio", request_type=agent.ImportAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2408,7 +2808,7 @@ async def test_import_agent_async_from_dict(): def test_import_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2438,7 +2838,7 @@ def test_import_agent_field_headers(): @pytest.mark.asyncio async def test_import_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2476,7 +2876,7 @@ async def test_import_agent_field_headers_async(): ) def test_restore_agent(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2503,7 +2903,7 @@ def test_restore_agent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2520,7 +2920,7 @@ async def test_restore_agent_async( transport: str = "grpc_asyncio", request_type=agent.RestoreAgentRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2552,7 +2952,7 @@ async def test_restore_agent_async_from_dict(): def test_restore_agent_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2582,7 +2982,7 @@ def test_restore_agent_field_headers(): @pytest.mark.asyncio async def test_restore_agent_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2620,7 +3020,7 @@ async def test_restore_agent_field_headers_async(): ) def test_get_validation_result(request_type, transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2649,7 +3049,7 @@ def test_get_validation_result_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2668,7 +3068,7 @@ async def test_get_validation_result_async( transport: str = "grpc_asyncio", request_type=agent.GetValidationResultRequest ): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2702,7 +3102,7 @@ async def test_get_validation_result_async_from_dict(): def test_get_validation_result_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2734,7 +3134,7 @@ def test_get_validation_result_field_headers(): @pytest.mark.asyncio async def test_get_validation_result_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2774,7 +3174,7 @@ async def test_get_validation_result_field_headers_async(): ) def test_get_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2847,7 +3247,7 @@ def test_get_agent_rest_required_fields(request_type=agent.GetAgentRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2856,7 +3256,7 @@ def test_get_agent_rest_required_fields(request_type=agent.GetAgentRequest): jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2865,7 +3265,7 @@ def test_get_agent_rest_required_fields(request_type=agent.GetAgentRequest): assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2907,7 +3307,7 @@ def test_get_agent_rest_required_fields(request_type=agent.GetAgentRequest): def test_get_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_agent._get_unset_required_fields({}) @@ -2917,7 +3317,7 @@ def test_get_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -2969,7 +3369,7 @@ def test_get_agent_rest_bad_request( transport: str = "rest", request_type=agent.GetAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2991,7 +3391,7 @@ def test_get_agent_rest_bad_request( def test_get_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3031,7 +3431,7 @@ def test_get_agent_rest_flattened(): def test_get_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3046,7 +3446,7 @@ def test_get_agent_rest_flattened_error(transport: str = "rest"): def test_get_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3059,7 +3459,7 @@ def test_get_agent_rest_error(): ) def test_set_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3215,14 +3615,14 @@ def test_set_agent_rest_required_fields(request_type=gcd_agent.SetAgentRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_agent._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3231,7 +3631,7 @@ def test_set_agent_rest_required_fields(request_type=gcd_agent.SetAgentRequest): # verify required fields with non-default values are left alone client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3274,7 +3674,7 @@ def test_set_agent_rest_required_fields(request_type=gcd_agent.SetAgentRequest): def test_set_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.set_agent._get_unset_required_fields({}) @@ -3284,7 +3684,7 @@ def test_set_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_set_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -3336,7 +3736,7 @@ def test_set_agent_rest_bad_request( transport: str = "rest", request_type=gcd_agent.SetAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3358,7 +3758,7 @@ def test_set_agent_rest_bad_request( def test_set_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3399,7 +3799,7 @@ def test_set_agent_rest_flattened(): def test_set_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3414,7 +3814,7 @@ def test_set_agent_rest_flattened_error(transport: str = "rest"): def test_set_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3427,7 +3827,7 @@ def test_set_agent_rest_error(): ) def test_delete_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3471,7 +3871,7 @@ def test_delete_agent_rest_required_fields(request_type=agent.DeleteAgentRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3480,7 +3880,7 @@ def test_delete_agent_rest_required_fields(request_type=agent.DeleteAgentRequest jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3489,7 +3889,7 @@ def test_delete_agent_rest_required_fields(request_type=agent.DeleteAgentRequest assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3528,7 +3928,7 @@ def test_delete_agent_rest_required_fields(request_type=agent.DeleteAgentRequest def test_delete_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_agent._get_unset_required_fields({}) @@ -3538,7 +3938,7 @@ def test_delete_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -3584,7 +3984,7 @@ def test_delete_agent_rest_bad_request( transport: str = "rest", request_type=agent.DeleteAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3606,7 +4006,7 @@ def test_delete_agent_rest_bad_request( def test_delete_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3644,7 +4044,7 @@ def test_delete_agent_rest_flattened(): def test_delete_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3659,7 +4059,7 @@ def test_delete_agent_rest_flattened_error(transport: str = "rest"): def test_delete_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3672,7 +4072,7 @@ def test_delete_agent_rest_error(): ) def test_search_agents_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3721,7 +4121,7 @@ def test_search_agents_rest_required_fields(request_type=agent.SearchAgentsReque # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_agents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3730,7 +4130,7 @@ def test_search_agents_rest_required_fields(request_type=agent.SearchAgentsReque jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_agents._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3746,7 +4146,7 @@ def test_search_agents_rest_required_fields(request_type=agent.SearchAgentsReque assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3788,7 +4188,7 @@ def test_search_agents_rest_required_fields(request_type=agent.SearchAgentsReque def test_search_agents_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search_agents._get_unset_required_fields({}) @@ -3806,7 +4206,7 @@ def test_search_agents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_agents_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -3860,7 +4260,7 @@ def test_search_agents_rest_bad_request( transport: str = "rest", request_type=agent.SearchAgentsRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3882,7 +4282,7 @@ def test_search_agents_rest_bad_request( def test_search_agents_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3923,7 +4323,7 @@ def test_search_agents_rest_flattened(): def test_search_agents_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3938,7 +4338,7 @@ def test_search_agents_rest_flattened_error(transport: str = "rest"): def test_search_agents_rest_pager(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4006,7 +4406,7 @@ def test_search_agents_rest_pager(transport: str = "rest"): ) def test_train_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4050,7 +4450,7 @@ def test_train_agent_rest_required_fields(request_type=agent.TrainAgentRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4059,7 +4459,7 @@ def test_train_agent_rest_required_fields(request_type=agent.TrainAgentRequest): jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4068,7 +4468,7 @@ def test_train_agent_rest_required_fields(request_type=agent.TrainAgentRequest): assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4108,7 +4508,7 @@ def test_train_agent_rest_required_fields(request_type=agent.TrainAgentRequest): def test_train_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.train_agent._get_unset_required_fields({}) @@ -4118,7 +4518,7 @@ def test_train_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_train_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -4174,7 +4574,7 @@ def test_train_agent_rest_bad_request( transport: str = "rest", request_type=agent.TrainAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4196,7 +4596,7 @@ def test_train_agent_rest_bad_request( def test_train_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4235,7 +4635,7 @@ def test_train_agent_rest_flattened(): def test_train_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4250,7 +4650,7 @@ def test_train_agent_rest_flattened_error(transport: str = "rest"): def test_train_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4263,7 +4663,7 @@ def test_train_agent_rest_error(): ) def test_export_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4307,7 +4707,7 @@ def test_export_agent_rest_required_fields(request_type=agent.ExportAgentRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4316,7 +4716,7 @@ def test_export_agent_rest_required_fields(request_type=agent.ExportAgentRequest jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4325,7 +4725,7 @@ def test_export_agent_rest_required_fields(request_type=agent.ExportAgentRequest assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4365,7 +4765,7 @@ def test_export_agent_rest_required_fields(request_type=agent.ExportAgentRequest def test_export_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.export_agent._get_unset_required_fields({}) @@ -4375,7 +4775,7 @@ def test_export_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_export_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -4431,7 +4831,7 @@ def test_export_agent_rest_bad_request( transport: str = "rest", request_type=agent.ExportAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4453,7 +4853,7 @@ def test_export_agent_rest_bad_request( def test_export_agent_rest_flattened(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4492,7 +4892,7 @@ def test_export_agent_rest_flattened(): def test_export_agent_rest_flattened_error(transport: str = "rest"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4507,7 +4907,7 @@ def test_export_agent_rest_flattened_error(transport: str = "rest"): def test_export_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4520,7 +4920,7 @@ def test_export_agent_rest_error(): ) def test_import_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4564,7 +4964,7 @@ def test_import_agent_rest_required_fields(request_type=agent.ImportAgentRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4573,7 +4973,7 @@ def test_import_agent_rest_required_fields(request_type=agent.ImportAgentRequest jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4582,7 +4982,7 @@ def test_import_agent_rest_required_fields(request_type=agent.ImportAgentRequest assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4622,7 +5022,7 @@ def test_import_agent_rest_required_fields(request_type=agent.ImportAgentRequest def test_import_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_agent._get_unset_required_fields({}) @@ -4632,7 +5032,7 @@ def test_import_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -4688,7 +5088,7 @@ def test_import_agent_rest_bad_request( transport: str = "rest", request_type=agent.ImportAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4710,7 +5110,7 @@ def test_import_agent_rest_bad_request( def test_import_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4723,7 +5123,7 @@ def test_import_agent_rest_error(): ) def test_restore_agent_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4767,7 +5167,7 @@ def test_restore_agent_rest_required_fields(request_type=agent.RestoreAgentReque # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).restore_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4776,7 +5176,7 @@ def test_restore_agent_rest_required_fields(request_type=agent.RestoreAgentReque jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).restore_agent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4785,7 +5185,7 @@ def test_restore_agent_rest_required_fields(request_type=agent.RestoreAgentReque assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4825,7 +5225,7 @@ def test_restore_agent_rest_required_fields(request_type=agent.RestoreAgentReque def test_restore_agent_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.restore_agent._get_unset_required_fields({}) @@ -4835,7 +5235,7 @@ def test_restore_agent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_restore_agent_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -4891,7 +5291,7 @@ def test_restore_agent_rest_bad_request( transport: str = "rest", request_type=agent.RestoreAgentRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4913,7 +5313,7 @@ def test_restore_agent_rest_bad_request( def test_restore_agent_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4926,7 +5326,7 @@ def test_restore_agent_rest_error(): ) def test_get_validation_result_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4974,7 +5374,7 @@ def test_get_validation_result_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_validation_result._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4983,7 +5383,7 @@ def test_get_validation_result_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_validation_result._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("language_code",)) @@ -4994,7 +5394,7 @@ def test_get_validation_result_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5036,7 +5436,7 @@ def test_get_validation_result_rest_required_fields( def test_get_validation_result_rest_unset_required_fields(): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_validation_result._get_unset_required_fields({}) @@ -5046,7 +5446,7 @@ def test_get_validation_result_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_validation_result_rest_interceptors(null_interceptor): transport = transports.AgentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AgentsRestInterceptor(), ) client = AgentsClient(transport=transport) @@ -5102,7 +5502,7 @@ def test_get_validation_result_rest_bad_request( transport: str = "rest", request_type=agent.GetValidationResultRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5124,24 +5524,24 @@ def test_get_validation_result_rest_bad_request( def test_get_validation_result_rest_error(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AgentsClient( @@ -5151,7 +5551,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5162,16 +5562,17 @@ 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 = AgentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AgentsClient( @@ -5183,7 +5584,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = AgentsClient(transport=transport) assert client.transport is transport @@ -5192,13 +5593,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AgentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.AgentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5215,7 +5616,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5229,7 +5630,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = AgentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5237,7 +5638,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5249,7 +5650,7 @@ def test_agents_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.AgentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5261,7 +5662,7 @@ def test_agents_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AgentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5311,7 +5712,7 @@ def test_agents_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AgentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5333,7 +5734,7 @@ def test_agents_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.agents.transports.AgentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AgentsTransport() adc.assert_called_once() @@ -5341,7 +5742,7 @@ def test_agents_base_transport_with_adc(): def test_agents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) AgentsClient() adc.assert_called_once_with( scopes=None, @@ -5364,7 +5765,7 @@ def test_agents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5414,7 +5815,7 @@ def test_agents_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5442,7 +5843,7 @@ def test_agents_transport_create_channel(transport_class, grpc_helpers): [transports.AgentsGrpcTransport, transports.AgentsGrpcAsyncIOTransport], ) def test_agents_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5480,7 +5881,7 @@ def test_agents_grpc_transport_client_cert_source_for_mtls(transport_class): def test_agents_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5492,7 +5893,7 @@ def test_agents_http_transport_client_cert_source_for_mtls(): def test_agents_rest_lro_client(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5517,7 +5918,7 @@ def test_agents_rest_lro_client(): ) def test_agents_host_no_port(transport_name): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -5540,7 +5941,7 @@ def test_agents_host_no_port(transport_name): ) def test_agents_host_with_port(transport_name): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -5560,8 +5961,8 @@ def test_agents_host_with_port(transport_name): ], ) def test_agents_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = AgentsClient( credentials=creds1, transport=transport_name, @@ -5644,7 +6045,7 @@ def test_agents_transport_channel_mtls_with_client_cert_source(transport_class): mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5719,7 +6120,7 @@ def test_agents_transport_channel_mtls_with_adc(transport_class): def test_agents_grpc_lro_client(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5736,7 +6137,7 @@ def test_agents_grpc_lro_client(): def test_agents_grpc_lro_async_client(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -5881,7 +6282,7 @@ def test_client_with_default_client_info(): transports.AgentsTransport, "_prep_wrapped_messages" ) as prep: client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5891,7 +6292,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = AgentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5900,7 +6301,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5915,7 +6316,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5945,7 +6346,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -5973,7 +6374,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6001,7 +6402,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6029,7 +6430,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6059,7 +6460,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6087,7 +6488,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6117,7 +6518,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6145,7 +6546,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6173,7 +6574,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6199,7 +6600,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6224,7 +6625,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6248,7 +6649,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6277,7 +6678,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6304,7 +6705,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6322,7 +6723,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6338,7 +6739,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6363,7 +6764,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6389,7 +6790,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6418,7 +6819,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6447,7 +6848,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6465,7 +6866,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6483,7 +6884,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6508,7 +6909,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6534,7 +6935,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6563,7 +6964,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6592,7 +6993,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6610,7 +7011,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6628,7 +7029,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6653,7 +7054,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6679,7 +7080,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6708,7 +7109,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6737,7 +7138,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6755,7 +7156,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6773,7 +7174,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6798,7 +7199,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6823,7 +7224,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = AgentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = AgentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -6850,7 +7251,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = AgentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = AgentsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -6878,7 +7279,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6896,7 +7297,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = AgentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6920,7 +7321,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -6937,7 +7338,7 @@ def test_client_ctx(): ] for transport in transports: client = AgentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -6968,7 +7369,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py index 7ebe989bea85..b0d088a8feb7 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_answer_records.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -73,6 +73,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -102,6 +125,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert AnswerRecordsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert AnswerRecordsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert AnswerRecordsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + AnswerRecordsClient._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 AnswerRecordsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert AnswerRecordsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert AnswerRecordsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + AnswerRecordsClient._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 AnswerRecordsClient._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 AnswerRecordsClient._get_client_cert_source(None, False) is None + assert ( + AnswerRecordsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + AnswerRecordsClient._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 ( + AnswerRecordsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + AnswerRecordsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + AnswerRecordsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsClient), +) +@mock.patch.object( + AnswerRecordsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = AnswerRecordsClient._DEFAULT_UNIVERSE + default_endpoint = AnswerRecordsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AnswerRecordsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + AnswerRecordsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + AnswerRecordsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AnswerRecordsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + AnswerRecordsClient._get_api_endpoint(None, None, default_universe, "always") + == AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AnswerRecordsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == AnswerRecordsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AnswerRecordsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + AnswerRecordsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + AnswerRecordsClient._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 ( + AnswerRecordsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + AnswerRecordsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + AnswerRecordsClient._get_universe_domain(None, None) + == AnswerRecordsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + AnswerRecordsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (AnswerRecordsClient, transports.AnswerRecordsGrpcTransport, "grpc"), + (AnswerRecordsClient, transports.AnswerRecordsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -111,7 +391,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_answer_records_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -163,7 +443,7 @@ def test_answer_records_client_service_account_always_use_jwt( ], ) def test_answer_records_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -213,20 +493,22 @@ def test_answer_records_client_get_transport_class(): ) @mock.patch.object( AnswerRecordsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AnswerRecordsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsClient), ) @mock.patch.object( AnswerRecordsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AnswerRecordsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsAsyncClient), ) def test_answer_records_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(AnswerRecordsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -261,7 +543,9 @@ def test_answer_records_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, @@ -291,15 +575,23 @@ def test_answer_records_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") @@ -309,7 +601,9 @@ def test_answer_records_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", @@ -327,7 +621,9 @@ def test_answer_records_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, @@ -360,13 +656,13 @@ def test_answer_records_client_client_options( ) @mock.patch.object( AnswerRecordsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AnswerRecordsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsClient), ) @mock.patch.object( AnswerRecordsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AnswerRecordsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_answer_records_client_mtls_env_auto( @@ -389,7 +685,9 @@ def test_answer_records_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 @@ -421,7 +719,9 @@ def test_answer_records_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 @@ -455,7 +755,9 @@ def test_answer_records_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, @@ -545,6 +847,118 @@ def test_answer_records_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", [AnswerRecordsClient, AnswerRecordsAsyncClient] +) +@mock.patch.object( + AnswerRecordsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsClient), +) +@mock.patch.object( + AnswerRecordsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AnswerRecordsAsyncClient), +) +def test_answer_records_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = AnswerRecordsClient._DEFAULT_UNIVERSE + default_endpoint = AnswerRecordsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AnswerRecordsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -571,7 +985,9 @@ def test_answer_records_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, @@ -611,7 +1027,9 @@ def test_answer_records_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, @@ -671,7 +1089,9 @@ def test_answer_records_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, @@ -688,8 +1108,8 @@ def test_answer_records_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -721,7 +1141,7 @@ def test_answer_records_client_create_channel_credentials_file( ) def test_get_answer_record(request_type, transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -753,7 +1173,7 @@ def test_get_answer_record_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -772,7 +1192,7 @@ async def test_get_answer_record_async( transport: str = "grpc_asyncio", request_type=answer_record.GetAnswerRecordRequest ): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -809,7 +1229,7 @@ async def test_get_answer_record_async_from_dict(): def test_get_answer_record_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -841,7 +1261,7 @@ def test_get_answer_record_field_headers(): @pytest.mark.asyncio async def test_get_answer_record_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -881,7 +1301,7 @@ async def test_get_answer_record_field_headers_async(): ) def test_list_answer_records(request_type, transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -913,7 +1333,7 @@ def test_list_answer_records_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -932,7 +1352,7 @@ async def test_list_answer_records_async( transport: str = "grpc_asyncio", request_type=answer_record.ListAnswerRecordsRequest ): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -969,7 +1389,7 @@ async def test_list_answer_records_async_from_dict(): def test_list_answer_records_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1001,7 +1421,7 @@ def test_list_answer_records_field_headers(): @pytest.mark.asyncio async def test_list_answer_records_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1034,7 +1454,7 @@ async def test_list_answer_records_field_headers_async(): def test_list_answer_records_flattened(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1060,7 +1480,7 @@ def test_list_answer_records_flattened(): def test_list_answer_records_flattened_error(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1075,7 +1495,7 @@ def test_list_answer_records_flattened_error(): @pytest.mark.asyncio async def test_list_answer_records_flattened_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1106,7 +1526,7 @@ async def test_list_answer_records_flattened_async(): @pytest.mark.asyncio async def test_list_answer_records_flattened_error_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1120,7 +1540,7 @@ async def test_list_answer_records_flattened_error_async(): def test_list_answer_records_pager(transport_name: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1172,7 +1592,7 @@ def test_list_answer_records_pager(transport_name: str = "grpc"): def test_list_answer_records_pages(transport_name: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1216,7 +1636,7 @@ def test_list_answer_records_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_answer_records_async_pager(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1268,7 +1688,7 @@ async def test_list_answer_records_async_pager(): @pytest.mark.asyncio async def test_list_answer_records_async_pages(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1325,7 +1745,7 @@ async def test_list_answer_records_async_pages(): ) def test_update_answer_record(request_type, transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1357,7 +1777,7 @@ def test_update_answer_record_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1377,7 +1797,7 @@ async def test_update_answer_record_async( request_type=gcd_answer_record.UpdateAnswerRecordRequest, ): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1414,7 +1834,7 @@ async def test_update_answer_record_async_from_dict(): def test_update_answer_record_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1446,7 +1866,7 @@ def test_update_answer_record_field_headers(): @pytest.mark.asyncio async def test_update_answer_record_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1479,7 +1899,7 @@ async def test_update_answer_record_field_headers_async(): def test_update_answer_record_flattened(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1509,7 +1929,7 @@ def test_update_answer_record_flattened(): def test_update_answer_record_flattened_error(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1525,7 +1945,7 @@ def test_update_answer_record_flattened_error(): @pytest.mark.asyncio async def test_update_answer_record_flattened_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1560,7 +1980,7 @@ async def test_update_answer_record_flattened_async(): @pytest.mark.asyncio async def test_update_answer_record_flattened_error_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1582,7 +2002,7 @@ async def test_update_answer_record_flattened_error_async(): ) def test_get_answer_record_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1616,7 +2036,7 @@ def test_get_answer_record_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_answer_record_rest_interceptors(null_interceptor): transport = transports.AnswerRecordsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AnswerRecordsRestInterceptor(), @@ -1674,7 +2094,7 @@ def test_get_answer_record_rest_bad_request( transport: str = "rest", request_type=answer_record.GetAnswerRecordRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1696,7 +2116,7 @@ def test_get_answer_record_rest_bad_request( def test_get_answer_record_rest_error(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -1709,7 +2129,7 @@ def test_get_answer_record_rest_error(): ) def test_list_answer_records_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1743,7 +2163,7 @@ def test_list_answer_records_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_answer_records_rest_interceptors(null_interceptor): transport = transports.AnswerRecordsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AnswerRecordsRestInterceptor(), @@ -1801,7 +2221,7 @@ def test_list_answer_records_rest_bad_request( transport: str = "rest", request_type=answer_record.ListAnswerRecordsRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1823,7 +2243,7 @@ def test_list_answer_records_rest_bad_request( def test_list_answer_records_rest_flattened(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1864,7 +2284,7 @@ def test_list_answer_records_rest_flattened(): def test_list_answer_records_rest_flattened_error(transport: str = "rest"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1879,7 +2299,7 @@ def test_list_answer_records_rest_flattened_error(transport: str = "rest"): def test_list_answer_records_rest_pager(transport: str = "rest"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1949,7 +2369,7 @@ def test_list_answer_records_rest_pager(transport: str = "rest"): ) def test_update_answer_record_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2378,14 +2798,14 @@ def test_update_answer_record_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_answer_record._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_answer_record._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -2394,7 +2814,7 @@ def test_update_answer_record_rest_required_fields( # verify required fields with non-default values are left alone client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2437,7 +2857,7 @@ def test_update_answer_record_rest_required_fields( def test_update_answer_record_rest_unset_required_fields(): transport = transports.AnswerRecordsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_answer_record._get_unset_required_fields({}) @@ -2447,7 +2867,7 @@ def test_update_answer_record_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_answer_record_rest_interceptors(null_interceptor): transport = transports.AnswerRecordsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AnswerRecordsRestInterceptor(), @@ -2505,7 +2925,7 @@ def test_update_answer_record_rest_bad_request( transport: str = "rest", request_type=gcd_answer_record.UpdateAnswerRecordRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2527,7 +2947,7 @@ def test_update_answer_record_rest_bad_request( def test_update_answer_record_rest_flattened(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2572,7 +2992,7 @@ def test_update_answer_record_rest_flattened(): def test_update_answer_record_rest_flattened_error(transport: str = "rest"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2588,24 +3008,24 @@ def test_update_answer_record_rest_flattened_error(transport: str = "rest"): def test_update_answer_record_rest_error(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AnswerRecordsClient( @@ -2615,7 +3035,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -2626,16 +3046,17 @@ 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 = AnswerRecordsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AnswerRecordsClient( @@ -2647,7 +3068,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = AnswerRecordsClient(transport=transport) assert client.transport is transport @@ -2656,13 +3077,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AnswerRecordsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.AnswerRecordsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -2679,7 +3100,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -2693,7 +3114,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = AnswerRecordsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -2701,7 +3122,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -2713,7 +3134,7 @@ def test_answer_records_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.AnswerRecordsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -2725,7 +3146,7 @@ def test_answer_records_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AnswerRecordsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -2764,7 +3185,7 @@ def test_answer_records_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AnswerRecordsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2786,7 +3207,7 @@ def test_answer_records_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.answer_records.transports.AnswerRecordsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AnswerRecordsTransport() adc.assert_called_once() @@ -2794,7 +3215,7 @@ def test_answer_records_base_transport_with_adc(): def test_answer_records_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) AnswerRecordsClient() adc.assert_called_once_with( scopes=None, @@ -2817,7 +3238,7 @@ def test_answer_records_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2867,7 +3288,7 @@ def test_answer_records_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2898,7 +3319,7 @@ def test_answer_records_transport_create_channel(transport_class, grpc_helpers): ], ) def test_answer_records_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2936,7 +3357,7 @@ def test_answer_records_grpc_transport_client_cert_source_for_mtls(transport_cla def test_answer_records_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -2956,7 +3377,7 @@ def test_answer_records_http_transport_client_cert_source_for_mtls(): ) def test_answer_records_host_no_port(transport_name): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -2979,7 +3400,7 @@ def test_answer_records_host_no_port(transport_name): ) def test_answer_records_host_with_port(transport_name): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -2999,8 +3420,8 @@ def test_answer_records_host_with_port(transport_name): ], ) def test_answer_records_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = AnswerRecordsClient( credentials=creds1, transport=transport_name, @@ -3068,7 +3489,7 @@ def test_answer_records_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -3352,7 +3773,7 @@ def test_client_with_default_client_info(): transports.AnswerRecordsTransport, "_prep_wrapped_messages" ) as prep: client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3362,7 +3783,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = AnswerRecordsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3371,7 +3792,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -3386,7 +3807,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3416,7 +3837,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -3444,7 +3865,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3472,7 +3893,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -3500,7 +3921,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3530,7 +3951,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -3558,7 +3979,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3588,7 +4009,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -3616,7 +4037,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3644,7 +4065,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -3670,7 +4091,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3695,7 +4116,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3719,7 +4140,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3748,7 +4169,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3775,7 +4196,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -3793,7 +4214,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -3809,7 +4230,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3834,7 +4255,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3860,7 +4281,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3889,7 +4310,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3918,7 +4339,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3936,7 +4357,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3954,7 +4375,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3979,7 +4400,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4005,7 +4426,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4034,7 +4455,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4063,7 +4484,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -4081,7 +4502,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -4099,7 +4520,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4124,7 +4545,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4150,7 +4571,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4179,7 +4600,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4208,7 +4629,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -4226,7 +4647,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -4244,7 +4665,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4269,7 +4690,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4294,7 +4715,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = AnswerRecordsClient(credentials=ga_credentials.AnonymousCredentials()) + client = AnswerRecordsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -4321,7 +4742,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = AnswerRecordsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = AnswerRecordsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -4349,7 +4772,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -4367,7 +4790,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = AnswerRecordsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -4391,7 +4814,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -4408,7 +4831,7 @@ def test_client_ctx(): ] for transport in transports: client = AnswerRecordsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -4439,7 +4862,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py index cce429086ca4..2288b8d7ab5e 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_contexts.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -71,6 +71,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -95,6 +118,244 @@ def test__get_default_mtls_endpoint(): assert ContextsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert ContextsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ContextsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ContextsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ContextsClient._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 ContextsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ContextsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ContextsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ContextsClient._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 ContextsClient._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 ContextsClient._get_client_cert_source(None, False) is None + assert ( + ContextsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + ContextsClient._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 ( + ContextsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ContextsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ContextsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsClient), +) +@mock.patch.object( + ContextsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ContextsClient._DEFAULT_UNIVERSE + default_endpoint = ContextsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ContextsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ContextsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ContextsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ContextsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ContextsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + ContextsClient._get_api_endpoint(None, None, default_universe, "always") + == ContextsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ContextsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ContextsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ContextsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ContextsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ContextsClient._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 ( + ContextsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + ContextsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ContextsClient._get_universe_domain(None, None) + == ContextsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ContextsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (ContextsClient, transports.ContextsGrpcTransport, "grpc"), + (ContextsClient, transports.ContextsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -104,7 +365,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_contexts_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -156,7 +417,7 @@ def test_contexts_client_service_account_always_use_jwt( ], ) def test_contexts_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -201,17 +462,21 @@ def test_contexts_client_get_transport_class(): ], ) @mock.patch.object( - ContextsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ContextsClient) + ContextsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsClient), ) @mock.patch.object( ContextsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ContextsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsAsyncClient), ) def test_contexts_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(ContextsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -246,7 +511,9 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -276,15 +543,23 @@ def test_contexts_client_client_options(client_class, transport_class, transport # 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") @@ -294,7 +569,9 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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", @@ -312,7 +589,9 @@ def test_contexts_client_client_options(client_class, transport_class, transport 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, @@ -344,12 +623,14 @@ def test_contexts_client_client_options(client_class, transport_class, transport ], ) @mock.patch.object( - ContextsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ContextsClient) + ContextsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsClient), ) @mock.patch.object( ContextsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ContextsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_contexts_client_mtls_env_auto( @@ -372,7 +653,9 @@ def test_contexts_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 @@ -404,7 +687,9 @@ def test_contexts_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 @@ -438,7 +723,9 @@ def test_contexts_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, @@ -524,6 +811,116 @@ def test_contexts_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", [ContextsClient, ContextsAsyncClient]) +@mock.patch.object( + ContextsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsClient), +) +@mock.patch.object( + ContextsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ContextsAsyncClient), +) +def test_contexts_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ContextsClient._DEFAULT_UNIVERSE + default_endpoint = ContextsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ContextsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -546,7 +943,9 @@ def test_contexts_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, @@ -581,7 +980,9 @@ def test_contexts_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, @@ -634,7 +1035,9 @@ def test_contexts_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, @@ -651,8 +1054,8 @@ def test_contexts_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -684,7 +1087,7 @@ def test_contexts_client_create_channel_credentials_file( ) def test_list_contexts(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -714,7 +1117,7 @@ def test_list_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -731,7 +1134,7 @@ async def test_list_contexts_async( transport: str = "grpc_asyncio", request_type=context.ListContextsRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -766,7 +1169,7 @@ async def test_list_contexts_async_from_dict(): def test_list_contexts_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -796,7 +1199,7 @@ def test_list_contexts_field_headers(): @pytest.mark.asyncio async def test_list_contexts_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -827,7 +1230,7 @@ async def test_list_contexts_field_headers_async(): def test_list_contexts_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -851,7 +1254,7 @@ def test_list_contexts_flattened(): def test_list_contexts_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -866,7 +1269,7 @@ def test_list_contexts_flattened_error(): @pytest.mark.asyncio async def test_list_contexts_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -895,7 +1298,7 @@ async def test_list_contexts_flattened_async(): @pytest.mark.asyncio async def test_list_contexts_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -909,7 +1312,7 @@ async def test_list_contexts_flattened_error_async(): def test_list_contexts_pager(transport_name: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -959,7 +1362,7 @@ def test_list_contexts_pager(transport_name: str = "grpc"): def test_list_contexts_pages(transport_name: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1001,7 +1404,7 @@ def test_list_contexts_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_contexts_async_pager(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1051,7 +1454,7 @@ async def test_list_contexts_async_pager(): @pytest.mark.asyncio async def test_list_contexts_async_pages(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1106,7 +1509,7 @@ async def test_list_contexts_async_pages(): ) def test_get_context(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1138,7 +1541,7 @@ def test_get_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1155,7 +1558,7 @@ async def test_get_context_async( transport: str = "grpc_asyncio", request_type=context.GetContextRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1192,7 +1595,7 @@ async def test_get_context_async_from_dict(): def test_get_context_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1222,7 +1625,7 @@ def test_get_context_field_headers(): @pytest.mark.asyncio async def test_get_context_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1251,7 +1654,7 @@ async def test_get_context_field_headers_async(): def test_get_context_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1275,7 +1678,7 @@ def test_get_context_flattened(): def test_get_context_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1290,7 +1693,7 @@ def test_get_context_flattened_error(): @pytest.mark.asyncio async def test_get_context_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1317,7 +1720,7 @@ async def test_get_context_flattened_async(): @pytest.mark.asyncio async def test_get_context_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1338,7 +1741,7 @@ async def test_get_context_flattened_error_async(): ) def test_create_context(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1370,7 +1773,7 @@ def test_create_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1387,7 +1790,7 @@ async def test_create_context_async( transport: str = "grpc_asyncio", request_type=gcd_context.CreateContextRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1424,7 +1827,7 @@ async def test_create_context_async_from_dict(): def test_create_context_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1454,7 +1857,7 @@ def test_create_context_field_headers(): @pytest.mark.asyncio async def test_create_context_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1483,7 +1886,7 @@ async def test_create_context_field_headers_async(): def test_create_context_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1511,7 +1914,7 @@ def test_create_context_flattened(): def test_create_context_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1527,7 +1930,7 @@ def test_create_context_flattened_error(): @pytest.mark.asyncio async def test_create_context_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1558,7 +1961,7 @@ async def test_create_context_flattened_async(): @pytest.mark.asyncio async def test_create_context_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1580,7 +1983,7 @@ async def test_create_context_flattened_error_async(): ) def test_update_context(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1612,7 +2015,7 @@ def test_update_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1629,7 +2032,7 @@ async def test_update_context_async( transport: str = "grpc_asyncio", request_type=gcd_context.UpdateContextRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1666,7 +2069,7 @@ async def test_update_context_async_from_dict(): def test_update_context_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1696,7 +2099,7 @@ def test_update_context_field_headers(): @pytest.mark.asyncio async def test_update_context_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1725,7 +2128,7 @@ async def test_update_context_field_headers_async(): def test_update_context_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1753,7 +2156,7 @@ def test_update_context_flattened(): def test_update_context_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1769,7 +2172,7 @@ def test_update_context_flattened_error(): @pytest.mark.asyncio async def test_update_context_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1800,7 +2203,7 @@ async def test_update_context_flattened_async(): @pytest.mark.asyncio async def test_update_context_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1822,7 +2225,7 @@ async def test_update_context_flattened_error_async(): ) def test_delete_context(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1849,7 +2252,7 @@ def test_delete_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1866,7 +2269,7 @@ async def test_delete_context_async( transport: str = "grpc_asyncio", request_type=context.DeleteContextRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1896,7 +2299,7 @@ async def test_delete_context_async_from_dict(): def test_delete_context_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1926,7 +2329,7 @@ def test_delete_context_field_headers(): @pytest.mark.asyncio async def test_delete_context_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1955,7 +2358,7 @@ async def test_delete_context_field_headers_async(): def test_delete_context_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1979,7 +2382,7 @@ def test_delete_context_flattened(): def test_delete_context_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1994,7 +2397,7 @@ def test_delete_context_flattened_error(): @pytest.mark.asyncio async def test_delete_context_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2021,7 +2424,7 @@ async def test_delete_context_flattened_async(): @pytest.mark.asyncio async def test_delete_context_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2042,7 +2445,7 @@ async def test_delete_context_flattened_error_async(): ) def test_delete_all_contexts(request_type, transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2071,7 +2474,7 @@ def test_delete_all_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2090,7 +2493,7 @@ async def test_delete_all_contexts_async( transport: str = "grpc_asyncio", request_type=context.DeleteAllContextsRequest ): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2122,7 +2525,7 @@ async def test_delete_all_contexts_async_from_dict(): def test_delete_all_contexts_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2154,7 +2557,7 @@ def test_delete_all_contexts_field_headers(): @pytest.mark.asyncio async def test_delete_all_contexts_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2185,7 +2588,7 @@ async def test_delete_all_contexts_field_headers_async(): def test_delete_all_contexts_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2211,7 +2614,7 @@ def test_delete_all_contexts_flattened(): def test_delete_all_contexts_flattened_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2226,7 +2629,7 @@ def test_delete_all_contexts_flattened_error(): @pytest.mark.asyncio async def test_delete_all_contexts_flattened_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2255,7 +2658,7 @@ async def test_delete_all_contexts_flattened_async(): @pytest.mark.asyncio async def test_delete_all_contexts_flattened_error_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2276,7 +2679,7 @@ async def test_delete_all_contexts_flattened_error_async(): ) def test_list_contexts_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2325,7 +2728,7 @@ def test_list_contexts_rest_required_fields(request_type=context.ListContextsReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_contexts._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2334,7 +2737,7 @@ def test_list_contexts_rest_required_fields(request_type=context.ListContextsReq jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_contexts._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2350,7 +2753,7 @@ def test_list_contexts_rest_required_fields(request_type=context.ListContextsReq assert jsonified_request["parent"] == "parent_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2392,7 +2795,7 @@ def test_list_contexts_rest_required_fields(request_type=context.ListContextsReq def test_list_contexts_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_contexts._get_unset_required_fields({}) @@ -2410,7 +2813,7 @@ def test_list_contexts_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_contexts_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -2464,7 +2867,7 @@ def test_list_contexts_rest_bad_request( transport: str = "rest", request_type=context.ListContextsRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2486,7 +2889,7 @@ def test_list_contexts_rest_bad_request( def test_list_contexts_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2528,7 +2931,7 @@ def test_list_contexts_rest_flattened(): def test_list_contexts_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2543,7 +2946,7 @@ def test_list_contexts_rest_flattened_error(transport: str = "rest"): def test_list_contexts_rest_pager(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2611,7 +3014,7 @@ def test_list_contexts_rest_pager(transport: str = "rest"): ) def test_get_context_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2662,7 +3065,7 @@ def test_get_context_rest_required_fields(request_type=context.GetContextRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2671,7 +3074,7 @@ def test_get_context_rest_required_fields(request_type=context.GetContextRequest jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2680,7 +3083,7 @@ def test_get_context_rest_required_fields(request_type=context.GetContextRequest assert jsonified_request["name"] == "name_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2722,7 +3125,7 @@ def test_get_context_rest_required_fields(request_type=context.GetContextRequest def test_get_context_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_context._get_unset_required_fields({}) @@ -2732,7 +3135,7 @@ def test_get_context_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_context_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -2784,7 +3187,7 @@ def test_get_context_rest_bad_request( transport: str = "rest", request_type=context.GetContextRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2806,7 +3209,7 @@ def test_get_context_rest_bad_request( def test_get_context_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2850,7 +3253,7 @@ def test_get_context_rest_flattened(): def test_get_context_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2865,7 +3268,7 @@ def test_get_context_rest_flattened_error(transport: str = "rest"): def test_get_context_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2878,7 +3281,7 @@ def test_get_context_rest_error(): ) def test_create_context_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3003,7 +3406,7 @@ def test_create_context_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3012,7 +3415,7 @@ def test_create_context_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3021,7 +3424,7 @@ def test_create_context_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3064,7 +3467,7 @@ def test_create_context_rest_required_fields( def test_create_context_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_context._get_unset_required_fields({}) @@ -3082,7 +3485,7 @@ def test_create_context_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_context_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -3136,7 +3539,7 @@ def test_create_context_rest_bad_request( transport: str = "rest", request_type=gcd_context.CreateContextRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3158,7 +3561,7 @@ def test_create_context_rest_bad_request( def test_create_context_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3201,7 +3604,7 @@ def test_create_context_rest_flattened(): def test_create_context_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3217,7 +3620,7 @@ def test_create_context_rest_flattened_error(transport: str = "rest"): def test_create_context_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3230,7 +3633,7 @@ def test_create_context_rest_error(): ) def test_update_context_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3356,14 +3759,14 @@ def test_update_context_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_context._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3372,7 +3775,7 @@ def test_update_context_rest_required_fields( # verify required fields with non-default values are left alone client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3415,7 +3818,7 @@ def test_update_context_rest_required_fields( def test_update_context_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_context._get_unset_required_fields({}) @@ -3425,7 +3828,7 @@ def test_update_context_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_context_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -3479,7 +3882,7 @@ def test_update_context_rest_bad_request( transport: str = "rest", request_type=gcd_context.UpdateContextRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3503,7 +3906,7 @@ def test_update_context_rest_bad_request( def test_update_context_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3550,7 +3953,7 @@ def test_update_context_rest_flattened(): def test_update_context_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3566,7 +3969,7 @@ def test_update_context_rest_flattened_error(transport: str = "rest"): def test_update_context_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3579,7 +3982,7 @@ def test_update_context_rest_error(): ) def test_delete_context_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3623,7 +4026,7 @@ def test_delete_context_rest_required_fields(request_type=context.DeleteContextR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3632,7 +4035,7 @@ def test_delete_context_rest_required_fields(request_type=context.DeleteContextR jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_context._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3641,7 +4044,7 @@ def test_delete_context_rest_required_fields(request_type=context.DeleteContextR assert jsonified_request["name"] == "name_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3680,7 +4083,7 @@ def test_delete_context_rest_required_fields(request_type=context.DeleteContextR def test_delete_context_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_context._get_unset_required_fields({}) @@ -3690,7 +4093,7 @@ def test_delete_context_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_context_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -3736,7 +4139,7 @@ def test_delete_context_rest_bad_request( transport: str = "rest", request_type=context.DeleteContextRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3758,7 +4161,7 @@ def test_delete_context_rest_bad_request( def test_delete_context_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3800,7 +4203,7 @@ def test_delete_context_rest_flattened(): def test_delete_context_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3815,7 +4218,7 @@ def test_delete_context_rest_flattened_error(transport: str = "rest"): def test_delete_context_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3828,7 +4231,7 @@ def test_delete_context_rest_error(): ) def test_delete_all_contexts_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3874,7 +4277,7 @@ def test_delete_all_contexts_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_all_contexts._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3883,7 +4286,7 @@ def test_delete_all_contexts_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_all_contexts._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3892,7 +4295,7 @@ def test_delete_all_contexts_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3931,7 +4334,7 @@ def test_delete_all_contexts_rest_required_fields( def test_delete_all_contexts_rest_unset_required_fields(): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_all_contexts._get_unset_required_fields({}) @@ -3941,7 +4344,7 @@ def test_delete_all_contexts_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_all_contexts_rest_interceptors(null_interceptor): transport = transports.ContextsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ContextsRestInterceptor(), ) client = ContextsClient(transport=transport) @@ -3989,7 +4392,7 @@ def test_delete_all_contexts_rest_bad_request( transport: str = "rest", request_type=context.DeleteAllContextsRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4011,7 +4414,7 @@ def test_delete_all_contexts_rest_bad_request( def test_delete_all_contexts_rest_flattened(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4051,7 +4454,7 @@ def test_delete_all_contexts_rest_flattened(): def test_delete_all_contexts_rest_flattened_error(transport: str = "rest"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4066,24 +4469,24 @@ def test_delete_all_contexts_rest_flattened_error(transport: str = "rest"): def test_delete_all_contexts_rest_error(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ContextsClient( @@ -4093,7 +4496,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4104,16 +4507,17 @@ 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 = ContextsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ContextsClient( @@ -4125,7 +4529,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ContextsClient(transport=transport) assert client.transport is transport @@ -4134,13 +4538,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ContextsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ContextsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4157,7 +4561,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4171,7 +4575,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ContextsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4179,7 +4583,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4191,7 +4595,7 @@ def test_contexts_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ContextsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4203,7 +4607,7 @@ def test_contexts_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ContextsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4245,7 +4649,7 @@ def test_contexts_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.contexts.transports.ContextsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ContextsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4267,7 +4671,7 @@ def test_contexts_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.contexts.transports.ContextsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ContextsTransport() adc.assert_called_once() @@ -4275,7 +4679,7 @@ def test_contexts_base_transport_with_adc(): def test_contexts_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ContextsClient() adc.assert_called_once_with( scopes=None, @@ -4298,7 +4702,7 @@ def test_contexts_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4348,7 +4752,7 @@ def test_contexts_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4376,7 +4780,7 @@ def test_contexts_transport_create_channel(transport_class, grpc_helpers): [transports.ContextsGrpcTransport, transports.ContextsGrpcAsyncIOTransport], ) def test_contexts_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4414,7 +4818,7 @@ def test_contexts_grpc_transport_client_cert_source_for_mtls(transport_class): def test_contexts_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4434,7 +4838,7 @@ def test_contexts_http_transport_client_cert_source_for_mtls(): ) def test_contexts_host_no_port(transport_name): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4457,7 +4861,7 @@ def test_contexts_host_no_port(transport_name): ) def test_contexts_host_with_port(transport_name): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4477,8 +4881,8 @@ def test_contexts_host_with_port(transport_name): ], ) def test_contexts_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ContextsClient( credentials=creds1, transport=transport_name, @@ -4552,7 +4956,7 @@ def test_contexts_transport_channel_mtls_with_client_cert_source(transport_class mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4761,7 +5165,7 @@ def test_client_with_default_client_info(): transports.ContextsTransport, "_prep_wrapped_messages" ) as prep: client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4771,7 +5175,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ContextsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4780,7 +5184,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4795,7 +5199,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4825,7 +5229,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4853,7 +5257,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4881,7 +5285,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4909,7 +5313,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4939,7 +5343,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4967,7 +5371,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4997,7 +5401,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -5025,7 +5429,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5053,7 +5457,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -5079,7 +5483,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5104,7 +5508,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5128,7 +5532,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5157,7 +5561,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5184,7 +5588,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5202,7 +5606,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5218,7 +5622,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5243,7 +5647,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5269,7 +5673,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5298,7 +5702,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5327,7 +5731,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5345,7 +5749,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5363,7 +5767,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5388,7 +5792,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5414,7 +5818,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5443,7 +5847,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5472,7 +5876,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5490,7 +5894,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5508,7 +5912,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5533,7 +5937,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5559,7 +5963,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5588,7 +5992,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5617,7 +6021,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5635,7 +6039,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5653,7 +6057,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5678,7 +6082,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5703,7 +6107,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = ContextsClient(credentials=ga_credentials.AnonymousCredentials()) + client = ContextsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5730,7 +6134,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = ContextsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = ContextsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5758,7 +6162,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5776,7 +6180,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ContextsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5800,7 +6204,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5817,7 +6221,7 @@ def test_client_ctx(): ] for transport in transports: client = ContextsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5848,7 +6252,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py index 0620079e72b2..6292da2a3db5 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversation_profiles.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -85,6 +85,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -115,6 +138,289 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert ConversationProfilesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ConversationProfilesClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ConversationProfilesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ConversationProfilesClient._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 ConversationProfilesClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ConversationProfilesClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ConversationProfilesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationProfilesClient._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 ConversationProfilesClient._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 ConversationProfilesClient._get_client_cert_source(None, False) is None + assert ( + ConversationProfilesClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + ConversationProfilesClient._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 ( + ConversationProfilesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ConversationProfilesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ConversationProfilesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesClient), +) +@mock.patch.object( + ConversationProfilesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ConversationProfilesClient._DEFAULT_UNIVERSE + default_endpoint = ConversationProfilesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationProfilesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ConversationProfilesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ConversationProfilesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationProfilesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ConversationProfilesClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationProfilesClient._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 ( + ConversationProfilesClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ConversationProfilesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ConversationProfilesClient._get_universe_domain(None, None) + == ConversationProfilesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ConversationProfilesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + ConversationProfilesClient, + transports.ConversationProfilesGrpcTransport, + "grpc", + ), + ( + ConversationProfilesClient, + transports.ConversationProfilesRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -126,7 +432,7 @@ def test__get_default_mtls_endpoint(): def test_conversation_profiles_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -180,7 +486,7 @@ def test_conversation_profiles_client_service_account_always_use_jwt( def test_conversation_profiles_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -238,20 +544,22 @@ def test_conversation_profiles_client_get_transport_class(): ) @mock.patch.object( ConversationProfilesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationProfilesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesClient), ) @mock.patch.object( ConversationProfilesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationProfilesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesAsyncClient), ) def test_conversation_profiles_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ConversationProfilesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -286,7 +594,9 @@ def test_conversation_profiles_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, @@ -316,15 +626,23 @@ def test_conversation_profiles_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") @@ -334,7 +652,9 @@ def test_conversation_profiles_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", @@ -352,7 +672,9 @@ def test_conversation_profiles_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, @@ -405,13 +727,13 @@ def test_conversation_profiles_client_client_options( ) @mock.patch.object( ConversationProfilesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationProfilesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesClient), ) @mock.patch.object( ConversationProfilesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationProfilesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_conversation_profiles_client_mtls_env_auto( @@ -434,7 +756,9 @@ def test_conversation_profiles_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 @@ -466,7 +790,9 @@ def test_conversation_profiles_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 @@ -500,7 +826,9 @@ def test_conversation_profiles_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, @@ -590,6 +918,118 @@ def test_conversation_profiles_client_get_mtls_endpoint_and_cert_source(client_c 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", [ConversationProfilesClient, ConversationProfilesAsyncClient] +) +@mock.patch.object( + ConversationProfilesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesClient), +) +@mock.patch.object( + ConversationProfilesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationProfilesAsyncClient), +) +def test_conversation_profiles_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ConversationProfilesClient._DEFAULT_UNIVERSE + default_endpoint = ConversationProfilesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationProfilesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -624,7 +1064,9 @@ def test_conversation_profiles_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, @@ -669,7 +1111,9 @@ def test_conversation_profiles_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, @@ -729,7 +1173,9 @@ def test_conversation_profiles_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, @@ -746,8 +1192,8 @@ def test_conversation_profiles_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -779,7 +1225,7 @@ def test_conversation_profiles_client_create_channel_credentials_file( ) def test_list_conversation_profiles(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -811,7 +1257,7 @@ def test_list_conversation_profiles_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -831,7 +1277,7 @@ async def test_list_conversation_profiles_async( request_type=conversation_profile.ListConversationProfilesRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -868,7 +1314,7 @@ async def test_list_conversation_profiles_async_from_dict(): def test_list_conversation_profiles_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -900,7 +1346,7 @@ def test_list_conversation_profiles_field_headers(): @pytest.mark.asyncio async def test_list_conversation_profiles_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -933,7 +1379,7 @@ async def test_list_conversation_profiles_field_headers_async(): def test_list_conversation_profiles_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -959,7 +1405,7 @@ def test_list_conversation_profiles_flattened(): def test_list_conversation_profiles_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -974,7 +1420,7 @@ def test_list_conversation_profiles_flattened_error(): @pytest.mark.asyncio async def test_list_conversation_profiles_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1005,7 +1451,7 @@ async def test_list_conversation_profiles_flattened_async(): @pytest.mark.asyncio async def test_list_conversation_profiles_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1019,7 +1465,7 @@ async def test_list_conversation_profiles_flattened_error_async(): def test_list_conversation_profiles_pager(transport_name: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1073,7 +1519,7 @@ def test_list_conversation_profiles_pager(transport_name: str = "grpc"): def test_list_conversation_profiles_pages(transport_name: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1117,7 +1563,7 @@ def test_list_conversation_profiles_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversation_profiles_async_pager(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1171,7 +1617,7 @@ async def test_list_conversation_profiles_async_pager(): @pytest.mark.asyncio async def test_list_conversation_profiles_async_pages(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1228,7 +1674,7 @@ async def test_list_conversation_profiles_async_pages(): ) def test_get_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1268,7 +1714,7 @@ def test_get_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1288,7 +1734,7 @@ async def test_get_conversation_profile_async( request_type=conversation_profile.GetConversationProfileRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1333,7 +1779,7 @@ async def test_get_conversation_profile_async_from_dict(): def test_get_conversation_profile_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1365,7 +1811,7 @@ def test_get_conversation_profile_field_headers(): @pytest.mark.asyncio async def test_get_conversation_profile_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1398,7 +1844,7 @@ async def test_get_conversation_profile_field_headers_async(): def test_get_conversation_profile_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1424,7 +1870,7 @@ def test_get_conversation_profile_flattened(): def test_get_conversation_profile_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1439,7 +1885,7 @@ def test_get_conversation_profile_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_profile_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1470,7 +1916,7 @@ async def test_get_conversation_profile_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_profile_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1491,7 +1937,7 @@ async def test_get_conversation_profile_flattened_error_async(): ) def test_create_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1531,7 +1977,7 @@ def test_create_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1551,7 +1997,7 @@ async def test_create_conversation_profile_async( request_type=gcd_conversation_profile.CreateConversationProfileRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1596,7 +2042,7 @@ async def test_create_conversation_profile_async_from_dict(): def test_create_conversation_profile_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1628,7 +2074,7 @@ def test_create_conversation_profile_field_headers(): @pytest.mark.asyncio async def test_create_conversation_profile_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1661,7 +2107,7 @@ async def test_create_conversation_profile_field_headers_async(): def test_create_conversation_profile_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1693,7 +2139,7 @@ def test_create_conversation_profile_flattened(): def test_create_conversation_profile_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1711,7 +2157,7 @@ def test_create_conversation_profile_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_profile_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1748,7 +2194,7 @@ async def test_create_conversation_profile_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_profile_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1772,7 +2218,7 @@ async def test_create_conversation_profile_flattened_error_async(): ) def test_update_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1812,7 +2258,7 @@ def test_update_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1832,7 +2278,7 @@ async def test_update_conversation_profile_async( request_type=gcd_conversation_profile.UpdateConversationProfileRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1877,7 +2323,7 @@ async def test_update_conversation_profile_async_from_dict(): def test_update_conversation_profile_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1909,7 +2355,7 @@ def test_update_conversation_profile_field_headers(): @pytest.mark.asyncio async def test_update_conversation_profile_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1942,7 +2388,7 @@ async def test_update_conversation_profile_field_headers_async(): def test_update_conversation_profile_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1974,7 +2420,7 @@ def test_update_conversation_profile_flattened(): def test_update_conversation_profile_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1992,7 +2438,7 @@ def test_update_conversation_profile_flattened_error(): @pytest.mark.asyncio async def test_update_conversation_profile_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2029,7 +2475,7 @@ async def test_update_conversation_profile_flattened_async(): @pytest.mark.asyncio async def test_update_conversation_profile_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2053,7 +2499,7 @@ async def test_update_conversation_profile_flattened_error_async(): ) def test_delete_conversation_profile(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2082,7 +2528,7 @@ def test_delete_conversation_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2102,7 +2548,7 @@ async def test_delete_conversation_profile_async( request_type=conversation_profile.DeleteConversationProfileRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2134,7 +2580,7 @@ async def test_delete_conversation_profile_async_from_dict(): def test_delete_conversation_profile_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2166,7 +2612,7 @@ def test_delete_conversation_profile_field_headers(): @pytest.mark.asyncio async def test_delete_conversation_profile_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2197,7 +2643,7 @@ async def test_delete_conversation_profile_field_headers_async(): def test_delete_conversation_profile_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2223,7 +2669,7 @@ def test_delete_conversation_profile_flattened(): def test_delete_conversation_profile_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2238,7 +2684,7 @@ def test_delete_conversation_profile_flattened_error(): @pytest.mark.asyncio async def test_delete_conversation_profile_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2267,7 +2713,7 @@ async def test_delete_conversation_profile_flattened_async(): @pytest.mark.asyncio async def test_delete_conversation_profile_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2288,7 +2734,7 @@ async def test_delete_conversation_profile_flattened_error_async(): ) def test_set_suggestion_feature_config(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2317,7 +2763,7 @@ def test_set_suggestion_feature_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2337,7 +2783,7 @@ async def test_set_suggestion_feature_config_async( request_type=gcd_conversation_profile.SetSuggestionFeatureConfigRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2371,7 +2817,7 @@ async def test_set_suggestion_feature_config_async_from_dict(): def test_set_suggestion_feature_config_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2403,7 +2849,7 @@ def test_set_suggestion_feature_config_field_headers(): @pytest.mark.asyncio async def test_set_suggestion_feature_config_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2436,7 +2882,7 @@ async def test_set_suggestion_feature_config_field_headers_async(): def test_set_suggestion_feature_config_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2480,7 +2926,7 @@ def test_set_suggestion_feature_config_flattened(): def test_set_suggestion_feature_config_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2501,7 +2947,7 @@ def test_set_suggestion_feature_config_flattened_error(): @pytest.mark.asyncio async def test_set_suggestion_feature_config_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2550,7 +2996,7 @@ async def test_set_suggestion_feature_config_flattened_async(): @pytest.mark.asyncio async def test_set_suggestion_feature_config_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2577,7 +3023,7 @@ async def test_set_suggestion_feature_config_flattened_error_async(): ) def test_clear_suggestion_feature_config(request_type, transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2606,7 +3052,7 @@ def test_clear_suggestion_feature_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2626,7 +3072,7 @@ async def test_clear_suggestion_feature_config_async( request_type=gcd_conversation_profile.ClearSuggestionFeatureConfigRequest, ): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2660,7 +3106,7 @@ async def test_clear_suggestion_feature_config_async_from_dict(): def test_clear_suggestion_feature_config_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2692,7 +3138,7 @@ def test_clear_suggestion_feature_config_field_headers(): @pytest.mark.asyncio async def test_clear_suggestion_feature_config_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2725,7 +3171,7 @@ async def test_clear_suggestion_feature_config_field_headers_async(): def test_clear_suggestion_feature_config_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2759,7 +3205,7 @@ def test_clear_suggestion_feature_config_flattened(): def test_clear_suggestion_feature_config_flattened_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2776,7 +3222,7 @@ def test_clear_suggestion_feature_config_flattened_error(): @pytest.mark.asyncio async def test_clear_suggestion_feature_config_flattened_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2815,7 +3261,7 @@ async def test_clear_suggestion_feature_config_flattened_async(): @pytest.mark.asyncio async def test_clear_suggestion_feature_config_flattened_error_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2838,7 +3284,7 @@ async def test_clear_suggestion_feature_config_flattened_error_async(): ) def test_list_conversation_profiles_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2891,7 +3337,7 @@ def test_list_conversation_profiles_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_profiles._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2900,7 +3346,7 @@ def test_list_conversation_profiles_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversation_profiles._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2916,7 +3362,7 @@ def test_list_conversation_profiles_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2960,7 +3406,7 @@ def test_list_conversation_profiles_rest_required_fields( def test_list_conversation_profiles_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_conversation_profiles._get_unset_required_fields({}) @@ -2978,7 +3424,7 @@ def test_list_conversation_profiles_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversation_profiles_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -3040,7 +3486,7 @@ def test_list_conversation_profiles_rest_bad_request( request_type=conversation_profile.ListConversationProfilesRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3062,7 +3508,7 @@ def test_list_conversation_profiles_rest_bad_request( def test_list_conversation_profiles_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3106,7 +3552,7 @@ def test_list_conversation_profiles_rest_flattened(): def test_list_conversation_profiles_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3121,7 +3567,7 @@ def test_list_conversation_profiles_rest_flattened_error(transport: str = "rest" def test_list_conversation_profiles_rest_pager(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3194,7 +3640,7 @@ def test_list_conversation_profiles_rest_pager(transport: str = "rest"): ) def test_get_conversation_profile_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3253,7 +3699,7 @@ def test_get_conversation_profile_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3262,7 +3708,7 @@ def test_get_conversation_profile_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3271,7 +3717,7 @@ def test_get_conversation_profile_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3313,7 +3759,7 @@ def test_get_conversation_profile_rest_required_fields( def test_get_conversation_profile_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_conversation_profile._get_unset_required_fields({}) @@ -3323,7 +3769,7 @@ def test_get_conversation_profile_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_profile_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -3382,7 +3828,7 @@ def test_get_conversation_profile_rest_bad_request( request_type=conversation_profile.GetConversationProfileRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3404,7 +3850,7 @@ def test_get_conversation_profile_rest_bad_request( def test_get_conversation_profile_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3446,7 +3892,7 @@ def test_get_conversation_profile_rest_flattened(): def test_get_conversation_profile_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3461,7 +3907,7 @@ def test_get_conversation_profile_rest_flattened_error(transport: str = "rest"): def test_get_conversation_profile_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3474,7 +3920,7 @@ def test_get_conversation_profile_rest_error(): ) def test_create_conversation_profile_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3695,7 +4141,7 @@ def test_create_conversation_profile_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3704,7 +4150,7 @@ def test_create_conversation_profile_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3713,7 +4159,7 @@ def test_create_conversation_profile_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3756,7 +4202,7 @@ def test_create_conversation_profile_rest_required_fields( def test_create_conversation_profile_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_conversation_profile._get_unset_required_fields({}) @@ -3774,7 +4220,7 @@ def test_create_conversation_profile_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_profile_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -3837,7 +4283,7 @@ def test_create_conversation_profile_rest_bad_request( request_type=gcd_conversation_profile.CreateConversationProfileRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3859,7 +4305,7 @@ def test_create_conversation_profile_rest_bad_request( def test_create_conversation_profile_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3904,7 +4350,7 @@ def test_create_conversation_profile_rest_flattened(): def test_create_conversation_profile_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3922,7 +4368,7 @@ def test_create_conversation_profile_rest_flattened_error(transport: str = "rest def test_create_conversation_profile_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3935,7 +4381,7 @@ def test_create_conversation_profile_rest_error(): ) def test_update_conversation_profile_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4159,14 +4605,14 @@ def test_update_conversation_profile_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation_profile._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -4175,7 +4621,7 @@ def test_update_conversation_profile_rest_required_fields( # verify required fields with non-default values are left alone client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4218,7 +4664,7 @@ def test_update_conversation_profile_rest_required_fields( def test_update_conversation_profile_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_conversation_profile._get_unset_required_fields({}) @@ -4236,7 +4682,7 @@ def test_update_conversation_profile_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_conversation_profile_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -4299,7 +4745,7 @@ def test_update_conversation_profile_rest_bad_request( request_type=gcd_conversation_profile.UpdateConversationProfileRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4325,7 +4771,7 @@ def test_update_conversation_profile_rest_bad_request( def test_update_conversation_profile_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4374,7 +4820,7 @@ def test_update_conversation_profile_rest_flattened(): def test_update_conversation_profile_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4392,7 +4838,7 @@ def test_update_conversation_profile_rest_flattened_error(transport: str = "rest def test_update_conversation_profile_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4405,7 +4851,7 @@ def test_update_conversation_profile_rest_error(): ) def test_delete_conversation_profile_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4451,7 +4897,7 @@ def test_delete_conversation_profile_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4460,7 +4906,7 @@ def test_delete_conversation_profile_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation_profile._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4469,7 +4915,7 @@ def test_delete_conversation_profile_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4508,7 +4954,7 @@ def test_delete_conversation_profile_rest_required_fields( def test_delete_conversation_profile_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_conversation_profile._get_unset_required_fields({}) @@ -4518,7 +4964,7 @@ def test_delete_conversation_profile_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_conversation_profile_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -4570,7 +5016,7 @@ def test_delete_conversation_profile_rest_bad_request( request_type=conversation_profile.DeleteConversationProfileRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4592,7 +5038,7 @@ def test_delete_conversation_profile_rest_bad_request( def test_delete_conversation_profile_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4632,7 +5078,7 @@ def test_delete_conversation_profile_rest_flattened(): def test_delete_conversation_profile_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4647,7 +5093,7 @@ def test_delete_conversation_profile_rest_flattened_error(transport: str = "rest def test_delete_conversation_profile_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4660,7 +5106,7 @@ def test_delete_conversation_profile_rest_error(): ) def test_set_suggestion_feature_config_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4708,7 +5154,7 @@ def test_set_suggestion_feature_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_suggestion_feature_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4717,7 +5163,7 @@ def test_set_suggestion_feature_config_rest_required_fields( jsonified_request["conversationProfile"] = "conversation_profile_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_suggestion_feature_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4726,7 +5172,7 @@ def test_set_suggestion_feature_config_rest_required_fields( assert jsonified_request["conversationProfile"] == "conversation_profile_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4766,7 +5212,7 @@ def test_set_suggestion_feature_config_rest_required_fields( def test_set_suggestion_feature_config_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.set_suggestion_feature_config._get_unset_required_fields( @@ -4787,7 +5233,7 @@ def test_set_suggestion_feature_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_set_suggestion_feature_config_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -4850,7 +5296,7 @@ def test_set_suggestion_feature_config_rest_bad_request( request_type=gcd_conversation_profile.SetSuggestionFeatureConfigRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4874,7 +5320,7 @@ def test_set_suggestion_feature_config_rest_bad_request( def test_set_suggestion_feature_config_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4922,7 +5368,7 @@ def test_set_suggestion_feature_config_rest_flattened(): def test_set_suggestion_feature_config_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4943,7 +5389,7 @@ def test_set_suggestion_feature_config_rest_flattened_error(transport: str = "re def test_set_suggestion_feature_config_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4956,7 +5402,7 @@ def test_set_suggestion_feature_config_rest_error(): ) def test_clear_suggestion_feature_config_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5004,7 +5450,7 @@ def test_clear_suggestion_feature_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).clear_suggestion_feature_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5013,7 +5459,7 @@ def test_clear_suggestion_feature_config_rest_required_fields( jsonified_request["conversationProfile"] = "conversation_profile_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).clear_suggestion_feature_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5022,7 +5468,7 @@ def test_clear_suggestion_feature_config_rest_required_fields( assert jsonified_request["conversationProfile"] == "conversation_profile_value" client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5062,7 +5508,7 @@ def test_clear_suggestion_feature_config_rest_required_fields( def test_clear_suggestion_feature_config_rest_unset_required_fields(): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.clear_suggestion_feature_config._get_unset_required_fields( @@ -5083,7 +5529,7 @@ def test_clear_suggestion_feature_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_clear_suggestion_feature_config_rest_interceptors(null_interceptor): transport = transports.ConversationProfilesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationProfilesRestInterceptor(), @@ -5146,7 +5592,7 @@ def test_clear_suggestion_feature_config_rest_bad_request( request_type=gcd_conversation_profile.ClearSuggestionFeatureConfigRequest, ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5170,7 +5616,7 @@ def test_clear_suggestion_feature_config_rest_bad_request( def test_clear_suggestion_feature_config_rest_flattened(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5214,7 +5660,7 @@ def test_clear_suggestion_feature_config_rest_flattened(): def test_clear_suggestion_feature_config_rest_flattened_error(transport: str = "rest"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5231,24 +5677,24 @@ def test_clear_suggestion_feature_config_rest_flattened_error(transport: str = " def test_clear_suggestion_feature_config_rest_error(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationProfilesClient( @@ -5258,7 +5704,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5269,16 +5715,17 @@ 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 = ConversationProfilesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationProfilesClient( @@ -5290,7 +5737,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ConversationProfilesClient(transport=transport) assert client.transport is transport @@ -5299,13 +5746,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationProfilesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ConversationProfilesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5322,7 +5769,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5336,7 +5783,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ConversationProfilesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5344,7 +5791,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5356,7 +5803,7 @@ def test_conversation_profiles_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ConversationProfilesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5368,7 +5815,7 @@ def test_conversation_profiles_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConversationProfilesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5416,7 +5863,7 @@ def test_conversation_profiles_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationProfilesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5438,7 +5885,7 @@ def test_conversation_profiles_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.conversation_profiles.transports.ConversationProfilesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationProfilesTransport() adc.assert_called_once() @@ -5446,7 +5893,7 @@ def test_conversation_profiles_base_transport_with_adc(): def test_conversation_profiles_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ConversationProfilesClient() adc.assert_called_once_with( scopes=None, @@ -5469,7 +5916,7 @@ def test_conversation_profiles_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5519,7 +5966,7 @@ def test_conversation_profiles_transport_create_channel(transport_class, grpc_he ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5552,7 +5999,7 @@ def test_conversation_profiles_transport_create_channel(transport_class, grpc_he def test_conversation_profiles_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5590,7 +6037,7 @@ def test_conversation_profiles_grpc_transport_client_cert_source_for_mtls( def test_conversation_profiles_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5602,7 +6049,7 @@ def test_conversation_profiles_http_transport_client_cert_source_for_mtls(): def test_conversation_profiles_rest_lro_client(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5627,7 +6074,7 @@ def test_conversation_profiles_rest_lro_client(): ) def test_conversation_profiles_host_no_port(transport_name): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -5650,7 +6097,7 @@ def test_conversation_profiles_host_no_port(transport_name): ) def test_conversation_profiles_host_with_port(transport_name): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -5670,8 +6117,8 @@ def test_conversation_profiles_host_with_port(transport_name): ], ) def test_conversation_profiles_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ConversationProfilesClient( credentials=creds1, transport=transport_name, @@ -5753,7 +6200,7 @@ def test_conversation_profiles_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5831,7 +6278,7 @@ def test_conversation_profiles_transport_channel_mtls_with_adc(transport_class): def test_conversation_profiles_grpc_lro_client(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5848,7 +6295,7 @@ def test_conversation_profiles_grpc_lro_client(): def test_conversation_profiles_grpc_lro_async_client(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -6123,7 +6570,7 @@ def test_client_with_default_client_info(): transports.ConversationProfilesTransport, "_prep_wrapped_messages" ) as prep: client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6133,7 +6580,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ConversationProfilesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6142,7 +6589,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6157,7 +6604,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6187,7 +6634,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -6215,7 +6662,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6243,7 +6690,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6271,7 +6718,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6301,7 +6748,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6329,7 +6776,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6359,7 +6806,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6387,7 +6834,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6415,7 +6862,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6441,7 +6888,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6466,7 +6913,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6490,7 +6937,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6519,7 +6966,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6546,7 +6993,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6564,7 +7011,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6580,7 +7027,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6605,7 +7052,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6631,7 +7078,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6660,7 +7107,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6689,7 +7136,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6707,7 +7154,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6725,7 +7172,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6750,7 +7197,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6776,7 +7223,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6805,7 +7252,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6834,7 +7281,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6852,7 +7299,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6870,7 +7317,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6895,7 +7342,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6921,7 +7368,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6950,7 +7397,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6979,7 +7426,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6997,7 +7444,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7015,7 +7462,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7040,7 +7487,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7066,7 +7513,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7095,7 +7542,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7124,7 +7571,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7142,7 +7589,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ConversationProfilesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7166,7 +7613,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7183,7 +7630,7 @@ def test_client_ctx(): ] for transport in transports: client = ConversationProfilesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7217,7 +7664,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py index 137af1af088f..f4106a91e3ec 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_conversations.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -78,6 +78,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -107,6 +130,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert ConversationsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ConversationsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ConversationsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ConversationsClient._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 ConversationsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ConversationsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ConversationsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationsClient._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 ConversationsClient._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 ConversationsClient._get_client_cert_source(None, False) is None + assert ( + ConversationsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + ConversationsClient._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 ( + ConversationsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ConversationsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ConversationsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsClient), +) +@mock.patch.object( + ConversationsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ConversationsClient._DEFAULT_UNIVERSE + default_endpoint = ConversationsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ConversationsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ConversationsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ConversationsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + ConversationsClient._get_api_endpoint(None, None, default_universe, "always") + == ConversationsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ConversationsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ConversationsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationsClient._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 ( + ConversationsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ConversationsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ConversationsClient._get_universe_domain(None, None) + == ConversationsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ConversationsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (ConversationsClient, transports.ConversationsGrpcTransport, "grpc"), + (ConversationsClient, transports.ConversationsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -116,7 +396,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_conversations_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -168,7 +448,7 @@ def test_conversations_client_service_account_always_use_jwt( ], ) def test_conversations_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -218,20 +498,22 @@ def test_conversations_client_get_transport_class(): ) @mock.patch.object( ConversationsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsClient), ) @mock.patch.object( ConversationsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsAsyncClient), ) def test_conversations_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ConversationsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -266,7 +548,9 @@ def test_conversations_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, @@ -296,15 +580,23 @@ def test_conversations_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") @@ -314,7 +606,9 @@ def test_conversations_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", @@ -332,7 +626,9 @@ def test_conversations_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, @@ -365,13 +661,13 @@ def test_conversations_client_client_options( ) @mock.patch.object( ConversationsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsClient), ) @mock.patch.object( ConversationsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_conversations_client_mtls_env_auto( @@ -394,7 +690,9 @@ def test_conversations_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 @@ -426,7 +724,9 @@ def test_conversations_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 @@ -460,7 +760,9 @@ def test_conversations_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, @@ -550,6 +852,118 @@ def test_conversations_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", [ConversationsClient, ConversationsAsyncClient] +) +@mock.patch.object( + ConversationsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsClient), +) +@mock.patch.object( + ConversationsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationsAsyncClient), +) +def test_conversations_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ConversationsClient._DEFAULT_UNIVERSE + default_endpoint = ConversationsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ConversationsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -576,7 +990,9 @@ def test_conversations_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, @@ -616,7 +1032,9 @@ def test_conversations_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, @@ -676,7 +1094,9 @@ def test_conversations_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, @@ -693,8 +1113,8 @@ def test_conversations_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -726,7 +1146,7 @@ def test_conversations_client_create_channel_credentials_file( ) def test_create_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -770,7 +1190,7 @@ def test_create_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -790,7 +1210,7 @@ async def test_create_conversation_async( request_type=gcd_conversation.CreateConversationRequest, ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -839,7 +1259,7 @@ async def test_create_conversation_async_from_dict(): def test_create_conversation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -871,7 +1291,7 @@ def test_create_conversation_field_headers(): @pytest.mark.asyncio async def test_create_conversation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -904,7 +1324,7 @@ async def test_create_conversation_field_headers_async(): def test_create_conversation_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -934,7 +1354,7 @@ def test_create_conversation_flattened(): def test_create_conversation_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -950,7 +1370,7 @@ def test_create_conversation_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -985,7 +1405,7 @@ async def test_create_conversation_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1007,7 +1427,7 @@ async def test_create_conversation_flattened_error_async(): ) def test_list_conversations(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1039,7 +1459,7 @@ def test_list_conversations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1058,7 +1478,7 @@ async def test_list_conversations_async( transport: str = "grpc_asyncio", request_type=conversation.ListConversationsRequest ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1095,7 +1515,7 @@ async def test_list_conversations_async_from_dict(): def test_list_conversations_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1127,7 +1547,7 @@ def test_list_conversations_field_headers(): @pytest.mark.asyncio async def test_list_conversations_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1160,7 +1580,7 @@ async def test_list_conversations_field_headers_async(): def test_list_conversations_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1186,7 +1606,7 @@ def test_list_conversations_flattened(): def test_list_conversations_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1201,7 +1621,7 @@ def test_list_conversations_flattened_error(): @pytest.mark.asyncio async def test_list_conversations_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1232,7 +1652,7 @@ async def test_list_conversations_flattened_async(): @pytest.mark.asyncio async def test_list_conversations_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1246,7 +1666,7 @@ async def test_list_conversations_flattened_error_async(): def test_list_conversations_pager(transport_name: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1298,7 +1718,7 @@ def test_list_conversations_pager(transport_name: str = "grpc"): def test_list_conversations_pages(transport_name: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1342,7 +1762,7 @@ def test_list_conversations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversations_async_pager(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1394,7 +1814,7 @@ async def test_list_conversations_async_pager(): @pytest.mark.asyncio async def test_list_conversations_async_pages(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1451,7 +1871,7 @@ async def test_list_conversations_async_pages(): ) def test_get_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1492,7 +1912,7 @@ def test_get_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1509,7 +1929,7 @@ async def test_get_conversation_async( transport: str = "grpc_asyncio", request_type=conversation.GetConversationRequest ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1555,7 +1975,7 @@ async def test_get_conversation_async_from_dict(): def test_get_conversation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1585,7 +2005,7 @@ def test_get_conversation_field_headers(): @pytest.mark.asyncio async def test_get_conversation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1616,7 +2036,7 @@ async def test_get_conversation_field_headers_async(): def test_get_conversation_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1640,7 +2060,7 @@ def test_get_conversation_flattened(): def test_get_conversation_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1655,7 +2075,7 @@ def test_get_conversation_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1684,7 +2104,7 @@ async def test_get_conversation_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1705,7 +2125,7 @@ async def test_get_conversation_flattened_error_async(): ) def test_complete_conversation(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1748,7 +2168,7 @@ def test_complete_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1768,7 +2188,7 @@ async def test_complete_conversation_async( request_type=conversation.CompleteConversationRequest, ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1816,7 +2236,7 @@ async def test_complete_conversation_async_from_dict(): def test_complete_conversation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1848,7 +2268,7 @@ def test_complete_conversation_field_headers(): @pytest.mark.asyncio async def test_complete_conversation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1881,7 +2301,7 @@ async def test_complete_conversation_field_headers_async(): def test_complete_conversation_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1907,7 +2327,7 @@ def test_complete_conversation_flattened(): def test_complete_conversation_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1922,7 +2342,7 @@ def test_complete_conversation_flattened_error(): @pytest.mark.asyncio async def test_complete_conversation_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1953,7 +2373,7 @@ async def test_complete_conversation_flattened_async(): @pytest.mark.asyncio async def test_complete_conversation_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1974,7 +2394,7 @@ async def test_complete_conversation_flattened_error_async(): ) def test_batch_create_messages(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2003,7 +2423,7 @@ def test_batch_create_messages_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2023,7 +2443,7 @@ async def test_batch_create_messages_async( request_type=conversation.BatchCreateMessagesRequest, ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2057,7 +2477,7 @@ async def test_batch_create_messages_async_from_dict(): def test_batch_create_messages_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2089,7 +2509,7 @@ def test_batch_create_messages_field_headers(): @pytest.mark.asyncio async def test_batch_create_messages_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2122,7 +2542,7 @@ async def test_batch_create_messages_field_headers_async(): def test_batch_create_messages_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2148,7 +2568,7 @@ def test_batch_create_messages_flattened(): def test_batch_create_messages_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2163,7 +2583,7 @@ def test_batch_create_messages_flattened_error(): @pytest.mark.asyncio async def test_batch_create_messages_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2194,7 +2614,7 @@ async def test_batch_create_messages_flattened_async(): @pytest.mark.asyncio async def test_batch_create_messages_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2215,7 +2635,7 @@ async def test_batch_create_messages_flattened_error_async(): ) def test_list_messages(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2245,7 +2665,7 @@ def test_list_messages_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2262,7 +2682,7 @@ async def test_list_messages_async( transport: str = "grpc_asyncio", request_type=conversation.ListMessagesRequest ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2297,7 +2717,7 @@ async def test_list_messages_async_from_dict(): def test_list_messages_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2327,7 +2747,7 @@ def test_list_messages_field_headers(): @pytest.mark.asyncio async def test_list_messages_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2358,7 +2778,7 @@ async def test_list_messages_field_headers_async(): def test_list_messages_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2382,7 +2802,7 @@ def test_list_messages_flattened(): def test_list_messages_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2397,7 +2817,7 @@ def test_list_messages_flattened_error(): @pytest.mark.asyncio async def test_list_messages_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2426,7 +2846,7 @@ async def test_list_messages_flattened_async(): @pytest.mark.asyncio async def test_list_messages_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2440,7 +2860,7 @@ async def test_list_messages_flattened_error_async(): def test_list_messages_pager(transport_name: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2490,7 +2910,7 @@ def test_list_messages_pager(transport_name: str = "grpc"): def test_list_messages_pages(transport_name: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2532,7 +2952,7 @@ def test_list_messages_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_messages_async_pager(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2582,7 +3002,7 @@ async def test_list_messages_async_pager(): @pytest.mark.asyncio async def test_list_messages_async_pages(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2637,7 +3057,7 @@ async def test_list_messages_async_pages(): ) def test_suggest_conversation_summary(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2671,7 +3091,7 @@ def test_suggest_conversation_summary_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2691,7 +3111,7 @@ async def test_suggest_conversation_summary_async( request_type=gcd_conversation.SuggestConversationSummaryRequest, ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2730,7 +3150,7 @@ async def test_suggest_conversation_summary_async_from_dict(): def test_suggest_conversation_summary_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2762,7 +3182,7 @@ def test_suggest_conversation_summary_field_headers(): @pytest.mark.asyncio async def test_suggest_conversation_summary_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2795,7 +3215,7 @@ async def test_suggest_conversation_summary_field_headers_async(): def test_suggest_conversation_summary_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2821,7 +3241,7 @@ def test_suggest_conversation_summary_flattened(): def test_suggest_conversation_summary_flattened_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2836,7 +3256,7 @@ def test_suggest_conversation_summary_flattened_error(): @pytest.mark.asyncio async def test_suggest_conversation_summary_flattened_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2867,7 +3287,7 @@ async def test_suggest_conversation_summary_flattened_async(): @pytest.mark.asyncio async def test_suggest_conversation_summary_flattened_error_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2888,7 +3308,7 @@ async def test_suggest_conversation_summary_flattened_error_async(): ) def test_generate_stateless_summary(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2922,7 +3342,7 @@ def test_generate_stateless_summary_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2942,7 +3362,7 @@ async def test_generate_stateless_summary_async( request_type=conversation.GenerateStatelessSummaryRequest, ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2981,7 +3401,7 @@ async def test_generate_stateless_summary_async_from_dict(): def test_generate_stateless_summary_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3013,7 +3433,7 @@ def test_generate_stateless_summary_field_headers(): @pytest.mark.asyncio async def test_generate_stateless_summary_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3053,7 +3473,7 @@ async def test_generate_stateless_summary_field_headers_async(): ) def test_search_knowledge(request_type, transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3083,7 +3503,7 @@ def test_search_knowledge_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3100,7 +3520,7 @@ async def test_search_knowledge_async( transport: str = "grpc_asyncio", request_type=conversation.SearchKnowledgeRequest ): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3135,7 +3555,7 @@ async def test_search_knowledge_async_from_dict(): def test_search_knowledge_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3165,7 +3585,7 @@ def test_search_knowledge_field_headers(): @pytest.mark.asyncio async def test_search_knowledge_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3203,7 +3623,7 @@ async def test_search_knowledge_field_headers_async(): ) def test_create_conversation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3342,7 +3762,7 @@ def test_create_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3351,7 +3771,7 @@ def test_create_conversation_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("conversation_id",)) @@ -3362,7 +3782,7 @@ def test_create_conversation_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3405,7 +3825,7 @@ def test_create_conversation_rest_required_fields( def test_create_conversation_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_conversation._get_unset_required_fields({}) @@ -3423,7 +3843,7 @@ def test_create_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -3481,7 +3901,7 @@ def test_create_conversation_rest_bad_request( transport: str = "rest", request_type=gcd_conversation.CreateConversationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3503,7 +3923,7 @@ def test_create_conversation_rest_bad_request( def test_create_conversation_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3545,7 +3965,7 @@ def test_create_conversation_rest_flattened(): def test_create_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3561,7 +3981,7 @@ def test_create_conversation_rest_flattened_error(transport: str = "rest"): def test_create_conversation_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3574,7 +3994,7 @@ def test_create_conversation_rest_error(): ) def test_list_conversations_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3625,7 +4045,7 @@ def test_list_conversations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3634,7 +4054,7 @@ def test_list_conversations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3651,7 +4071,7 @@ def test_list_conversations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3693,7 +4113,7 @@ def test_list_conversations_rest_required_fields( def test_list_conversations_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_conversations._get_unset_required_fields({}) @@ -3712,7 +4132,7 @@ def test_list_conversations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversations_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -3770,7 +4190,7 @@ def test_list_conversations_rest_bad_request( transport: str = "rest", request_type=conversation.ListConversationsRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3792,7 +4212,7 @@ def test_list_conversations_rest_bad_request( def test_list_conversations_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3833,7 +4253,7 @@ def test_list_conversations_rest_flattened(): def test_list_conversations_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3848,7 +4268,7 @@ def test_list_conversations_rest_flattened_error(transport: str = "rest"): def test_list_conversations_rest_pager(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3918,7 +4338,7 @@ def test_list_conversations_rest_pager(transport: str = "rest"): ) def test_get_conversation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3980,7 +4400,7 @@ def test_get_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3989,7 +4409,7 @@ def test_get_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3998,7 +4418,7 @@ def test_get_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4040,7 +4460,7 @@ def test_get_conversation_rest_required_fields( def test_get_conversation_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_conversation._get_unset_required_fields({}) @@ -4050,7 +4470,7 @@ def test_get_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -4108,7 +4528,7 @@ def test_get_conversation_rest_bad_request( transport: str = "rest", request_type=conversation.GetConversationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4130,7 +4550,7 @@ def test_get_conversation_rest_bad_request( def test_get_conversation_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4171,7 +4591,7 @@ def test_get_conversation_rest_flattened(): def test_get_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4186,7 +4606,7 @@ def test_get_conversation_rest_flattened_error(transport: str = "rest"): def test_get_conversation_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4199,7 +4619,7 @@ def test_get_conversation_rest_error(): ) def test_complete_conversation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4261,7 +4681,7 @@ def test_complete_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4270,7 +4690,7 @@ def test_complete_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4279,7 +4699,7 @@ def test_complete_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4322,7 +4742,7 @@ def test_complete_conversation_rest_required_fields( def test_complete_conversation_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.complete_conversation._get_unset_required_fields({}) @@ -4332,7 +4752,7 @@ def test_complete_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_complete_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -4390,7 +4810,7 @@ def test_complete_conversation_rest_bad_request( transport: str = "rest", request_type=conversation.CompleteConversationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4412,7 +4832,7 @@ def test_complete_conversation_rest_bad_request( def test_complete_conversation_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4454,7 +4874,7 @@ def test_complete_conversation_rest_flattened(): def test_complete_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4469,7 +4889,7 @@ def test_complete_conversation_rest_flattened_error(transport: str = "rest"): def test_complete_conversation_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4482,7 +4902,7 @@ def test_complete_conversation_rest_error(): ) def test_batch_create_messages_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4530,7 +4950,7 @@ def test_batch_create_messages_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_create_messages._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4539,7 +4959,7 @@ def test_batch_create_messages_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_create_messages._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4548,7 +4968,7 @@ def test_batch_create_messages_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4591,7 +5011,7 @@ def test_batch_create_messages_rest_required_fields( def test_batch_create_messages_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_create_messages._get_unset_required_fields({}) @@ -4609,7 +5029,7 @@ def test_batch_create_messages_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_create_messages_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -4667,7 +5087,7 @@ def test_batch_create_messages_rest_bad_request( transport: str = "rest", request_type=conversation.BatchCreateMessagesRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4689,7 +5109,7 @@ def test_batch_create_messages_rest_bad_request( def test_batch_create_messages_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4731,7 +5151,7 @@ def test_batch_create_messages_rest_flattened(): def test_batch_create_messages_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4746,7 +5166,7 @@ def test_batch_create_messages_rest_flattened_error(transport: str = "rest"): def test_batch_create_messages_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4759,7 +5179,7 @@ def test_batch_create_messages_rest_error(): ) def test_list_messages_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4810,7 +5230,7 @@ def test_list_messages_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_messages._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4819,7 +5239,7 @@ def test_list_messages_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_messages._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4836,7 +5256,7 @@ def test_list_messages_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4878,7 +5298,7 @@ def test_list_messages_rest_required_fields( def test_list_messages_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_messages._get_unset_required_fields({}) @@ -4897,7 +5317,7 @@ def test_list_messages_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_messages_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -4955,7 +5375,7 @@ def test_list_messages_rest_bad_request( transport: str = "rest", request_type=conversation.ListMessagesRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4977,7 +5397,7 @@ def test_list_messages_rest_bad_request( def test_list_messages_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5019,7 +5439,7 @@ def test_list_messages_rest_flattened(): def test_list_messages_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5034,7 +5454,7 @@ def test_list_messages_rest_flattened_error(transport: str = "rest"): def test_list_messages_rest_pager(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5102,7 +5522,7 @@ def test_list_messages_rest_pager(transport: str = "rest"): ) def test_suggest_conversation_summary_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5157,7 +5577,7 @@ def test_suggest_conversation_summary_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_conversation_summary._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5166,7 +5586,7 @@ def test_suggest_conversation_summary_rest_required_fields( jsonified_request["conversation"] = "conversation_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_conversation_summary._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5175,7 +5595,7 @@ def test_suggest_conversation_summary_rest_required_fields( assert jsonified_request["conversation"] == "conversation_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5220,7 +5640,7 @@ def test_suggest_conversation_summary_rest_required_fields( def test_suggest_conversation_summary_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.suggest_conversation_summary._get_unset_required_fields({}) @@ -5230,7 +5650,7 @@ def test_suggest_conversation_summary_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_suggest_conversation_summary_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -5291,7 +5711,7 @@ def test_suggest_conversation_summary_rest_bad_request( request_type=gcd_conversation.SuggestConversationSummaryRequest, ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5313,7 +5733,7 @@ def test_suggest_conversation_summary_rest_bad_request( def test_suggest_conversation_summary_rest_flattened(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5357,7 +5777,7 @@ def test_suggest_conversation_summary_rest_flattened(): def test_suggest_conversation_summary_rest_flattened_error(transport: str = "rest"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5372,7 +5792,7 @@ def test_suggest_conversation_summary_rest_flattened_error(transport: str = "res def test_suggest_conversation_summary_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5385,7 +5805,7 @@ def test_suggest_conversation_summary_rest_error(): ) def test_generate_stateless_summary_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5437,21 +5857,21 @@ def test_generate_stateless_summary_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_stateless_summary._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_stateless_summary._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5496,7 +5916,7 @@ def test_generate_stateless_summary_rest_required_fields( def test_generate_stateless_summary_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_stateless_summary._get_unset_required_fields({}) @@ -5514,7 +5934,7 @@ def test_generate_stateless_summary_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_stateless_summary_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -5574,7 +5994,7 @@ def test_generate_stateless_summary_rest_bad_request( transport: str = "rest", request_type=conversation.GenerateStatelessSummaryRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5596,7 +6016,7 @@ def test_generate_stateless_summary_rest_bad_request( def test_generate_stateless_summary_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5609,7 +6029,7 @@ def test_generate_stateless_summary_rest_error(): ) def test_search_knowledge_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5660,7 +6080,7 @@ def test_search_knowledge_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_knowledge._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5669,7 +6089,7 @@ def test_search_knowledge_rest_required_fields( jsonified_request["conversationProfile"] = "conversation_profile_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_knowledge._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5678,7 +6098,7 @@ def test_search_knowledge_rest_required_fields( assert jsonified_request["conversationProfile"] == "conversation_profile_value" client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5721,7 +6141,7 @@ def test_search_knowledge_rest_required_fields( def test_search_knowledge_rest_unset_required_fields(): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search_knowledge._get_unset_required_fields({}) @@ -5739,7 +6159,7 @@ def test_search_knowledge_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_knowledge_rest_interceptors(null_interceptor): transport = transports.ConversationsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationsRestInterceptor(), @@ -5797,7 +6217,7 @@ def test_search_knowledge_rest_bad_request( transport: str = "rest", request_type=conversation.SearchKnowledgeRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5819,24 +6239,24 @@ def test_search_knowledge_rest_bad_request( def test_search_knowledge_rest_error(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationsClient( @@ -5846,7 +6266,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5857,16 +6277,17 @@ 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 = ConversationsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationsClient( @@ -5878,7 +6299,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ConversationsClient(transport=transport) assert client.transport is transport @@ -5887,13 +6308,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ConversationsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5910,7 +6331,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5924,7 +6345,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ConversationsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5932,7 +6353,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5944,7 +6365,7 @@ def test_conversations_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ConversationsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5956,7 +6377,7 @@ def test_conversations_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConversationsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6001,7 +6422,7 @@ def test_conversations_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6023,7 +6444,7 @@ def test_conversations_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.conversations.transports.ConversationsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationsTransport() adc.assert_called_once() @@ -6031,7 +6452,7 @@ def test_conversations_base_transport_with_adc(): def test_conversations_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ConversationsClient() adc.assert_called_once_with( scopes=None, @@ -6054,7 +6475,7 @@ def test_conversations_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -6104,7 +6525,7 @@ def test_conversations_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6135,7 +6556,7 @@ def test_conversations_transport_create_channel(transport_class, grpc_helpers): ], ) def test_conversations_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6173,7 +6594,7 @@ def test_conversations_grpc_transport_client_cert_source_for_mtls(transport_clas def test_conversations_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -6193,7 +6614,7 @@ def test_conversations_http_transport_client_cert_source_for_mtls(): ) def test_conversations_host_no_port(transport_name): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -6216,7 +6637,7 @@ def test_conversations_host_no_port(transport_name): ) def test_conversations_host_with_port(transport_name): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -6236,8 +6657,8 @@ def test_conversations_host_with_port(transport_name): ], ) def test_conversations_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ConversationsClient( credentials=creds1, transport=transport_name, @@ -6323,7 +6744,7 @@ def test_conversations_transport_channel_mtls_with_client_cert_source(transport_ mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6733,7 +7154,7 @@ def test_client_with_default_client_info(): transports.ConversationsTransport, "_prep_wrapped_messages" ) as prep: client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6743,7 +7164,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ConversationsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6752,7 +7173,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6767,7 +7188,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6797,7 +7218,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -6825,7 +7246,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6853,7 +7274,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6881,7 +7302,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6911,7 +7332,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6939,7 +7360,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6969,7 +7390,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6997,7 +7418,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7025,7 +7446,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -7051,7 +7472,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7076,7 +7497,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7100,7 +7521,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7129,7 +7550,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7156,7 +7577,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7174,7 +7595,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7190,7 +7611,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7215,7 +7636,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7241,7 +7662,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7270,7 +7691,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7299,7 +7720,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7317,7 +7738,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7335,7 +7756,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7360,7 +7781,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7386,7 +7807,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7415,7 +7836,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7444,7 +7865,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7462,7 +7883,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7480,7 +7901,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7505,7 +7926,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7531,7 +7952,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7560,7 +7981,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7589,7 +8010,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7607,7 +8028,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7625,7 +8046,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7650,7 +8071,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7675,7 +8096,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = ConversationsClient(credentials=ga_credentials.AnonymousCredentials()) + client = ConversationsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7702,7 +8123,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = ConversationsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = ConversationsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7730,7 +8153,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7748,7 +8171,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ConversationsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7772,7 +8195,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7789,7 +8212,7 @@ def test_client_ctx(): ] for transport in transports: client = ConversationsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7820,7 +8243,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_documents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_documents.py index bfc4c03bfb8d..41dc3184aa65 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_documents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_documents.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -84,6 +84,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -108,6 +131,247 @@ def test__get_default_mtls_endpoint(): assert DocumentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert DocumentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DocumentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DocumentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DocumentsClient._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 DocumentsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DocumentsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DocumentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentsClient._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 DocumentsClient._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 DocumentsClient._get_client_cert_source(None, False) is None + assert ( + DocumentsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + DocumentsClient._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 ( + DocumentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DocumentsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DocumentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsClient), +) +@mock.patch.object( + DocumentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DocumentsClient._DEFAULT_UNIVERSE + default_endpoint = DocumentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DocumentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DocumentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DocumentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DocumentsClient._get_api_endpoint(None, None, default_universe, "always") + == DocumentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DocumentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DocumentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentsClient._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 ( + DocumentsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DocumentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DocumentsClient._get_universe_domain(None, None) + == DocumentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DocumentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DocumentsClient, transports.DocumentsGrpcTransport, "grpc"), + (DocumentsClient, transports.DocumentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -117,7 +381,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_documents_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -169,7 +433,7 @@ def test_documents_client_service_account_always_use_jwt( ], ) def test_documents_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -218,17 +482,21 @@ def test_documents_client_get_transport_class(): ], ) @mock.patch.object( - DocumentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentsClient) + DocumentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsClient), ) @mock.patch.object( DocumentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsAsyncClient), ) def test_documents_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(DocumentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -263,7 +531,9 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -293,15 +563,23 @@ def test_documents_client_client_options(client_class, transport_class, transpor # 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") @@ -311,7 +589,9 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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", @@ -329,7 +609,9 @@ def test_documents_client_client_options(client_class, transport_class, transpor 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, @@ -361,12 +643,14 @@ def test_documents_client_client_options(client_class, transport_class, transpor ], ) @mock.patch.object( - DocumentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DocumentsClient) + DocumentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsClient), ) @mock.patch.object( DocumentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_documents_client_mtls_env_auto( @@ -389,7 +673,9 @@ def test_documents_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 @@ -421,7 +707,9 @@ def test_documents_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 @@ -455,7 +743,9 @@ def test_documents_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, @@ -541,6 +831,116 @@ def test_documents_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", [DocumentsClient, DocumentsAsyncClient]) +@mock.patch.object( + DocumentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsClient), +) +@mock.patch.object( + DocumentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentsAsyncClient), +) +def test_documents_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DocumentsClient._DEFAULT_UNIVERSE + default_endpoint = DocumentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -567,7 +967,9 @@ def test_documents_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, @@ -602,7 +1004,9 @@ def test_documents_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, @@ -655,7 +1059,9 @@ def test_documents_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, @@ -672,8 +1078,8 @@ def test_documents_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -705,7 +1111,7 @@ def test_documents_client_create_channel_credentials_file( ) def test_list_documents(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -735,7 +1141,7 @@ def test_list_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -752,7 +1158,7 @@ async def test_list_documents_async( transport: str = "grpc_asyncio", request_type=document.ListDocumentsRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -787,7 +1193,7 @@ async def test_list_documents_async_from_dict(): def test_list_documents_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -817,7 +1223,7 @@ def test_list_documents_field_headers(): @pytest.mark.asyncio async def test_list_documents_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -848,7 +1254,7 @@ async def test_list_documents_field_headers_async(): def test_list_documents_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -872,7 +1278,7 @@ def test_list_documents_flattened(): def test_list_documents_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -887,7 +1293,7 @@ def test_list_documents_flattened_error(): @pytest.mark.asyncio async def test_list_documents_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -916,7 +1322,7 @@ async def test_list_documents_flattened_async(): @pytest.mark.asyncio async def test_list_documents_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -930,7 +1336,7 @@ async def test_list_documents_flattened_error_async(): def test_list_documents_pager(transport_name: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -980,7 +1386,7 @@ def test_list_documents_pager(transport_name: str = "grpc"): def test_list_documents_pages(transport_name: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1022,7 +1428,7 @@ def test_list_documents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_documents_async_pager(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1072,7 +1478,7 @@ async def test_list_documents_async_pager(): @pytest.mark.asyncio async def test_list_documents_async_pages(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1127,7 +1533,7 @@ async def test_list_documents_async_pages(): ) def test_get_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1168,7 +1574,7 @@ def test_get_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1185,7 +1591,7 @@ async def test_get_document_async( transport: str = "grpc_asyncio", request_type=document.GetDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1230,7 +1636,7 @@ async def test_get_document_async_from_dict(): def test_get_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1260,7 +1666,7 @@ def test_get_document_field_headers(): @pytest.mark.asyncio async def test_get_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1289,7 +1695,7 @@ async def test_get_document_field_headers_async(): def test_get_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1313,7 +1719,7 @@ def test_get_document_flattened(): def test_get_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1328,7 +1734,7 @@ def test_get_document_flattened_error(): @pytest.mark.asyncio async def test_get_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1355,7 +1761,7 @@ async def test_get_document_flattened_async(): @pytest.mark.asyncio async def test_get_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1376,7 +1782,7 @@ async def test_get_document_flattened_error_async(): ) def test_create_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1403,7 +1809,7 @@ def test_create_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1420,7 +1826,7 @@ async def test_create_document_async( transport: str = "grpc_asyncio", request_type=gcd_document.CreateDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1452,7 +1858,7 @@ async def test_create_document_async_from_dict(): def test_create_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1482,7 +1888,7 @@ def test_create_document_field_headers(): @pytest.mark.asyncio async def test_create_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1513,7 +1919,7 @@ async def test_create_document_field_headers_async(): def test_create_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1541,7 +1947,7 @@ def test_create_document_flattened(): def test_create_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1557,7 +1963,7 @@ def test_create_document_flattened_error(): @pytest.mark.asyncio async def test_create_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1590,7 +1996,7 @@ async def test_create_document_flattened_async(): @pytest.mark.asyncio async def test_create_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1612,7 +2018,7 @@ async def test_create_document_flattened_error_async(): ) def test_import_documents(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1639,7 +2045,7 @@ def test_import_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1656,7 +2062,7 @@ async def test_import_documents_async( transport: str = "grpc_asyncio", request_type=document.ImportDocumentsRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1688,7 +2094,7 @@ async def test_import_documents_async_from_dict(): def test_import_documents_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1718,7 +2124,7 @@ def test_import_documents_field_headers(): @pytest.mark.asyncio async def test_import_documents_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1756,7 +2162,7 @@ async def test_import_documents_field_headers_async(): ) def test_delete_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1783,7 +2189,7 @@ def test_delete_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1800,7 +2206,7 @@ async def test_delete_document_async( transport: str = "grpc_asyncio", request_type=document.DeleteDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1832,7 +2238,7 @@ async def test_delete_document_async_from_dict(): def test_delete_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1862,7 +2268,7 @@ def test_delete_document_field_headers(): @pytest.mark.asyncio async def test_delete_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1893,7 +2299,7 @@ async def test_delete_document_field_headers_async(): def test_delete_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1917,7 +2323,7 @@ def test_delete_document_flattened(): def test_delete_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1932,7 +2338,7 @@ def test_delete_document_flattened_error(): @pytest.mark.asyncio async def test_delete_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1961,7 +2367,7 @@ async def test_delete_document_flattened_async(): @pytest.mark.asyncio async def test_delete_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1982,7 +2388,7 @@ async def test_delete_document_flattened_error_async(): ) def test_update_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2009,7 +2415,7 @@ def test_update_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2026,7 +2432,7 @@ async def test_update_document_async( transport: str = "grpc_asyncio", request_type=gcd_document.UpdateDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2058,7 +2464,7 @@ async def test_update_document_async_from_dict(): def test_update_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2088,7 +2494,7 @@ def test_update_document_field_headers(): @pytest.mark.asyncio async def test_update_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2119,7 +2525,7 @@ async def test_update_document_field_headers_async(): def test_update_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2147,7 +2553,7 @@ def test_update_document_flattened(): def test_update_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2163,7 +2569,7 @@ def test_update_document_flattened_error(): @pytest.mark.asyncio async def test_update_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2196,7 +2602,7 @@ async def test_update_document_flattened_async(): @pytest.mark.asyncio async def test_update_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2218,7 +2624,7 @@ async def test_update_document_flattened_error_async(): ) def test_reload_document(request_type, transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2245,7 +2651,7 @@ def test_reload_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2262,7 +2668,7 @@ async def test_reload_document_async( transport: str = "grpc_asyncio", request_type=document.ReloadDocumentRequest ): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2294,7 +2700,7 @@ async def test_reload_document_async_from_dict(): def test_reload_document_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2324,7 +2730,7 @@ def test_reload_document_field_headers(): @pytest.mark.asyncio async def test_reload_document_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2355,7 +2761,7 @@ async def test_reload_document_field_headers_async(): def test_reload_document_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2381,7 +2787,7 @@ def test_reload_document_flattened(): def test_reload_document_flattened_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2397,7 +2803,7 @@ def test_reload_document_flattened_error(): @pytest.mark.asyncio async def test_reload_document_flattened_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2428,7 +2834,7 @@ async def test_reload_document_flattened_async(): @pytest.mark.asyncio async def test_reload_document_flattened_error_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2450,7 +2856,7 @@ async def test_reload_document_flattened_error_async(): ) def test_list_documents_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2501,7 +2907,7 @@ def test_list_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2510,7 +2916,7 @@ def test_list_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2527,7 +2933,7 @@ def test_list_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2569,7 +2975,7 @@ def test_list_documents_rest_required_fields( def test_list_documents_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_documents._get_unset_required_fields({}) @@ -2588,7 +2994,7 @@ def test_list_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_documents_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -2642,7 +3048,7 @@ def test_list_documents_rest_bad_request( transport: str = "rest", request_type=document.ListDocumentsRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2664,7 +3070,7 @@ def test_list_documents_rest_bad_request( def test_list_documents_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2706,7 +3112,7 @@ def test_list_documents_rest_flattened(): def test_list_documents_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2721,7 +3127,7 @@ def test_list_documents_rest_flattened_error(transport: str = "rest"): def test_list_documents_rest_pager(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2789,7 +3195,7 @@ def test_list_documents_rest_pager(transport: str = "rest"): ) def test_get_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2849,7 +3255,7 @@ def test_get_document_rest_required_fields(request_type=document.GetDocumentRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2858,7 +3264,7 @@ def test_get_document_rest_required_fields(request_type=document.GetDocumentRequ jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2867,7 +3273,7 @@ def test_get_document_rest_required_fields(request_type=document.GetDocumentRequ assert jsonified_request["name"] == "name_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2909,7 +3315,7 @@ def test_get_document_rest_required_fields(request_type=document.GetDocumentRequ def test_get_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_document._get_unset_required_fields({}) @@ -2919,7 +3325,7 @@ def test_get_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -2971,7 +3377,7 @@ def test_get_document_rest_bad_request( transport: str = "rest", request_type=document.GetDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2993,7 +3399,7 @@ def test_get_document_rest_bad_request( def test_get_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3037,7 +3443,7 @@ def test_get_document_rest_flattened(): def test_get_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3052,7 +3458,7 @@ def test_get_document_rest_flattened_error(transport: str = "rest"): def test_get_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3065,7 +3471,7 @@ def test_get_document_rest_error(): ) def test_create_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3203,7 +3609,7 @@ def test_create_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3212,7 +3618,7 @@ def test_create_document_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("import_gcs_custom_metadata",)) @@ -3223,7 +3629,7 @@ def test_create_document_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3263,7 +3669,7 @@ def test_create_document_rest_required_fields( def test_create_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_document._get_unset_required_fields({}) @@ -3281,7 +3687,7 @@ def test_create_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -3339,7 +3745,7 @@ def test_create_document_rest_bad_request( transport: str = "rest", request_type=gcd_document.CreateDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3361,7 +3767,7 @@ def test_create_document_rest_bad_request( def test_create_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3402,7 +3808,7 @@ def test_create_document_rest_flattened(): def test_create_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3418,7 +3824,7 @@ def test_create_document_rest_flattened_error(transport: str = "rest"): def test_create_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3431,7 +3837,7 @@ def test_create_document_rest_error(): ) def test_import_documents_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3477,7 +3883,7 @@ def test_import_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3486,7 +3892,7 @@ def test_import_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3495,7 +3901,7 @@ def test_import_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3535,7 +3941,7 @@ def test_import_documents_rest_required_fields( def test_import_documents_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_documents._get_unset_required_fields({}) @@ -3553,7 +3959,7 @@ def test_import_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_documents_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -3611,7 +4017,7 @@ def test_import_documents_rest_bad_request( transport: str = "rest", request_type=document.ImportDocumentsRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3633,7 +4039,7 @@ def test_import_documents_rest_bad_request( def test_import_documents_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3646,7 +4052,7 @@ def test_import_documents_rest_error(): ) def test_delete_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3692,7 +4098,7 @@ def test_delete_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3701,7 +4107,7 @@ def test_delete_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3710,7 +4116,7 @@ def test_delete_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3749,7 +4155,7 @@ def test_delete_document_rest_required_fields( def test_delete_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_document._get_unset_required_fields({}) @@ -3759,7 +4165,7 @@ def test_delete_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -3815,7 +4221,7 @@ def test_delete_document_rest_bad_request( transport: str = "rest", request_type=document.DeleteDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3837,7 +4243,7 @@ def test_delete_document_rest_bad_request( def test_delete_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3879,7 +4285,7 @@ def test_delete_document_rest_flattened(): def test_delete_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3894,7 +4300,7 @@ def test_delete_document_rest_flattened_error(transport: str = "rest"): def test_delete_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3907,7 +4313,7 @@ def test_delete_document_rest_error(): ) def test_update_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4048,14 +4454,14 @@ def test_update_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -4064,7 +4470,7 @@ def test_update_document_rest_required_fields( # verify required fields with non-default values are left alone client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4104,7 +4510,7 @@ def test_update_document_rest_required_fields( def test_update_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_document._get_unset_required_fields({}) @@ -4114,7 +4520,7 @@ def test_update_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -4172,7 +4578,7 @@ def test_update_document_rest_bad_request( transport: str = "rest", request_type=gcd_document.UpdateDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4198,7 +4604,7 @@ def test_update_document_rest_bad_request( def test_update_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4243,7 +4649,7 @@ def test_update_document_rest_flattened(): def test_update_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4259,7 +4665,7 @@ def test_update_document_rest_flattened_error(transport: str = "rest"): def test_update_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4272,7 +4678,7 @@ def test_update_document_rest_error(): ) def test_reload_document_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4318,7 +4724,7 @@ def test_reload_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reload_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4327,7 +4733,7 @@ def test_reload_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reload_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4336,7 +4742,7 @@ def test_reload_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4376,7 +4782,7 @@ def test_reload_document_rest_required_fields( def test_reload_document_rest_unset_required_fields(): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.reload_document._get_unset_required_fields({}) @@ -4386,7 +4792,7 @@ def test_reload_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_reload_document_rest_interceptors(null_interceptor): transport = transports.DocumentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentsRestInterceptor(), ) client = DocumentsClient(transport=transport) @@ -4442,7 +4848,7 @@ def test_reload_document_rest_bad_request( transport: str = "rest", request_type=document.ReloadDocumentRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4464,7 +4870,7 @@ def test_reload_document_rest_bad_request( def test_reload_document_rest_flattened(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4506,7 +4912,7 @@ def test_reload_document_rest_flattened(): def test_reload_document_rest_flattened_error(transport: str = "rest"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4522,24 +4928,24 @@ def test_reload_document_rest_flattened_error(transport: str = "rest"): def test_reload_document_rest_error(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentsClient( @@ -4549,7 +4955,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4560,16 +4966,17 @@ 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 = DocumentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentsClient( @@ -4581,7 +4988,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DocumentsClient(transport=transport) assert client.transport is transport @@ -4590,13 +4997,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DocumentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4613,7 +5020,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4627,7 +5034,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DocumentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4635,7 +5042,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4647,7 +5054,7 @@ def test_documents_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DocumentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4659,7 +5066,7 @@ def test_documents_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DocumentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4707,7 +5114,7 @@ def test_documents_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.documents.transports.DocumentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4729,7 +5136,7 @@ def test_documents_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.documents.transports.DocumentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentsTransport() adc.assert_called_once() @@ -4737,7 +5144,7 @@ def test_documents_base_transport_with_adc(): def test_documents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DocumentsClient() adc.assert_called_once_with( scopes=None, @@ -4760,7 +5167,7 @@ def test_documents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4810,7 +5217,7 @@ def test_documents_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4838,7 +5245,7 @@ def test_documents_transport_create_channel(transport_class, grpc_helpers): [transports.DocumentsGrpcTransport, transports.DocumentsGrpcAsyncIOTransport], ) def test_documents_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4876,7 +5283,7 @@ def test_documents_grpc_transport_client_cert_source_for_mtls(transport_class): def test_documents_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4888,7 +5295,7 @@ def test_documents_http_transport_client_cert_source_for_mtls(): def test_documents_rest_lro_client(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -4913,7 +5320,7 @@ def test_documents_rest_lro_client(): ) def test_documents_host_no_port(transport_name): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4936,7 +5343,7 @@ def test_documents_host_no_port(transport_name): ) def test_documents_host_with_port(transport_name): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4956,8 +5363,8 @@ def test_documents_host_with_port(transport_name): ], ) def test_documents_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DocumentsClient( credentials=creds1, transport=transport_name, @@ -5034,7 +5441,7 @@ def test_documents_transport_channel_mtls_with_client_cert_source(transport_clas mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5109,7 +5516,7 @@ def test_documents_transport_channel_mtls_with_adc(transport_class): def test_documents_grpc_lro_client(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5126,7 +5533,7 @@ def test_documents_grpc_lro_client(): def test_documents_grpc_lro_async_client(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -5277,7 +5684,7 @@ def test_client_with_default_client_info(): transports.DocumentsTransport, "_prep_wrapped_messages" ) as prep: client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5287,7 +5694,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5296,7 +5703,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5311,7 +5718,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5341,7 +5748,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -5369,7 +5776,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5397,7 +5804,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -5425,7 +5832,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5455,7 +5862,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -5483,7 +5890,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5513,7 +5920,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -5541,7 +5948,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5569,7 +5976,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -5595,7 +6002,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5620,7 +6027,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5644,7 +6051,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5673,7 +6080,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5700,7 +6107,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5718,7 +6125,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5734,7 +6141,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5759,7 +6166,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5785,7 +6192,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5814,7 +6221,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5843,7 +6250,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5861,7 +6268,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5879,7 +6286,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5904,7 +6311,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5930,7 +6337,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5959,7 +6366,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5988,7 +6395,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6006,7 +6413,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6024,7 +6431,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6049,7 +6456,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6075,7 +6482,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6104,7 +6511,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6133,7 +6540,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6151,7 +6558,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6169,7 +6576,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6194,7 +6601,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6219,7 +6626,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = DocumentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = DocumentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -6246,7 +6653,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = DocumentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = DocumentsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -6274,7 +6681,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6292,7 +6699,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = DocumentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6316,7 +6723,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -6333,7 +6740,7 @@ def test_client_ctx(): ] for transport in transports: client = DocumentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -6364,7 +6771,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py index 12fab2a96eff..a2c9abe82c45 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_entity_types.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -81,6 +81,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -107,6 +130,251 @@ def test__get_default_mtls_endpoint(): assert EntityTypesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert EntityTypesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EntityTypesClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EntityTypesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EntityTypesClient._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 EntityTypesClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EntityTypesClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EntityTypesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EntityTypesClient._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 EntityTypesClient._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 EntityTypesClient._get_client_cert_source(None, False) is None + assert ( + EntityTypesClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + EntityTypesClient._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 ( + EntityTypesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + EntityTypesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesClient), +) +@mock.patch.object( + EntityTypesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EntityTypesClient._DEFAULT_UNIVERSE + default_endpoint = EntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + EntityTypesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EntityTypesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EntityTypesClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + EntityTypesClient._get_api_endpoint(None, None, default_universe, "always") + == EntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EntityTypesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EntityTypesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + EntityTypesClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EntityTypesClient._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 ( + EntityTypesClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + EntityTypesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + EntityTypesClient._get_universe_domain(None, None) + == EntityTypesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EntityTypesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (EntityTypesClient, transports.EntityTypesGrpcTransport, "grpc"), + (EntityTypesClient, transports.EntityTypesRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -116,7 +384,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_entity_types_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -168,7 +436,7 @@ def test_entity_types_client_service_account_always_use_jwt( ], ) def test_entity_types_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -217,19 +485,23 @@ def test_entity_types_client_get_transport_class(): ], ) @mock.patch.object( - EntityTypesClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EntityTypesClient) + EntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesClient), ) @mock.patch.object( EntityTypesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EntityTypesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesAsyncClient), ) def test_entity_types_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(EntityTypesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -264,7 +536,9 @@ def test_entity_types_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, @@ -294,15 +568,23 @@ def test_entity_types_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") @@ -312,7 +594,9 @@ def test_entity_types_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", @@ -330,7 +614,9 @@ def test_entity_types_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, @@ -362,12 +648,14 @@ def test_entity_types_client_client_options( ], ) @mock.patch.object( - EntityTypesClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EntityTypesClient) + EntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesClient), ) @mock.patch.object( EntityTypesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EntityTypesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_entity_types_client_mtls_env_auto( @@ -390,7 +678,9 @@ def test_entity_types_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 @@ -422,7 +712,9 @@ def test_entity_types_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 @@ -456,7 +748,9 @@ def test_entity_types_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, @@ -542,6 +836,116 @@ def test_entity_types_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", [EntityTypesClient, EntityTypesAsyncClient]) +@mock.patch.object( + EntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesClient), +) +@mock.patch.object( + EntityTypesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EntityTypesAsyncClient), +) +def test_entity_types_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EntityTypesClient._DEFAULT_UNIVERSE + default_endpoint = EntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EntityTypesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -568,7 +972,9 @@ def test_entity_types_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, @@ -603,7 +1009,9 @@ def test_entity_types_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, @@ -656,7 +1064,9 @@ def test_entity_types_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, @@ -673,8 +1083,8 @@ def test_entity_types_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -706,7 +1116,7 @@ def test_entity_types_client_create_channel_credentials_file( ) def test_list_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -738,7 +1148,7 @@ def test_list_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -757,7 +1167,7 @@ async def test_list_entity_types_async( transport: str = "grpc_asyncio", request_type=entity_type.ListEntityTypesRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -794,7 +1204,7 @@ async def test_list_entity_types_async_from_dict(): def test_list_entity_types_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -826,7 +1236,7 @@ def test_list_entity_types_field_headers(): @pytest.mark.asyncio async def test_list_entity_types_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -859,7 +1269,7 @@ async def test_list_entity_types_field_headers_async(): def test_list_entity_types_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -889,7 +1299,7 @@ def test_list_entity_types_flattened(): def test_list_entity_types_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -905,7 +1315,7 @@ def test_list_entity_types_flattened_error(): @pytest.mark.asyncio async def test_list_entity_types_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -940,7 +1350,7 @@ async def test_list_entity_types_flattened_async(): @pytest.mark.asyncio async def test_list_entity_types_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -955,7 +1365,7 @@ async def test_list_entity_types_flattened_error_async(): def test_list_entity_types_pager(transport_name: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1007,7 +1417,7 @@ def test_list_entity_types_pager(transport_name: str = "grpc"): def test_list_entity_types_pages(transport_name: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1051,7 +1461,7 @@ def test_list_entity_types_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_entity_types_async_pager(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1103,7 +1513,7 @@ async def test_list_entity_types_async_pager(): @pytest.mark.asyncio async def test_list_entity_types_async_pages(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1160,7 +1570,7 @@ async def test_list_entity_types_async_pages(): ) def test_get_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1201,7 +1611,7 @@ def test_get_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1218,7 +1628,7 @@ async def test_get_entity_type_async( transport: str = "grpc_asyncio", request_type=entity_type.GetEntityTypeRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1264,7 +1674,7 @@ async def test_get_entity_type_async_from_dict(): def test_get_entity_type_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1294,7 +1704,7 @@ def test_get_entity_type_field_headers(): @pytest.mark.asyncio async def test_get_entity_type_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1325,7 +1735,7 @@ async def test_get_entity_type_field_headers_async(): def test_get_entity_type_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1353,7 +1763,7 @@ def test_get_entity_type_flattened(): def test_get_entity_type_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1369,7 +1779,7 @@ def test_get_entity_type_flattened_error(): @pytest.mark.asyncio async def test_get_entity_type_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1402,7 +1812,7 @@ async def test_get_entity_type_flattened_async(): @pytest.mark.asyncio async def test_get_entity_type_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1424,7 +1834,7 @@ async def test_get_entity_type_flattened_error_async(): ) def test_create_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1467,7 +1877,7 @@ def test_create_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1487,7 +1897,7 @@ async def test_create_entity_type_async( request_type=gcd_entity_type.CreateEntityTypeRequest, ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1535,7 +1945,7 @@ async def test_create_entity_type_async_from_dict(): def test_create_entity_type_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1567,7 +1977,7 @@ def test_create_entity_type_field_headers(): @pytest.mark.asyncio async def test_create_entity_type_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1600,7 +2010,7 @@ async def test_create_entity_type_field_headers_async(): def test_create_entity_type_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1634,7 +2044,7 @@ def test_create_entity_type_flattened(): def test_create_entity_type_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1651,7 +2061,7 @@ def test_create_entity_type_flattened_error(): @pytest.mark.asyncio async def test_create_entity_type_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1690,7 +2100,7 @@ async def test_create_entity_type_flattened_async(): @pytest.mark.asyncio async def test_create_entity_type_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1713,7 +2123,7 @@ async def test_create_entity_type_flattened_error_async(): ) def test_update_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1756,7 +2166,7 @@ def test_update_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1776,7 +2186,7 @@ async def test_update_entity_type_async( request_type=gcd_entity_type.UpdateEntityTypeRequest, ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1824,7 +2234,7 @@ async def test_update_entity_type_async_from_dict(): def test_update_entity_type_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1856,7 +2266,7 @@ def test_update_entity_type_field_headers(): @pytest.mark.asyncio async def test_update_entity_type_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1889,7 +2299,7 @@ async def test_update_entity_type_field_headers_async(): def test_update_entity_type_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1923,7 +2333,7 @@ def test_update_entity_type_flattened(): def test_update_entity_type_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1940,7 +2350,7 @@ def test_update_entity_type_flattened_error(): @pytest.mark.asyncio async def test_update_entity_type_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1979,7 +2389,7 @@ async def test_update_entity_type_flattened_async(): @pytest.mark.asyncio async def test_update_entity_type_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2002,7 +2412,7 @@ async def test_update_entity_type_flattened_error_async(): ) def test_delete_entity_type(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2031,7 +2441,7 @@ def test_delete_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2050,7 +2460,7 @@ async def test_delete_entity_type_async( transport: str = "grpc_asyncio", request_type=entity_type.DeleteEntityTypeRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2082,7 +2492,7 @@ async def test_delete_entity_type_async_from_dict(): def test_delete_entity_type_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2114,7 +2524,7 @@ def test_delete_entity_type_field_headers(): @pytest.mark.asyncio async def test_delete_entity_type_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2145,7 +2555,7 @@ async def test_delete_entity_type_field_headers_async(): def test_delete_entity_type_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2171,7 +2581,7 @@ def test_delete_entity_type_flattened(): def test_delete_entity_type_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2186,7 +2596,7 @@ def test_delete_entity_type_flattened_error(): @pytest.mark.asyncio async def test_delete_entity_type_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2215,7 +2625,7 @@ async def test_delete_entity_type_flattened_async(): @pytest.mark.asyncio async def test_delete_entity_type_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2236,7 +2646,7 @@ async def test_delete_entity_type_flattened_error_async(): ) def test_batch_update_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2265,7 +2675,7 @@ def test_batch_update_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2285,7 +2695,7 @@ async def test_batch_update_entity_types_async( request_type=entity_type.BatchUpdateEntityTypesRequest, ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2319,7 +2729,7 @@ async def test_batch_update_entity_types_async_from_dict(): def test_batch_update_entity_types_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2351,7 +2761,7 @@ def test_batch_update_entity_types_field_headers(): @pytest.mark.asyncio async def test_batch_update_entity_types_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2391,7 +2801,7 @@ async def test_batch_update_entity_types_field_headers_async(): ) def test_batch_delete_entity_types(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2420,7 +2830,7 @@ def test_batch_delete_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2440,7 +2850,7 @@ async def test_batch_delete_entity_types_async( request_type=entity_type.BatchDeleteEntityTypesRequest, ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2474,7 +2884,7 @@ async def test_batch_delete_entity_types_async_from_dict(): def test_batch_delete_entity_types_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2506,7 +2916,7 @@ def test_batch_delete_entity_types_field_headers(): @pytest.mark.asyncio async def test_batch_delete_entity_types_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2539,7 +2949,7 @@ async def test_batch_delete_entity_types_field_headers_async(): def test_batch_delete_entity_types_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2569,7 +2979,7 @@ def test_batch_delete_entity_types_flattened(): def test_batch_delete_entity_types_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2585,7 +2995,7 @@ def test_batch_delete_entity_types_flattened_error(): @pytest.mark.asyncio async def test_batch_delete_entity_types_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2620,7 +3030,7 @@ async def test_batch_delete_entity_types_flattened_async(): @pytest.mark.asyncio async def test_batch_delete_entity_types_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2642,7 +3052,7 @@ async def test_batch_delete_entity_types_flattened_error_async(): ) def test_batch_create_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2671,7 +3081,7 @@ def test_batch_create_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2690,7 +3100,7 @@ async def test_batch_create_entities_async( transport: str = "grpc_asyncio", request_type=entity_type.BatchCreateEntitiesRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2724,7 +3134,7 @@ async def test_batch_create_entities_async_from_dict(): def test_batch_create_entities_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2756,7 +3166,7 @@ def test_batch_create_entities_field_headers(): @pytest.mark.asyncio async def test_batch_create_entities_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2789,7 +3199,7 @@ async def test_batch_create_entities_field_headers_async(): def test_batch_create_entities_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2823,7 +3233,7 @@ def test_batch_create_entities_flattened(): def test_batch_create_entities_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2840,7 +3250,7 @@ def test_batch_create_entities_flattened_error(): @pytest.mark.asyncio async def test_batch_create_entities_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2879,7 +3289,7 @@ async def test_batch_create_entities_flattened_async(): @pytest.mark.asyncio async def test_batch_create_entities_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2902,7 +3312,7 @@ async def test_batch_create_entities_flattened_error_async(): ) def test_batch_update_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2931,7 +3341,7 @@ def test_batch_update_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2950,7 +3360,7 @@ async def test_batch_update_entities_async( transport: str = "grpc_asyncio", request_type=entity_type.BatchUpdateEntitiesRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2984,7 +3394,7 @@ async def test_batch_update_entities_async_from_dict(): def test_batch_update_entities_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3016,7 +3426,7 @@ def test_batch_update_entities_field_headers(): @pytest.mark.asyncio async def test_batch_update_entities_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3049,7 +3459,7 @@ async def test_batch_update_entities_field_headers_async(): def test_batch_update_entities_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3083,7 +3493,7 @@ def test_batch_update_entities_flattened(): def test_batch_update_entities_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3100,7 +3510,7 @@ def test_batch_update_entities_flattened_error(): @pytest.mark.asyncio async def test_batch_update_entities_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3139,7 +3549,7 @@ async def test_batch_update_entities_flattened_async(): @pytest.mark.asyncio async def test_batch_update_entities_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3162,7 +3572,7 @@ async def test_batch_update_entities_flattened_error_async(): ) def test_batch_delete_entities(request_type, transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3191,7 +3601,7 @@ def test_batch_delete_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3210,7 +3620,7 @@ async def test_batch_delete_entities_async( transport: str = "grpc_asyncio", request_type=entity_type.BatchDeleteEntitiesRequest ): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3244,7 +3654,7 @@ async def test_batch_delete_entities_async_from_dict(): def test_batch_delete_entities_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3276,7 +3686,7 @@ def test_batch_delete_entities_field_headers(): @pytest.mark.asyncio async def test_batch_delete_entities_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3309,7 +3719,7 @@ async def test_batch_delete_entities_field_headers_async(): def test_batch_delete_entities_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3343,7 +3753,7 @@ def test_batch_delete_entities_flattened(): def test_batch_delete_entities_flattened_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3360,7 +3770,7 @@ def test_batch_delete_entities_flattened_error(): @pytest.mark.asyncio async def test_batch_delete_entities_flattened_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3399,7 +3809,7 @@ async def test_batch_delete_entities_flattened_async(): @pytest.mark.asyncio async def test_batch_delete_entities_flattened_error_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3422,7 +3832,7 @@ async def test_batch_delete_entities_flattened_error_async(): ) def test_list_entity_types_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3473,7 +3883,7 @@ def test_list_entity_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3482,7 +3892,7 @@ def test_list_entity_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_entity_types._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3499,7 +3909,7 @@ def test_list_entity_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3541,7 +3951,7 @@ def test_list_entity_types_rest_required_fields( def test_list_entity_types_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_entity_types._get_unset_required_fields({}) @@ -3560,7 +3970,7 @@ def test_list_entity_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_entity_types_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -3618,7 +4028,7 @@ def test_list_entity_types_rest_bad_request( transport: str = "rest", request_type=entity_type.ListEntityTypesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3640,7 +4050,7 @@ def test_list_entity_types_rest_bad_request( def test_list_entity_types_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3682,7 +4092,7 @@ def test_list_entity_types_rest_flattened(): def test_list_entity_types_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3698,7 +4108,7 @@ def test_list_entity_types_rest_flattened_error(transport: str = "rest"): def test_list_entity_types_rest_pager(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3768,7 +4178,7 @@ def test_list_entity_types_rest_pager(transport: str = "rest"): ) def test_get_entity_type_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3830,7 +4240,7 @@ def test_get_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3839,7 +4249,7 @@ def test_get_entity_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_entity_type._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("language_code",)) @@ -3850,7 +4260,7 @@ def test_get_entity_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3892,7 +4302,7 @@ def test_get_entity_type_rest_required_fields( def test_get_entity_type_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_entity_type._get_unset_required_fields({}) @@ -3902,7 +4312,7 @@ def test_get_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_entity_type_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -3960,7 +4370,7 @@ def test_get_entity_type_rest_bad_request( transport: str = "rest", request_type=entity_type.GetEntityTypeRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3982,7 +4392,7 @@ def test_get_entity_type_rest_bad_request( def test_get_entity_type_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4024,7 +4434,7 @@ def test_get_entity_type_rest_flattened(): def test_get_entity_type_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4040,7 +4450,7 @@ def test_get_entity_type_rest_flattened_error(transport: str = "rest"): def test_get_entity_type_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4053,7 +4463,7 @@ def test_get_entity_type_rest_error(): ) def test_create_entity_type_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4192,7 +4602,7 @@ def test_create_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4201,7 +4611,7 @@ def test_create_entity_type_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_entity_type._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("language_code",)) @@ -4212,7 +4622,7 @@ def test_create_entity_type_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4255,7 +4665,7 @@ def test_create_entity_type_rest_required_fields( def test_create_entity_type_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_entity_type._get_unset_required_fields({}) @@ -4273,7 +4683,7 @@ def test_create_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_entity_type_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -4331,7 +4741,7 @@ def test_create_entity_type_rest_bad_request( transport: str = "rest", request_type=gcd_entity_type.CreateEntityTypeRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4353,7 +4763,7 @@ def test_create_entity_type_rest_bad_request( def test_create_entity_type_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4396,7 +4806,7 @@ def test_create_entity_type_rest_flattened(): def test_create_entity_type_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4413,7 +4823,7 @@ def test_create_entity_type_rest_flattened_error(transport: str = "rest"): def test_create_entity_type_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4426,7 +4836,7 @@ def test_create_entity_type_rest_error(): ) def test_update_entity_type_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4566,14 +4976,14 @@ def test_update_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_entity_type._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4587,7 +4997,7 @@ def test_update_entity_type_rest_required_fields( # verify required fields with non-default values are left alone client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4630,7 +5040,7 @@ def test_update_entity_type_rest_required_fields( def test_update_entity_type_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_entity_type._get_unset_required_fields({}) @@ -4648,7 +5058,7 @@ def test_update_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_entity_type_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -4706,7 +5116,7 @@ def test_update_entity_type_rest_bad_request( transport: str = "rest", request_type=gcd_entity_type.UpdateEntityTypeRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4730,7 +5140,7 @@ def test_update_entity_type_rest_bad_request( def test_update_entity_type_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4776,7 +5186,7 @@ def test_update_entity_type_rest_flattened(): def test_update_entity_type_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4793,7 +5203,7 @@ def test_update_entity_type_rest_flattened_error(transport: str = "rest"): def test_update_entity_type_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4806,7 +5216,7 @@ def test_update_entity_type_rest_error(): ) def test_delete_entity_type_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4852,7 +5262,7 @@ def test_delete_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4861,7 +5271,7 @@ def test_delete_entity_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4870,7 +5280,7 @@ def test_delete_entity_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4909,7 +5319,7 @@ def test_delete_entity_type_rest_required_fields( def test_delete_entity_type_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_entity_type._get_unset_required_fields({}) @@ -4919,7 +5329,7 @@ def test_delete_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_entity_type_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -4969,7 +5379,7 @@ def test_delete_entity_type_rest_bad_request( transport: str = "rest", request_type=entity_type.DeleteEntityTypeRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4991,7 +5401,7 @@ def test_delete_entity_type_rest_bad_request( def test_delete_entity_type_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5030,7 +5440,7 @@ def test_delete_entity_type_rest_flattened(): def test_delete_entity_type_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5045,7 +5455,7 @@ def test_delete_entity_type_rest_flattened_error(transport: str = "rest"): def test_delete_entity_type_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5058,7 +5468,7 @@ def test_delete_entity_type_rest_error(): ) def test_batch_update_entity_types_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5104,7 +5514,7 @@ def test_batch_update_entity_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5113,7 +5523,7 @@ def test_batch_update_entity_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5122,7 +5532,7 @@ def test_batch_update_entity_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5162,7 +5572,7 @@ def test_batch_update_entity_types_rest_required_fields( def test_batch_update_entity_types_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_update_entity_types._get_unset_required_fields({}) @@ -5172,7 +5582,7 @@ def test_batch_update_entity_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_update_entity_types_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -5232,7 +5642,7 @@ def test_batch_update_entity_types_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchUpdateEntityTypesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5254,7 +5664,7 @@ def test_batch_update_entity_types_rest_bad_request( def test_batch_update_entity_types_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5267,7 +5677,7 @@ def test_batch_update_entity_types_rest_error(): ) def test_batch_delete_entity_types_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5314,7 +5724,7 @@ def test_batch_delete_entity_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5324,7 +5734,7 @@ def test_batch_delete_entity_types_rest_required_fields( jsonified_request["entityTypeNames"] = "entity_type_names_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5335,7 +5745,7 @@ def test_batch_delete_entity_types_rest_required_fields( assert jsonified_request["entityTypeNames"] == "entity_type_names_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5375,7 +5785,7 @@ def test_batch_delete_entity_types_rest_required_fields( def test_batch_delete_entity_types_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_delete_entity_types._get_unset_required_fields({}) @@ -5393,7 +5803,7 @@ def test_batch_delete_entity_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_delete_entity_types_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -5453,7 +5863,7 @@ def test_batch_delete_entity_types_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchDeleteEntityTypesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5475,7 +5885,7 @@ def test_batch_delete_entity_types_rest_bad_request( def test_batch_delete_entity_types_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5516,7 +5926,7 @@ def test_batch_delete_entity_types_rest_flattened(): def test_batch_delete_entity_types_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5532,7 +5942,7 @@ def test_batch_delete_entity_types_rest_flattened_error(transport: str = "rest") def test_batch_delete_entity_types_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5545,7 +5955,7 @@ def test_batch_delete_entity_types_rest_error(): ) def test_batch_create_entities_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5591,7 +6001,7 @@ def test_batch_create_entities_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_create_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5600,7 +6010,7 @@ def test_batch_create_entities_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_create_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5609,7 +6019,7 @@ def test_batch_create_entities_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5649,7 +6059,7 @@ def test_batch_create_entities_rest_required_fields( def test_batch_create_entities_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_create_entities._get_unset_required_fields({}) @@ -5667,7 +6077,7 @@ def test_batch_create_entities_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_create_entities_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -5727,7 +6137,7 @@ def test_batch_create_entities_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchCreateEntitiesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5749,7 +6159,7 @@ def test_batch_create_entities_rest_bad_request( def test_batch_create_entities_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5791,7 +6201,7 @@ def test_batch_create_entities_rest_flattened(): def test_batch_create_entities_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5808,7 +6218,7 @@ def test_batch_create_entities_rest_flattened_error(transport: str = "rest"): def test_batch_create_entities_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5821,7 +6231,7 @@ def test_batch_create_entities_rest_error(): ) def test_batch_update_entities_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5867,7 +6277,7 @@ def test_batch_update_entities_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5876,7 +6286,7 @@ def test_batch_update_entities_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5885,7 +6295,7 @@ def test_batch_update_entities_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5925,7 +6335,7 @@ def test_batch_update_entities_rest_required_fields( def test_batch_update_entities_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_update_entities._get_unset_required_fields({}) @@ -5943,7 +6353,7 @@ def test_batch_update_entities_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_update_entities_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -6003,7 +6413,7 @@ def test_batch_update_entities_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchUpdateEntitiesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6025,7 +6435,7 @@ def test_batch_update_entities_rest_bad_request( def test_batch_update_entities_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6067,7 +6477,7 @@ def test_batch_update_entities_rest_flattened(): def test_batch_update_entities_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6084,7 +6494,7 @@ def test_batch_update_entities_rest_flattened_error(transport: str = "rest"): def test_batch_update_entities_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6097,7 +6507,7 @@ def test_batch_update_entities_rest_error(): ) def test_batch_delete_entities_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6144,7 +6554,7 @@ def test_batch_delete_entities_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6154,7 +6564,7 @@ def test_batch_delete_entities_rest_required_fields( jsonified_request["entityValues"] = "entity_values_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_entities._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6165,7 +6575,7 @@ def test_batch_delete_entities_rest_required_fields( assert jsonified_request["entityValues"] == "entity_values_value" client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6205,7 +6615,7 @@ def test_batch_delete_entities_rest_required_fields( def test_batch_delete_entities_rest_unset_required_fields(): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_delete_entities._get_unset_required_fields({}) @@ -6223,7 +6633,7 @@ def test_batch_delete_entities_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_delete_entities_rest_interceptors(null_interceptor): transport = transports.EntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EntityTypesRestInterceptor(), @@ -6283,7 +6693,7 @@ def test_batch_delete_entities_rest_bad_request( transport: str = "rest", request_type=entity_type.BatchDeleteEntitiesRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6305,7 +6715,7 @@ def test_batch_delete_entities_rest_bad_request( def test_batch_delete_entities_rest_flattened(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6347,7 +6757,7 @@ def test_batch_delete_entities_rest_flattened(): def test_batch_delete_entities_rest_flattened_error(transport: str = "rest"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6364,24 +6774,24 @@ def test_batch_delete_entities_rest_flattened_error(transport: str = "rest"): def test_batch_delete_entities_rest_error(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EntityTypesClient( @@ -6391,7 +6801,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -6402,16 +6812,17 @@ 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 = EntityTypesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EntityTypesClient( @@ -6423,7 +6834,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EntityTypesClient(transport=transport) assert client.transport is transport @@ -6432,13 +6843,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EntityTypesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -6455,7 +6866,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -6469,7 +6880,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = EntityTypesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -6477,7 +6888,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -6489,7 +6900,7 @@ def test_entity_types_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EntityTypesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -6501,7 +6912,7 @@ def test_entity_types_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EntityTypesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6552,7 +6963,7 @@ def test_entity_types_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EntityTypesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6574,7 +6985,7 @@ def test_entity_types_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.entity_types.transports.EntityTypesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EntityTypesTransport() adc.assert_called_once() @@ -6582,7 +6993,7 @@ def test_entity_types_base_transport_with_adc(): def test_entity_types_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EntityTypesClient() adc.assert_called_once_with( scopes=None, @@ -6605,7 +7016,7 @@ def test_entity_types_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -6655,7 +7066,7 @@ def test_entity_types_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6683,7 +7094,7 @@ def test_entity_types_transport_create_channel(transport_class, grpc_helpers): [transports.EntityTypesGrpcTransport, transports.EntityTypesGrpcAsyncIOTransport], ) def test_entity_types_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6721,7 +7132,7 @@ def test_entity_types_grpc_transport_client_cert_source_for_mtls(transport_class def test_entity_types_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -6733,7 +7144,7 @@ def test_entity_types_http_transport_client_cert_source_for_mtls(): def test_entity_types_rest_lro_client(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -6758,7 +7169,7 @@ def test_entity_types_rest_lro_client(): ) def test_entity_types_host_no_port(transport_name): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -6781,7 +7192,7 @@ def test_entity_types_host_no_port(transport_name): ) def test_entity_types_host_with_port(transport_name): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -6801,8 +7212,8 @@ def test_entity_types_host_with_port(transport_name): ], ) def test_entity_types_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EntityTypesClient( credentials=creds1, transport=transport_name, @@ -6888,7 +7299,7 @@ def test_entity_types_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6963,7 +7374,7 @@ def test_entity_types_transport_channel_mtls_with_adc(transport_class): def test_entity_types_grpc_lro_client(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -6980,7 +7391,7 @@ def test_entity_types_grpc_lro_client(): def test_entity_types_grpc_lro_async_client(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -7128,7 +7539,7 @@ def test_client_with_default_client_info(): transports.EntityTypesTransport, "_prep_wrapped_messages" ) as prep: client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7138,7 +7549,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EntityTypesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7147,7 +7558,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -7162,7 +7573,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7192,7 +7603,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -7220,7 +7631,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7248,7 +7659,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -7276,7 +7687,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7306,7 +7717,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -7334,7 +7745,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7364,7 +7775,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -7392,7 +7803,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7420,7 +7831,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -7446,7 +7857,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7471,7 +7882,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7495,7 +7906,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7524,7 +7935,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7551,7 +7962,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7569,7 +7980,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7585,7 +7996,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7610,7 +8021,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7636,7 +8047,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7665,7 +8076,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7694,7 +8105,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7712,7 +8123,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7730,7 +8141,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7755,7 +8166,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7781,7 +8192,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7810,7 +8221,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7839,7 +8250,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7857,7 +8268,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7875,7 +8286,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7900,7 +8311,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7926,7 +8337,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7955,7 +8366,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7984,7 +8395,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8002,7 +8413,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8020,7 +8431,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8045,7 +8456,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8070,7 +8481,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = EntityTypesClient(credentials=ga_credentials.AnonymousCredentials()) + client = EntityTypesClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -8097,7 +8508,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = EntityTypesAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = EntityTypesAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -8125,7 +8538,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8143,7 +8556,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = EntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8167,7 +8580,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -8184,7 +8597,7 @@ def test_client_ctx(): ] for transport in transports: client = EntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -8215,7 +8628,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_environments.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_environments.py index ba90f61e87b7..69e57eed31d4 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_environments.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_environments.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -70,6 +70,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -96,6 +119,255 @@ def test__get_default_mtls_endpoint(): assert EnvironmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert EnvironmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EnvironmentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EnvironmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EnvironmentsClient._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 EnvironmentsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EnvironmentsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EnvironmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EnvironmentsClient._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 EnvironmentsClient._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 EnvironmentsClient._get_client_cert_source(None, False) is None + assert ( + EnvironmentsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + EnvironmentsClient._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 ( + EnvironmentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + EnvironmentsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EnvironmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsClient), +) +@mock.patch.object( + EnvironmentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EnvironmentsClient._DEFAULT_UNIVERSE + default_endpoint = EnvironmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EnvironmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + EnvironmentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EnvironmentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EnvironmentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + EnvironmentsClient._get_api_endpoint(None, None, default_universe, "always") + == EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EnvironmentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EnvironmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EnvironmentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + EnvironmentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EnvironmentsClient._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 ( + EnvironmentsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + EnvironmentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + EnvironmentsClient._get_universe_domain(None, None) + == EnvironmentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EnvironmentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (EnvironmentsClient, transports.EnvironmentsGrpcTransport, "grpc"), + (EnvironmentsClient, transports.EnvironmentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -105,7 +377,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_environments_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -157,7 +429,7 @@ def test_environments_client_service_account_always_use_jwt( ], ) def test_environments_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -206,19 +478,23 @@ def test_environments_client_get_transport_class(): ], ) @mock.patch.object( - EnvironmentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EnvironmentsClient) + EnvironmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsClient), ) @mock.patch.object( EnvironmentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EnvironmentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsAsyncClient), ) def test_environments_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(EnvironmentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -253,7 +529,9 @@ def test_environments_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 +561,23 @@ def test_environments_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 +587,9 @@ def test_environments_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 +607,9 @@ def test_environments_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 +641,14 @@ def test_environments_client_client_options( ], ) @mock.patch.object( - EnvironmentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EnvironmentsClient) + EnvironmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsClient), ) @mock.patch.object( EnvironmentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EnvironmentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_environments_client_mtls_env_auto( @@ -379,7 +671,9 @@ def test_environments_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 +705,9 @@ def test_environments_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 +741,9 @@ def test_environments_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 +829,116 @@ def test_environments_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", [EnvironmentsClient, EnvironmentsAsyncClient]) +@mock.patch.object( + EnvironmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsClient), +) +@mock.patch.object( + EnvironmentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnvironmentsAsyncClient), +) +def test_environments_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EnvironmentsClient._DEFAULT_UNIVERSE + default_endpoint = EnvironmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EnvironmentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -557,7 +965,9 @@ def test_environments_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, @@ -597,7 +1007,9 @@ def test_environments_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, @@ -655,7 +1067,9 @@ def test_environments_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, @@ -672,8 +1086,8 @@ def test_environments_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -705,7 +1119,7 @@ def test_environments_client_create_channel_credentials_file( ) def test_list_environments(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -737,7 +1151,7 @@ def test_list_environments_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -756,7 +1170,7 @@ async def test_list_environments_async( transport: str = "grpc_asyncio", request_type=environment.ListEnvironmentsRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -793,7 +1207,7 @@ async def test_list_environments_async_from_dict(): def test_list_environments_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -825,7 +1239,7 @@ def test_list_environments_field_headers(): @pytest.mark.asyncio async def test_list_environments_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -858,7 +1272,7 @@ async def test_list_environments_field_headers_async(): def test_list_environments_flattened(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -884,7 +1298,7 @@ def test_list_environments_flattened(): def test_list_environments_flattened_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -899,7 +1313,7 @@ def test_list_environments_flattened_error(): @pytest.mark.asyncio async def test_list_environments_flattened_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -930,7 +1344,7 @@ async def test_list_environments_flattened_async(): @pytest.mark.asyncio async def test_list_environments_flattened_error_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -944,7 +1358,7 @@ async def test_list_environments_flattened_error_async(): def test_list_environments_pager(transport_name: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -996,7 +1410,7 @@ def test_list_environments_pager(transport_name: str = "grpc"): def test_list_environments_pages(transport_name: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1040,7 +1454,7 @@ def test_list_environments_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_environments_async_pager(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1092,7 +1506,7 @@ async def test_list_environments_async_pager(): @pytest.mark.asyncio async def test_list_environments_async_pages(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1149,7 +1563,7 @@ async def test_list_environments_async_pages(): ) def test_get_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1185,7 +1599,7 @@ def test_get_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1202,7 +1616,7 @@ async def test_get_environment_async( transport: str = "grpc_asyncio", request_type=environment.GetEnvironmentRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1243,7 +1657,7 @@ async def test_get_environment_async_from_dict(): def test_get_environment_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1273,7 +1687,7 @@ def test_get_environment_field_headers(): @pytest.mark.asyncio async def test_get_environment_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1311,7 +1725,7 @@ async def test_get_environment_field_headers_async(): ) def test_create_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1349,7 +1763,7 @@ def test_create_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1368,7 +1782,7 @@ async def test_create_environment_async( transport: str = "grpc_asyncio", request_type=environment.CreateEnvironmentRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1411,7 +1825,7 @@ async def test_create_environment_async_from_dict(): def test_create_environment_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1443,7 +1857,7 @@ def test_create_environment_field_headers(): @pytest.mark.asyncio async def test_create_environment_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1483,7 +1897,7 @@ async def test_create_environment_field_headers_async(): ) def test_update_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1521,7 +1935,7 @@ def test_update_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1540,7 +1954,7 @@ async def test_update_environment_async( transport: str = "grpc_asyncio", request_type=environment.UpdateEnvironmentRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1583,7 +1997,7 @@ async def test_update_environment_async_from_dict(): def test_update_environment_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1615,7 +2029,7 @@ def test_update_environment_field_headers(): @pytest.mark.asyncio async def test_update_environment_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1655,7 +2069,7 @@ async def test_update_environment_field_headers_async(): ) def test_delete_environment(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1684,7 +2098,7 @@ def test_delete_environment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1703,7 +2117,7 @@ async def test_delete_environment_async( transport: str = "grpc_asyncio", request_type=environment.DeleteEnvironmentRequest ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1735,7 +2149,7 @@ async def test_delete_environment_async_from_dict(): def test_delete_environment_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1767,7 +2181,7 @@ def test_delete_environment_field_headers(): @pytest.mark.asyncio async def test_delete_environment_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1805,7 +2219,7 @@ async def test_delete_environment_field_headers_async(): ) def test_get_environment_history(request_type, transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1839,7 +2253,7 @@ def test_get_environment_history_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1859,7 +2273,7 @@ async def test_get_environment_history_async( request_type=environment.GetEnvironmentHistoryRequest, ): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1898,7 +2312,7 @@ async def test_get_environment_history_async_from_dict(): def test_get_environment_history_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1930,7 +2344,7 @@ def test_get_environment_history_field_headers(): @pytest.mark.asyncio async def test_get_environment_history_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1963,7 +2377,7 @@ async def test_get_environment_history_field_headers_async(): def test_get_environment_history_pager(transport_name: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2015,7 +2429,7 @@ def test_get_environment_history_pager(transport_name: str = "grpc"): def test_get_environment_history_pages(transport_name: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2059,7 +2473,7 @@ def test_get_environment_history_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_get_environment_history_async_pager(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2113,7 +2527,7 @@ async def test_get_environment_history_async_pager(): @pytest.mark.asyncio async def test_get_environment_history_async_pages(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2170,7 +2584,7 @@ async def test_get_environment_history_async_pages(): ) def test_list_environments_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2221,7 +2635,7 @@ def test_list_environments_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_environments._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2230,7 +2644,7 @@ def test_list_environments_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_environments._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2246,7 +2660,7 @@ def test_list_environments_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2288,7 +2702,7 @@ def test_list_environments_rest_required_fields( def test_list_environments_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_environments._get_unset_required_fields({}) @@ -2306,7 +2720,7 @@ def test_list_environments_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_environments_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -2364,7 +2778,7 @@ def test_list_environments_rest_bad_request( transport: str = "rest", request_type=environment.ListEnvironmentsRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2386,7 +2800,7 @@ def test_list_environments_rest_bad_request( def test_list_environments_rest_flattened(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2428,7 +2842,7 @@ def test_list_environments_rest_flattened(): def test_list_environments_rest_flattened_error(transport: str = "rest"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2443,7 +2857,7 @@ def test_list_environments_rest_flattened_error(transport: str = "rest"): def test_list_environments_rest_pager(transport: str = "rest"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2513,7 +2927,7 @@ def test_list_environments_rest_pager(transport: str = "rest"): ) def test_get_environment_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2570,7 +2984,7 @@ def test_get_environment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2579,7 +2993,7 @@ def test_get_environment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2588,7 +3002,7 @@ def test_get_environment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2630,7 +3044,7 @@ def test_get_environment_rest_required_fields( def test_get_environment_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_environment._get_unset_required_fields({}) @@ -2640,7 +3054,7 @@ def test_get_environment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_environment_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -2698,7 +3112,7 @@ def test_get_environment_rest_bad_request( transport: str = "rest", request_type=environment.GetEnvironmentRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2720,7 +3134,7 @@ def test_get_environment_rest_bad_request( def test_get_environment_rest_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2733,7 +3147,7 @@ def test_get_environment_rest_error(): ) def test_create_environment_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2885,7 +3299,7 @@ def test_create_environment_rest_required_fields( assert "environmentId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2897,7 +3311,7 @@ def test_create_environment_rest_required_fields( jsonified_request["environmentId"] = "environment_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_environment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("environment_id",)) @@ -2910,7 +3324,7 @@ def test_create_environment_rest_required_fields( assert jsonified_request["environmentId"] == "environment_id_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2959,7 +3373,7 @@ def test_create_environment_rest_required_fields( def test_create_environment_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_environment._get_unset_required_fields({}) @@ -2978,7 +3392,7 @@ def test_create_environment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_environment_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -3036,7 +3450,7 @@ def test_create_environment_rest_bad_request( transport: str = "rest", request_type=environment.CreateEnvironmentRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3058,7 +3472,7 @@ def test_create_environment_rest_bad_request( def test_create_environment_rest_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3071,7 +3485,7 @@ def test_create_environment_rest_error(): ) def test_update_environment_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3222,14 +3636,14 @@ def test_update_environment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_environment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3243,7 +3657,7 @@ def test_update_environment_rest_required_fields( # verify required fields with non-default values are left alone client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3286,7 +3700,7 @@ def test_update_environment_rest_required_fields( def test_update_environment_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_environment._get_unset_required_fields({}) @@ -3309,7 +3723,7 @@ def test_update_environment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_environment_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -3367,7 +3781,7 @@ def test_update_environment_rest_bad_request( transport: str = "rest", request_type=environment.UpdateEnvironmentRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3391,7 +3805,7 @@ def test_update_environment_rest_bad_request( def test_update_environment_rest_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3404,7 +3818,7 @@ def test_update_environment_rest_error(): ) def test_delete_environment_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3450,7 +3864,7 @@ def test_delete_environment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3459,7 +3873,7 @@ def test_delete_environment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_environment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3468,7 +3882,7 @@ def test_delete_environment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3507,7 +3921,7 @@ def test_delete_environment_rest_required_fields( def test_delete_environment_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_environment._get_unset_required_fields({}) @@ -3517,7 +3931,7 @@ def test_delete_environment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_environment_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -3567,7 +3981,7 @@ def test_delete_environment_rest_bad_request( transport: str = "rest", request_type=environment.DeleteEnvironmentRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3589,7 +4003,7 @@ def test_delete_environment_rest_bad_request( def test_delete_environment_rest_error(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3602,7 +4016,7 @@ def test_delete_environment_rest_error(): ) def test_get_environment_history_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3655,7 +4069,7 @@ def test_get_environment_history_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_environment_history._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3664,7 +4078,7 @@ def test_get_environment_history_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_environment_history._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3680,7 +4094,7 @@ def test_get_environment_history_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3722,7 +4136,7 @@ def test_get_environment_history_rest_required_fields( def test_get_environment_history_rest_unset_required_fields(): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_environment_history._get_unset_required_fields({}) @@ -3740,7 +4154,7 @@ def test_get_environment_history_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_environment_history_rest_interceptors(null_interceptor): transport = transports.EnvironmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnvironmentsRestInterceptor(), @@ -3798,7 +4212,7 @@ def test_get_environment_history_rest_bad_request( transport: str = "rest", request_type=environment.GetEnvironmentHistoryRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3820,7 +4234,7 @@ def test_get_environment_history_rest_bad_request( def test_get_environment_history_rest_pager(transport: str = "rest"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3882,17 +4296,17 @@ def test_get_environment_history_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EnvironmentsClient( @@ -3902,7 +4316,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3913,16 +4327,17 @@ 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 = EnvironmentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EnvironmentsClient( @@ -3934,7 +4349,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EnvironmentsClient(transport=transport) assert client.transport is transport @@ -3943,13 +4358,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EnvironmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EnvironmentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3966,7 +4381,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3980,7 +4395,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = EnvironmentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3988,7 +4403,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4000,7 +4415,7 @@ def test_environments_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EnvironmentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4012,7 +4427,7 @@ def test_environments_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EnvironmentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4054,7 +4469,7 @@ def test_environments_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EnvironmentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4076,7 +4491,7 @@ def test_environments_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.environments.transports.EnvironmentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EnvironmentsTransport() adc.assert_called_once() @@ -4084,7 +4499,7 @@ def test_environments_base_transport_with_adc(): def test_environments_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EnvironmentsClient() adc.assert_called_once_with( scopes=None, @@ -4107,7 +4522,7 @@ def test_environments_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4157,7 +4572,7 @@ def test_environments_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4185,7 +4600,7 @@ def test_environments_transport_create_channel(transport_class, grpc_helpers): [transports.EnvironmentsGrpcTransport, transports.EnvironmentsGrpcAsyncIOTransport], ) def test_environments_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4223,7 +4638,7 @@ def test_environments_grpc_transport_client_cert_source_for_mtls(transport_class def test_environments_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4243,7 +4658,7 @@ def test_environments_http_transport_client_cert_source_for_mtls(): ) def test_environments_host_no_port(transport_name): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4266,7 +4681,7 @@ def test_environments_host_no_port(transport_name): ) def test_environments_host_with_port(transport_name): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4286,8 +4701,8 @@ def test_environments_host_with_port(transport_name): ], ) def test_environments_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EnvironmentsClient( credentials=creds1, transport=transport_name, @@ -4361,7 +4776,7 @@ def test_environments_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4610,7 +5025,7 @@ def test_client_with_default_client_info(): transports.EnvironmentsTransport, "_prep_wrapped_messages" ) as prep: client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4620,7 +5035,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EnvironmentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4629,7 +5044,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4644,7 +5059,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4674,7 +5089,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4702,7 +5117,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4730,7 +5145,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4758,7 +5173,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4788,7 +5203,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4816,7 +5231,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4846,7 +5261,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4874,7 +5289,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4902,7 +5317,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4928,7 +5343,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4953,7 +5368,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4977,7 +5392,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5006,7 +5421,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5033,7 +5448,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5051,7 +5466,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5067,7 +5482,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5092,7 +5507,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5118,7 +5533,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5147,7 +5562,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5176,7 +5591,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5194,7 +5609,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5212,7 +5627,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5237,7 +5652,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5263,7 +5678,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5292,7 +5707,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5321,7 +5736,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5339,7 +5754,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5357,7 +5772,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5382,7 +5797,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5408,7 +5823,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5437,7 +5852,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5466,7 +5881,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5484,7 +5899,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5502,7 +5917,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5527,7 +5942,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5552,7 +5967,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = EnvironmentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = EnvironmentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5579,7 +5994,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = EnvironmentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = EnvironmentsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5607,7 +6024,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5625,7 +6042,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = EnvironmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5649,7 +6066,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5666,7 +6083,7 @@ def test_client_ctx(): ] for transport in transports: client = EnvironmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5697,7 +6114,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py index d0e6d66551fd..63f7183ef82b 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_fulfillments.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -69,6 +69,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -95,6 +118,255 @@ def test__get_default_mtls_endpoint(): assert FulfillmentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert FulfillmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert FulfillmentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert FulfillmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + FulfillmentsClient._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 FulfillmentsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert FulfillmentsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert FulfillmentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + FulfillmentsClient._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 FulfillmentsClient._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 FulfillmentsClient._get_client_cert_source(None, False) is None + assert ( + FulfillmentsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + FulfillmentsClient._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 ( + FulfillmentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + FulfillmentsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + FulfillmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsClient), +) +@mock.patch.object( + FulfillmentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = FulfillmentsClient._DEFAULT_UNIVERSE + default_endpoint = FulfillmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = FulfillmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + FulfillmentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + FulfillmentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + FulfillmentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + FulfillmentsClient._get_api_endpoint(None, None, default_universe, "always") + == FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + FulfillmentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == FulfillmentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + FulfillmentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + FulfillmentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + FulfillmentsClient._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 ( + FulfillmentsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + FulfillmentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + FulfillmentsClient._get_universe_domain(None, None) + == FulfillmentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + FulfillmentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (FulfillmentsClient, transports.FulfillmentsGrpcTransport, "grpc"), + (FulfillmentsClient, transports.FulfillmentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -104,7 +376,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_fulfillments_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -156,7 +428,7 @@ def test_fulfillments_client_service_account_always_use_jwt( ], ) def test_fulfillments_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -205,19 +477,23 @@ def test_fulfillments_client_get_transport_class(): ], ) @mock.patch.object( - FulfillmentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(FulfillmentsClient) + FulfillmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsClient), ) @mock.patch.object( FulfillmentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(FulfillmentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsAsyncClient), ) def test_fulfillments_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(FulfillmentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -252,7 +528,9 @@ def test_fulfillments_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, @@ -282,15 +560,23 @@ def test_fulfillments_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") @@ -300,7 +586,9 @@ def test_fulfillments_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", @@ -318,7 +606,9 @@ def test_fulfillments_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, @@ -350,12 +640,14 @@ def test_fulfillments_client_client_options( ], ) @mock.patch.object( - FulfillmentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(FulfillmentsClient) + FulfillmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsClient), ) @mock.patch.object( FulfillmentsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(FulfillmentsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_fulfillments_client_mtls_env_auto( @@ -378,7 +670,9 @@ def test_fulfillments_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 @@ -410,7 +704,9 @@ def test_fulfillments_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 @@ -444,7 +740,9 @@ def test_fulfillments_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, @@ -530,6 +828,116 @@ def test_fulfillments_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", [FulfillmentsClient, FulfillmentsAsyncClient]) +@mock.patch.object( + FulfillmentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsClient), +) +@mock.patch.object( + FulfillmentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FulfillmentsAsyncClient), +) +def test_fulfillments_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = FulfillmentsClient._DEFAULT_UNIVERSE + default_endpoint = FulfillmentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = FulfillmentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -556,7 +964,9 @@ def test_fulfillments_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, @@ -596,7 +1006,9 @@ def test_fulfillments_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, @@ -654,7 +1066,9 @@ def test_fulfillments_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, @@ -671,8 +1085,8 @@ def test_fulfillments_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -704,7 +1118,7 @@ def test_fulfillments_client_create_channel_credentials_file( ) def test_get_fulfillment(request_type, transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -738,7 +1152,7 @@ def test_get_fulfillment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -755,7 +1169,7 @@ async def test_get_fulfillment_async( transport: str = "grpc_asyncio", request_type=fulfillment.GetFulfillmentRequest ): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -794,7 +1208,7 @@ async def test_get_fulfillment_async_from_dict(): def test_get_fulfillment_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -824,7 +1238,7 @@ def test_get_fulfillment_field_headers(): @pytest.mark.asyncio async def test_get_fulfillment_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -855,7 +1269,7 @@ async def test_get_fulfillment_field_headers_async(): def test_get_fulfillment_flattened(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -879,7 +1293,7 @@ def test_get_fulfillment_flattened(): def test_get_fulfillment_flattened_error(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -894,7 +1308,7 @@ def test_get_fulfillment_flattened_error(): @pytest.mark.asyncio async def test_get_fulfillment_flattened_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -923,7 +1337,7 @@ async def test_get_fulfillment_flattened_async(): @pytest.mark.asyncio async def test_get_fulfillment_flattened_error_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -944,7 +1358,7 @@ async def test_get_fulfillment_flattened_error_async(): ) def test_update_fulfillment(request_type, transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -980,7 +1394,7 @@ def test_update_fulfillment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1000,7 +1414,7 @@ async def test_update_fulfillment_async( request_type=gcd_fulfillment.UpdateFulfillmentRequest, ): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1041,7 +1455,7 @@ async def test_update_fulfillment_async_from_dict(): def test_update_fulfillment_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1073,7 +1487,7 @@ def test_update_fulfillment_field_headers(): @pytest.mark.asyncio async def test_update_fulfillment_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1106,7 +1520,7 @@ async def test_update_fulfillment_field_headers_async(): def test_update_fulfillment_flattened(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1136,7 +1550,7 @@ def test_update_fulfillment_flattened(): def test_update_fulfillment_flattened_error(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1152,7 +1566,7 @@ def test_update_fulfillment_flattened_error(): @pytest.mark.asyncio async def test_update_fulfillment_flattened_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1187,7 +1601,7 @@ async def test_update_fulfillment_flattened_async(): @pytest.mark.asyncio async def test_update_fulfillment_flattened_error_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1209,7 +1623,7 @@ async def test_update_fulfillment_flattened_error_async(): ) def test_get_fulfillment_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1264,7 +1678,7 @@ def test_get_fulfillment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_fulfillment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1273,7 +1687,7 @@ def test_get_fulfillment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_fulfillment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1282,7 +1696,7 @@ def test_get_fulfillment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1324,7 +1738,7 @@ def test_get_fulfillment_rest_required_fields( def test_get_fulfillment_rest_unset_required_fields(): transport = transports.FulfillmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_fulfillment._get_unset_required_fields({}) @@ -1334,7 +1748,7 @@ def test_get_fulfillment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_fulfillment_rest_interceptors(null_interceptor): transport = transports.FulfillmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FulfillmentsRestInterceptor(), @@ -1392,7 +1806,7 @@ def test_get_fulfillment_rest_bad_request( transport: str = "rest", request_type=fulfillment.GetFulfillmentRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1414,7 +1828,7 @@ def test_get_fulfillment_rest_bad_request( def test_get_fulfillment_rest_flattened(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1455,7 +1869,7 @@ def test_get_fulfillment_rest_flattened(): def test_get_fulfillment_rest_flattened_error(transport: str = "rest"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1470,7 +1884,7 @@ def test_get_fulfillment_rest_flattened_error(transport: str = "rest"): def test_get_fulfillment_rest_error(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -1483,7 +1897,7 @@ def test_get_fulfillment_rest_error(): ) def test_update_fulfillment_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1617,14 +2031,14 @@ def test_update_fulfillment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_fulfillment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_fulfillment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -1633,7 +2047,7 @@ def test_update_fulfillment_rest_required_fields( # verify required fields with non-default values are left alone client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1676,7 +2090,7 @@ def test_update_fulfillment_rest_required_fields( def test_update_fulfillment_rest_unset_required_fields(): transport = transports.FulfillmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_fulfillment._get_unset_required_fields({}) @@ -1694,7 +2108,7 @@ def test_update_fulfillment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_fulfillment_rest_interceptors(null_interceptor): transport = transports.FulfillmentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FulfillmentsRestInterceptor(), @@ -1752,7 +2166,7 @@ def test_update_fulfillment_rest_bad_request( transport: str = "rest", request_type=gcd_fulfillment.UpdateFulfillmentRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1774,7 +2188,7 @@ def test_update_fulfillment_rest_bad_request( def test_update_fulfillment_rest_flattened(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1817,7 +2231,7 @@ def test_update_fulfillment_rest_flattened(): def test_update_fulfillment_rest_flattened_error(transport: str = "rest"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1833,24 +2247,24 @@ def test_update_fulfillment_rest_flattened_error(transport: str = "rest"): def test_update_fulfillment_rest_error(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = FulfillmentsClient( @@ -1860,7 +2274,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1871,16 +2285,17 @@ 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 = FulfillmentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = FulfillmentsClient( @@ -1892,7 +2307,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = FulfillmentsClient(transport=transport) assert client.transport is transport @@ -1901,13 +2316,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.FulfillmentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.FulfillmentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1924,7 +2339,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1938,7 +2353,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = FulfillmentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1946,7 +2361,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1958,7 +2373,7 @@ def test_fulfillments_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.FulfillmentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1970,7 +2385,7 @@ def test_fulfillments_base_transport(): ) as Transport: Transport.return_value = None transport = transports.FulfillmentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -2008,7 +2423,7 @@ def test_fulfillments_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.FulfillmentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2030,7 +2445,7 @@ def test_fulfillments_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.fulfillments.transports.FulfillmentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.FulfillmentsTransport() adc.assert_called_once() @@ -2038,7 +2453,7 @@ def test_fulfillments_base_transport_with_adc(): def test_fulfillments_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) FulfillmentsClient() adc.assert_called_once_with( scopes=None, @@ -2061,7 +2476,7 @@ def test_fulfillments_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2111,7 +2526,7 @@ def test_fulfillments_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2139,7 +2554,7 @@ def test_fulfillments_transport_create_channel(transport_class, grpc_helpers): [transports.FulfillmentsGrpcTransport, transports.FulfillmentsGrpcAsyncIOTransport], ) def test_fulfillments_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2177,7 +2592,7 @@ def test_fulfillments_grpc_transport_client_cert_source_for_mtls(transport_class def test_fulfillments_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -2197,7 +2612,7 @@ def test_fulfillments_http_transport_client_cert_source_for_mtls(): ) def test_fulfillments_host_no_port(transport_name): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -2220,7 +2635,7 @@ def test_fulfillments_host_no_port(transport_name): ) def test_fulfillments_host_with_port(transport_name): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -2240,8 +2655,8 @@ def test_fulfillments_host_with_port(transport_name): ], ) def test_fulfillments_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = FulfillmentsClient( credentials=creds1, transport=transport_name, @@ -2303,7 +2718,7 @@ def test_fulfillments_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2506,7 +2921,7 @@ def test_client_with_default_client_info(): transports.FulfillmentsTransport, "_prep_wrapped_messages" ) as prep: client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2516,7 +2931,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = FulfillmentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2525,7 +2940,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2540,7 +2955,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2570,7 +2985,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -2598,7 +3013,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2626,7 +3041,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2654,7 +3069,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2684,7 +3099,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2712,7 +3127,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2742,7 +3157,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2770,7 +3185,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2798,7 +3213,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2824,7 +3239,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2849,7 +3264,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2873,7 +3288,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2902,7 +3317,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2929,7 +3344,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -2947,7 +3362,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -2963,7 +3378,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2988,7 +3403,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3014,7 +3429,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3043,7 +3458,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3072,7 +3487,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3090,7 +3505,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3108,7 +3523,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3133,7 +3548,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3159,7 +3574,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3188,7 +3603,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3217,7 +3632,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3235,7 +3650,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3253,7 +3668,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3278,7 +3693,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3304,7 +3719,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3333,7 +3748,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3362,7 +3777,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3380,7 +3795,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3398,7 +3813,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3423,7 +3838,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3448,7 +3863,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = FulfillmentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = FulfillmentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -3475,7 +3890,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = FulfillmentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = FulfillmentsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -3503,7 +3920,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3521,7 +3938,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = FulfillmentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3545,7 +3962,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3562,7 +3979,7 @@ def test_client_ctx(): ] for transport in transports: client = FulfillmentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3593,7 +4010,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_intents.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_intents.py index 227444120c8e..a26a4149bf04 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_intents.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_intents.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -82,6 +82,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -105,6 +128,238 @@ def test__get_default_mtls_endpoint(): assert IntentsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert IntentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert IntentsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert IntentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + IntentsClient._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 IntentsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert IntentsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert IntentsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + IntentsClient._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 IntentsClient._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 IntentsClient._get_client_cert_source(None, False) is None + assert ( + IntentsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + IntentsClient._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 ( + IntentsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + IntentsClient._get_client_cert_source(mock_provided_cert_source, "true") + is mock_provided_cert_source + ) + + +@mock.patch.object( + IntentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsClient), +) +@mock.patch.object( + IntentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = IntentsClient._DEFAULT_UNIVERSE + default_endpoint = IntentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = IntentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + IntentsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + IntentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == IntentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + IntentsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + IntentsClient._get_api_endpoint(None, None, default_universe, "always") + == IntentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + IntentsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == IntentsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + IntentsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + IntentsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + IntentsClient._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 ( + IntentsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + IntentsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + IntentsClient._get_universe_domain(None, None) + == IntentsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + IntentsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (IntentsClient, transports.IntentsGrpcTransport, "grpc"), + (IntentsClient, transports.IntentsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -114,7 +369,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_intents_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -164,7 +419,7 @@ def test_intents_client_service_account_always_use_jwt(transport_class, transpor ], ) def test_intents_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -209,15 +464,21 @@ def test_intents_client_get_transport_class(): ], ) @mock.patch.object( - IntentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IntentsClient) + IntentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsClient), ) @mock.patch.object( - IntentsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IntentsAsyncClient) + IntentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsAsyncClient), ) def test_intents_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(IntentsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -252,7 +513,9 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -282,15 +545,23 @@ def test_intents_client_client_options(client_class, transport_class, transport_ # 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") @@ -300,7 +571,9 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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", @@ -318,7 +591,9 @@ def test_intents_client_client_options(client_class, transport_class, transport_ 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, @@ -350,10 +625,14 @@ def test_intents_client_client_options(client_class, transport_class, transport_ ], ) @mock.patch.object( - IntentsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IntentsClient) + IntentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsClient), ) @mock.patch.object( - IntentsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IntentsAsyncClient) + IntentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_intents_client_mtls_env_auto( @@ -376,7 +655,9 @@ def test_intents_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 @@ -408,7 +689,9 @@ def test_intents_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 @@ -442,7 +725,9 @@ def test_intents_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, @@ -526,6 +811,116 @@ def test_intents_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", [IntentsClient, IntentsAsyncClient]) +@mock.patch.object( + IntentsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsClient), +) +@mock.patch.object( + IntentsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IntentsAsyncClient), +) +def test_intents_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = IntentsClient._DEFAULT_UNIVERSE + default_endpoint = IntentsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = IntentsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -548,7 +943,9 @@ def test_intents_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, @@ -583,7 +980,9 @@ def test_intents_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, @@ -636,7 +1035,9 @@ def test_intents_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, @@ -653,8 +1054,8 @@ def test_intents_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -686,7 +1087,7 @@ def test_intents_client_create_channel_credentials_file( ) def test_list_intents(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -716,7 +1117,7 @@ def test_list_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -733,7 +1134,7 @@ async def test_list_intents_async( transport: str = "grpc_asyncio", request_type=intent.ListIntentsRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -768,7 +1169,7 @@ async def test_list_intents_async_from_dict(): def test_list_intents_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -798,7 +1199,7 @@ def test_list_intents_field_headers(): @pytest.mark.asyncio async def test_list_intents_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -829,7 +1230,7 @@ async def test_list_intents_field_headers_async(): def test_list_intents_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -857,7 +1258,7 @@ def test_list_intents_flattened(): def test_list_intents_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -873,7 +1274,7 @@ def test_list_intents_flattened_error(): @pytest.mark.asyncio async def test_list_intents_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -906,7 +1307,7 @@ async def test_list_intents_flattened_async(): @pytest.mark.asyncio async def test_list_intents_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -921,7 +1322,7 @@ async def test_list_intents_flattened_error_async(): def test_list_intents_pager(transport_name: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -971,7 +1372,7 @@ def test_list_intents_pager(transport_name: str = "grpc"): def test_list_intents_pages(transport_name: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1013,7 +1414,7 @@ def test_list_intents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_intents_async_pager(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1063,7 +1464,7 @@ async def test_list_intents_async_pager(): @pytest.mark.asyncio async def test_list_intents_async_pages(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1118,7 +1519,7 @@ async def test_list_intents_async_pages(): ) def test_get_intent(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1180,7 +1581,7 @@ def test_get_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1197,7 +1598,7 @@ async def test_get_intent_async( transport: str = "grpc_asyncio", request_type=intent.GetIntentRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1264,7 +1665,7 @@ async def test_get_intent_async_from_dict(): def test_get_intent_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1294,7 +1695,7 @@ def test_get_intent_field_headers(): @pytest.mark.asyncio async def test_get_intent_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1323,7 +1724,7 @@ async def test_get_intent_field_headers_async(): def test_get_intent_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1351,7 +1752,7 @@ def test_get_intent_flattened(): def test_get_intent_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1367,7 +1768,7 @@ def test_get_intent_flattened_error(): @pytest.mark.asyncio async def test_get_intent_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1398,7 +1799,7 @@ async def test_get_intent_flattened_async(): @pytest.mark.asyncio async def test_get_intent_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1420,7 +1821,7 @@ async def test_get_intent_flattened_error_async(): ) def test_create_intent(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1484,7 +1885,7 @@ def test_create_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1501,7 +1902,7 @@ async def test_create_intent_async( transport: str = "grpc_asyncio", request_type=gcd_intent.CreateIntentRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1572,7 +1973,7 @@ async def test_create_intent_async_from_dict(): def test_create_intent_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1602,7 +2003,7 @@ def test_create_intent_field_headers(): @pytest.mark.asyncio async def test_create_intent_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1631,7 +2032,7 @@ async def test_create_intent_field_headers_async(): def test_create_intent_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1663,7 +2064,7 @@ def test_create_intent_flattened(): def test_create_intent_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1680,7 +2081,7 @@ def test_create_intent_flattened_error(): @pytest.mark.asyncio async def test_create_intent_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1715,7 +2116,7 @@ async def test_create_intent_flattened_async(): @pytest.mark.asyncio async def test_create_intent_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1738,7 +2139,7 @@ async def test_create_intent_flattened_error_async(): ) def test_update_intent(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1802,7 +2203,7 @@ def test_update_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1819,7 +2220,7 @@ async def test_update_intent_async( transport: str = "grpc_asyncio", request_type=gcd_intent.UpdateIntentRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1890,7 +2291,7 @@ async def test_update_intent_async_from_dict(): def test_update_intent_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1920,7 +2321,7 @@ def test_update_intent_field_headers(): @pytest.mark.asyncio async def test_update_intent_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1949,7 +2350,7 @@ async def test_update_intent_field_headers_async(): def test_update_intent_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1981,7 +2382,7 @@ def test_update_intent_flattened(): def test_update_intent_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1998,7 +2399,7 @@ def test_update_intent_flattened_error(): @pytest.mark.asyncio async def test_update_intent_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2033,7 +2434,7 @@ async def test_update_intent_flattened_async(): @pytest.mark.asyncio async def test_update_intent_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2056,7 +2457,7 @@ async def test_update_intent_flattened_error_async(): ) def test_delete_intent(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2083,7 +2484,7 @@ def test_delete_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2100,7 +2501,7 @@ async def test_delete_intent_async( transport: str = "grpc_asyncio", request_type=intent.DeleteIntentRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2130,7 +2531,7 @@ async def test_delete_intent_async_from_dict(): def test_delete_intent_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2160,7 +2561,7 @@ def test_delete_intent_field_headers(): @pytest.mark.asyncio async def test_delete_intent_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2189,7 +2590,7 @@ async def test_delete_intent_field_headers_async(): def test_delete_intent_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2213,7 +2614,7 @@ def test_delete_intent_flattened(): def test_delete_intent_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2228,7 +2629,7 @@ def test_delete_intent_flattened_error(): @pytest.mark.asyncio async def test_delete_intent_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2255,7 +2656,7 @@ async def test_delete_intent_flattened_async(): @pytest.mark.asyncio async def test_delete_intent_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2276,7 +2677,7 @@ async def test_delete_intent_flattened_error_async(): ) def test_batch_update_intents(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2305,7 +2706,7 @@ def test_batch_update_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2324,7 +2725,7 @@ async def test_batch_update_intents_async( transport: str = "grpc_asyncio", request_type=intent.BatchUpdateIntentsRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2358,7 +2759,7 @@ async def test_batch_update_intents_async_from_dict(): def test_batch_update_intents_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2390,7 +2791,7 @@ def test_batch_update_intents_field_headers(): @pytest.mark.asyncio async def test_batch_update_intents_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2423,7 +2824,7 @@ async def test_batch_update_intents_field_headers_async(): def test_batch_update_intents_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2456,7 +2857,7 @@ def test_batch_update_intents_flattened(): def test_batch_update_intents_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2475,7 +2876,7 @@ def test_batch_update_intents_flattened_error(): @pytest.mark.asyncio async def test_batch_update_intents_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2513,7 +2914,7 @@ async def test_batch_update_intents_flattened_async(): @pytest.mark.asyncio async def test_batch_update_intents_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2538,7 +2939,7 @@ async def test_batch_update_intents_flattened_error_async(): ) def test_batch_delete_intents(request_type, transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2567,7 +2968,7 @@ def test_batch_delete_intents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2586,7 +2987,7 @@ async def test_batch_delete_intents_async( transport: str = "grpc_asyncio", request_type=intent.BatchDeleteIntentsRequest ): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2620,7 +3021,7 @@ async def test_batch_delete_intents_async_from_dict(): def test_batch_delete_intents_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2652,7 +3053,7 @@ def test_batch_delete_intents_field_headers(): @pytest.mark.asyncio async def test_batch_delete_intents_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2685,7 +3086,7 @@ async def test_batch_delete_intents_field_headers_async(): def test_batch_delete_intents_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2715,7 +3116,7 @@ def test_batch_delete_intents_flattened(): def test_batch_delete_intents_flattened_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2731,7 +3132,7 @@ def test_batch_delete_intents_flattened_error(): @pytest.mark.asyncio async def test_batch_delete_intents_flattened_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2766,7 +3167,7 @@ async def test_batch_delete_intents_flattened_async(): @pytest.mark.asyncio async def test_batch_delete_intents_flattened_error_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2788,7 +3189,7 @@ async def test_batch_delete_intents_flattened_error_async(): ) def test_list_intents_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2837,7 +3238,7 @@ def test_list_intents_rest_required_fields(request_type=intent.ListIntentsReques # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2846,7 +3247,7 @@ def test_list_intents_rest_required_fields(request_type=intent.ListIntentsReques jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_intents._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2864,7 +3265,7 @@ def test_list_intents_rest_required_fields(request_type=intent.ListIntentsReques assert jsonified_request["parent"] == "parent_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2906,7 +3307,7 @@ def test_list_intents_rest_required_fields(request_type=intent.ListIntentsReques def test_list_intents_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_intents._get_unset_required_fields({}) @@ -2926,7 +3327,7 @@ def test_list_intents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_intents_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -2980,7 +3381,7 @@ def test_list_intents_rest_bad_request( transport: str = "rest", request_type=intent.ListIntentsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3002,7 +3403,7 @@ def test_list_intents_rest_bad_request( def test_list_intents_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3044,7 +3445,7 @@ def test_list_intents_rest_flattened(): def test_list_intents_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3060,7 +3461,7 @@ def test_list_intents_rest_flattened_error(transport: str = "rest"): def test_list_intents_rest_pager(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3128,7 +3529,7 @@ def test_list_intents_rest_pager(transport: str = "rest"): ) def test_get_intent_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3209,7 +3610,7 @@ def test_get_intent_rest_required_fields(request_type=intent.GetIntentRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3218,7 +3619,7 @@ def test_get_intent_rest_required_fields(request_type=intent.GetIntentRequest): jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_intent._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3234,7 +3635,7 @@ def test_get_intent_rest_required_fields(request_type=intent.GetIntentRequest): assert jsonified_request["name"] == "name_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3276,7 +3677,7 @@ def test_get_intent_rest_required_fields(request_type=intent.GetIntentRequest): def test_get_intent_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_intent._get_unset_required_fields({}) @@ -3294,7 +3695,7 @@ def test_get_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_intent_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -3346,7 +3747,7 @@ def test_get_intent_rest_bad_request( transport: str = "rest", request_type=intent.GetIntentRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3368,7 +3769,7 @@ def test_get_intent_rest_bad_request( def test_get_intent_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3410,7 +3811,7 @@ def test_get_intent_rest_flattened(): def test_get_intent_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3426,7 +3827,7 @@ def test_get_intent_rest_flattened_error(transport: str = "rest"): def test_get_intent_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3439,7 +3840,7 @@ def test_get_intent_rest_error(): ) def test_create_intent_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3795,7 +4196,7 @@ def test_create_intent_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3804,7 +4205,7 @@ def test_create_intent_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_intent._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3820,7 +4221,7 @@ def test_create_intent_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3863,7 +4264,7 @@ def test_create_intent_rest_required_fields( def test_create_intent_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_intent._get_unset_required_fields({}) @@ -3886,7 +4287,7 @@ def test_create_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_intent_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -3938,7 +4339,7 @@ def test_create_intent_rest_bad_request( transport: str = "rest", request_type=gcd_intent.CreateIntentRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3960,7 +4361,7 @@ def test_create_intent_rest_bad_request( def test_create_intent_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4003,7 +4404,7 @@ def test_create_intent_rest_flattened(): def test_create_intent_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4020,7 +4421,7 @@ def test_create_intent_rest_flattened_error(transport: str = "rest"): def test_create_intent_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4033,7 +4434,7 @@ def test_create_intent_rest_error(): ) def test_update_intent_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4388,14 +4789,14 @@ def test_update_intent_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_intent._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4410,7 +4811,7 @@ def test_update_intent_rest_required_fields( # verify required fields with non-default values are left alone client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4453,7 +4854,7 @@ def test_update_intent_rest_required_fields( def test_update_intent_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_intent._get_unset_required_fields({}) @@ -4472,7 +4873,7 @@ def test_update_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_intent_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -4524,7 +4925,7 @@ def test_update_intent_rest_bad_request( transport: str = "rest", request_type=gcd_intent.UpdateIntentRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4546,7 +4947,7 @@ def test_update_intent_rest_bad_request( def test_update_intent_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4590,7 +4991,7 @@ def test_update_intent_rest_flattened(): def test_update_intent_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4607,7 +5008,7 @@ def test_update_intent_rest_flattened_error(transport: str = "rest"): def test_update_intent_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4620,7 +5021,7 @@ def test_update_intent_rest_error(): ) def test_delete_intent_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4664,7 +5065,7 @@ def test_delete_intent_rest_required_fields(request_type=intent.DeleteIntentRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4673,7 +5074,7 @@ def test_delete_intent_rest_required_fields(request_type=intent.DeleteIntentRequ jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4682,7 +5083,7 @@ def test_delete_intent_rest_required_fields(request_type=intent.DeleteIntentRequ assert jsonified_request["name"] == "name_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4721,7 +5122,7 @@ def test_delete_intent_rest_required_fields(request_type=intent.DeleteIntentRequ def test_delete_intent_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_intent._get_unset_required_fields({}) @@ -4731,7 +5132,7 @@ def test_delete_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_intent_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -4777,7 +5178,7 @@ def test_delete_intent_rest_bad_request( transport: str = "rest", request_type=intent.DeleteIntentRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4799,7 +5200,7 @@ def test_delete_intent_rest_bad_request( def test_delete_intent_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4838,7 +5239,7 @@ def test_delete_intent_rest_flattened(): def test_delete_intent_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4853,7 +5254,7 @@ def test_delete_intent_rest_flattened_error(transport: str = "rest"): def test_delete_intent_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4866,7 +5267,7 @@ def test_delete_intent_rest_error(): ) def test_batch_update_intents_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4912,7 +5313,7 @@ def test_batch_update_intents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4921,7 +5322,7 @@ def test_batch_update_intents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_update_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4930,7 +5331,7 @@ def test_batch_update_intents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4970,7 +5371,7 @@ def test_batch_update_intents_rest_required_fields( def test_batch_update_intents_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_update_intents._get_unset_required_fields({}) @@ -4980,7 +5381,7 @@ def test_batch_update_intents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_update_intents_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -5038,7 +5439,7 @@ def test_batch_update_intents_rest_bad_request( transport: str = "rest", request_type=intent.BatchUpdateIntentsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5060,7 +5461,7 @@ def test_batch_update_intents_rest_bad_request( def test_batch_update_intents_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5100,7 +5501,7 @@ def test_batch_update_intents_rest_flattened(): def test_batch_update_intents_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5119,7 +5520,7 @@ def test_batch_update_intents_rest_flattened_error(transport: str = "rest"): def test_batch_update_intents_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5132,7 +5533,7 @@ def test_batch_update_intents_rest_error(): ) def test_batch_delete_intents_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5178,7 +5579,7 @@ def test_batch_delete_intents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5187,7 +5588,7 @@ def test_batch_delete_intents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_intents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5196,7 +5597,7 @@ def test_batch_delete_intents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5236,7 +5637,7 @@ def test_batch_delete_intents_rest_required_fields( def test_batch_delete_intents_rest_unset_required_fields(): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_delete_intents._get_unset_required_fields({}) @@ -5254,7 +5655,7 @@ def test_batch_delete_intents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_delete_intents_rest_interceptors(null_interceptor): transport = transports.IntentsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IntentsRestInterceptor(), ) client = IntentsClient(transport=transport) @@ -5312,7 +5713,7 @@ def test_batch_delete_intents_rest_bad_request( transport: str = "rest", request_type=intent.BatchDeleteIntentsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5334,7 +5735,7 @@ def test_batch_delete_intents_rest_bad_request( def test_batch_delete_intents_rest_flattened(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5375,7 +5776,7 @@ def test_batch_delete_intents_rest_flattened(): def test_batch_delete_intents_rest_flattened_error(transport: str = "rest"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5391,24 +5792,24 @@ def test_batch_delete_intents_rest_flattened_error(transport: str = "rest"): def test_batch_delete_intents_rest_error(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = IntentsClient( @@ -5418,7 +5819,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5429,16 +5830,17 @@ 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 = IntentsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = IntentsClient( @@ -5450,7 +5852,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = IntentsClient(transport=transport) assert client.transport is transport @@ -5459,13 +5861,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.IntentsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.IntentsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5482,7 +5884,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5496,7 +5898,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = IntentsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5504,7 +5906,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5516,7 +5918,7 @@ def test_intents_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.IntentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5528,7 +5930,7 @@ def test_intents_base_transport(): ) as Transport: Transport.return_value = None transport = transports.IntentsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5576,7 +5978,7 @@ def test_intents_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.IntentsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5598,7 +6000,7 @@ def test_intents_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.intents.transports.IntentsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.IntentsTransport() adc.assert_called_once() @@ -5606,7 +6008,7 @@ def test_intents_base_transport_with_adc(): def test_intents_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) IntentsClient() adc.assert_called_once_with( scopes=None, @@ -5629,7 +6031,7 @@ def test_intents_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5679,7 +6081,7 @@ def test_intents_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5707,7 +6109,7 @@ def test_intents_transport_create_channel(transport_class, grpc_helpers): [transports.IntentsGrpcTransport, transports.IntentsGrpcAsyncIOTransport], ) def test_intents_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5745,7 +6147,7 @@ def test_intents_grpc_transport_client_cert_source_for_mtls(transport_class): def test_intents_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5757,7 +6159,7 @@ def test_intents_http_transport_client_cert_source_for_mtls(): def test_intents_rest_lro_client(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5782,7 +6184,7 @@ def test_intents_rest_lro_client(): ) def test_intents_host_no_port(transport_name): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -5805,7 +6207,7 @@ def test_intents_host_no_port(transport_name): ) def test_intents_host_with_port(transport_name): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -5825,8 +6227,8 @@ def test_intents_host_with_port(transport_name): ], ) def test_intents_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = IntentsClient( credentials=creds1, transport=transport_name, @@ -5903,7 +6305,7 @@ def test_intents_transport_channel_mtls_with_client_cert_source(transport_class) mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5978,7 +6380,7 @@ def test_intents_transport_channel_mtls_with_adc(transport_class): def test_intents_grpc_lro_client(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5995,7 +6397,7 @@ def test_intents_grpc_lro_client(): def test_intents_grpc_lro_async_client(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -6169,7 +6571,7 @@ def test_client_with_default_client_info(): transports.IntentsTransport, "_prep_wrapped_messages" ) as prep: client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6179,7 +6581,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = IntentsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6188,7 +6590,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6203,7 +6605,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6233,7 +6635,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -6261,7 +6663,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6289,7 +6691,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6317,7 +6719,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6347,7 +6749,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6375,7 +6777,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6405,7 +6807,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -6433,7 +6835,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6461,7 +6863,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6487,7 +6889,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6512,7 +6914,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6536,7 +6938,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6565,7 +6967,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6592,7 +6994,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6610,7 +7012,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6626,7 +7028,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6651,7 +7053,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6677,7 +7079,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6706,7 +7108,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6735,7 +7137,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6753,7 +7155,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6771,7 +7173,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6796,7 +7198,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6822,7 +7224,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6851,7 +7253,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6880,7 +7282,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6898,7 +7300,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6916,7 +7318,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6941,7 +7343,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6967,7 +7369,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6996,7 +7398,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7025,7 +7427,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7043,7 +7445,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7061,7 +7463,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7086,7 +7488,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7111,7 +7513,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = IntentsClient(credentials=ga_credentials.AnonymousCredentials()) + client = IntentsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7138,7 +7540,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = IntentsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = IntentsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -7166,7 +7568,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7184,7 +7586,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = IntentsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7208,7 +7610,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7225,7 +7627,7 @@ def test_client_ctx(): ] for transport in transports: client = IntentsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7256,7 +7658,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py index 1cf3b906e30e..068b62d46a6f 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_knowledge_bases.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -70,6 +70,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -99,6 +122,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert KnowledgeBasesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert KnowledgeBasesClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert KnowledgeBasesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + KnowledgeBasesClient._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 KnowledgeBasesClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert KnowledgeBasesClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert KnowledgeBasesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + KnowledgeBasesClient._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 KnowledgeBasesClient._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 KnowledgeBasesClient._get_client_cert_source(None, False) is None + assert ( + KnowledgeBasesClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + KnowledgeBasesClient._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 ( + KnowledgeBasesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + KnowledgeBasesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + KnowledgeBasesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesClient), +) +@mock.patch.object( + KnowledgeBasesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = KnowledgeBasesClient._DEFAULT_UNIVERSE + default_endpoint = KnowledgeBasesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = KnowledgeBasesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + KnowledgeBasesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + KnowledgeBasesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + KnowledgeBasesClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + KnowledgeBasesClient._get_api_endpoint(None, None, default_universe, "always") + == KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + KnowledgeBasesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == KnowledgeBasesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + KnowledgeBasesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + KnowledgeBasesClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + KnowledgeBasesClient._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 ( + KnowledgeBasesClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + KnowledgeBasesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + KnowledgeBasesClient._get_universe_domain(None, None) + == KnowledgeBasesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + KnowledgeBasesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (KnowledgeBasesClient, transports.KnowledgeBasesGrpcTransport, "grpc"), + (KnowledgeBasesClient, transports.KnowledgeBasesRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -108,7 +392,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_knowledge_bases_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -160,7 +444,7 @@ def test_knowledge_bases_client_service_account_always_use_jwt( ], ) def test_knowledge_bases_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -210,20 +494,22 @@ def test_knowledge_bases_client_get_transport_class(): ) @mock.patch.object( KnowledgeBasesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(KnowledgeBasesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesClient), ) @mock.patch.object( KnowledgeBasesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(KnowledgeBasesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesAsyncClient), ) def test_knowledge_bases_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(KnowledgeBasesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -258,7 +544,9 @@ def test_knowledge_bases_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, @@ -288,15 +576,23 @@ def test_knowledge_bases_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") @@ -306,7 +602,9 @@ def test_knowledge_bases_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", @@ -324,7 +622,9 @@ def test_knowledge_bases_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, @@ -357,13 +657,13 @@ def test_knowledge_bases_client_client_options( ) @mock.patch.object( KnowledgeBasesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(KnowledgeBasesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesClient), ) @mock.patch.object( KnowledgeBasesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(KnowledgeBasesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_knowledge_bases_client_mtls_env_auto( @@ -386,7 +686,9 @@ def test_knowledge_bases_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 @@ -418,7 +720,9 @@ def test_knowledge_bases_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 @@ -452,7 +756,9 @@ def test_knowledge_bases_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, @@ -542,6 +848,118 @@ def test_knowledge_bases_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", [KnowledgeBasesClient, KnowledgeBasesAsyncClient] +) +@mock.patch.object( + KnowledgeBasesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesClient), +) +@mock.patch.object( + KnowledgeBasesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(KnowledgeBasesAsyncClient), +) +def test_knowledge_bases_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = KnowledgeBasesClient._DEFAULT_UNIVERSE + default_endpoint = KnowledgeBasesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = KnowledgeBasesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -568,7 +986,9 @@ def test_knowledge_bases_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, @@ -608,7 +1028,9 @@ def test_knowledge_bases_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, @@ -668,7 +1090,9 @@ def test_knowledge_bases_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, @@ -685,8 +1109,8 @@ def test_knowledge_bases_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -718,7 +1142,7 @@ def test_knowledge_bases_client_create_channel_credentials_file( ) def test_list_knowledge_bases(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -750,7 +1174,7 @@ def test_list_knowledge_bases_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -770,7 +1194,7 @@ async def test_list_knowledge_bases_async( request_type=knowledge_base.ListKnowledgeBasesRequest, ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -807,7 +1231,7 @@ async def test_list_knowledge_bases_async_from_dict(): def test_list_knowledge_bases_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -839,7 +1263,7 @@ def test_list_knowledge_bases_field_headers(): @pytest.mark.asyncio async def test_list_knowledge_bases_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -872,7 +1296,7 @@ async def test_list_knowledge_bases_field_headers_async(): def test_list_knowledge_bases_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -898,7 +1322,7 @@ def test_list_knowledge_bases_flattened(): def test_list_knowledge_bases_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -913,7 +1337,7 @@ def test_list_knowledge_bases_flattened_error(): @pytest.mark.asyncio async def test_list_knowledge_bases_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -944,7 +1368,7 @@ async def test_list_knowledge_bases_flattened_async(): @pytest.mark.asyncio async def test_list_knowledge_bases_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -958,7 +1382,7 @@ async def test_list_knowledge_bases_flattened_error_async(): def test_list_knowledge_bases_pager(transport_name: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1010,7 +1434,7 @@ def test_list_knowledge_bases_pager(transport_name: str = "grpc"): def test_list_knowledge_bases_pages(transport_name: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1054,7 +1478,7 @@ def test_list_knowledge_bases_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_knowledge_bases_async_pager(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1106,7 +1530,7 @@ async def test_list_knowledge_bases_async_pager(): @pytest.mark.asyncio async def test_list_knowledge_bases_async_pages(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1163,7 +1587,7 @@ async def test_list_knowledge_bases_async_pages(): ) def test_get_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1199,7 +1623,7 @@ def test_get_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1218,7 +1642,7 @@ async def test_get_knowledge_base_async( transport: str = "grpc_asyncio", request_type=knowledge_base.GetKnowledgeBaseRequest ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1259,7 +1683,7 @@ async def test_get_knowledge_base_async_from_dict(): def test_get_knowledge_base_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1291,7 +1715,7 @@ def test_get_knowledge_base_field_headers(): @pytest.mark.asyncio async def test_get_knowledge_base_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1324,7 +1748,7 @@ async def test_get_knowledge_base_field_headers_async(): def test_get_knowledge_base_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1350,7 +1774,7 @@ def test_get_knowledge_base_flattened(): def test_get_knowledge_base_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1365,7 +1789,7 @@ def test_get_knowledge_base_flattened_error(): @pytest.mark.asyncio async def test_get_knowledge_base_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1396,7 +1820,7 @@ async def test_get_knowledge_base_flattened_async(): @pytest.mark.asyncio async def test_get_knowledge_base_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1417,7 +1841,7 @@ async def test_get_knowledge_base_flattened_error_async(): ) def test_create_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1453,7 +1877,7 @@ def test_create_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1473,7 +1897,7 @@ async def test_create_knowledge_base_async( request_type=gcd_knowledge_base.CreateKnowledgeBaseRequest, ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1514,7 +1938,7 @@ async def test_create_knowledge_base_async_from_dict(): def test_create_knowledge_base_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1546,7 +1970,7 @@ def test_create_knowledge_base_field_headers(): @pytest.mark.asyncio async def test_create_knowledge_base_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1579,7 +2003,7 @@ async def test_create_knowledge_base_field_headers_async(): def test_create_knowledge_base_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1609,7 +2033,7 @@ def test_create_knowledge_base_flattened(): def test_create_knowledge_base_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1625,7 +2049,7 @@ def test_create_knowledge_base_flattened_error(): @pytest.mark.asyncio async def test_create_knowledge_base_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1660,7 +2084,7 @@ async def test_create_knowledge_base_flattened_async(): @pytest.mark.asyncio async def test_create_knowledge_base_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1682,7 +2106,7 @@ async def test_create_knowledge_base_flattened_error_async(): ) def test_delete_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1711,7 +2135,7 @@ def test_delete_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1731,7 +2155,7 @@ async def test_delete_knowledge_base_async( request_type=knowledge_base.DeleteKnowledgeBaseRequest, ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1763,7 +2187,7 @@ async def test_delete_knowledge_base_async_from_dict(): def test_delete_knowledge_base_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1795,7 +2219,7 @@ def test_delete_knowledge_base_field_headers(): @pytest.mark.asyncio async def test_delete_knowledge_base_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1826,7 +2250,7 @@ async def test_delete_knowledge_base_field_headers_async(): def test_delete_knowledge_base_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1852,7 +2276,7 @@ def test_delete_knowledge_base_flattened(): def test_delete_knowledge_base_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1867,7 +2291,7 @@ def test_delete_knowledge_base_flattened_error(): @pytest.mark.asyncio async def test_delete_knowledge_base_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1896,7 +2320,7 @@ async def test_delete_knowledge_base_flattened_async(): @pytest.mark.asyncio async def test_delete_knowledge_base_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1917,7 +2341,7 @@ async def test_delete_knowledge_base_flattened_error_async(): ) def test_update_knowledge_base(request_type, transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1953,7 +2377,7 @@ def test_update_knowledge_base_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1973,7 +2397,7 @@ async def test_update_knowledge_base_async( request_type=gcd_knowledge_base.UpdateKnowledgeBaseRequest, ): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2014,7 +2438,7 @@ async def test_update_knowledge_base_async_from_dict(): def test_update_knowledge_base_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2046,7 +2470,7 @@ def test_update_knowledge_base_field_headers(): @pytest.mark.asyncio async def test_update_knowledge_base_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2079,7 +2503,7 @@ async def test_update_knowledge_base_field_headers_async(): def test_update_knowledge_base_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2109,7 +2533,7 @@ def test_update_knowledge_base_flattened(): def test_update_knowledge_base_flattened_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2125,7 +2549,7 @@ def test_update_knowledge_base_flattened_error(): @pytest.mark.asyncio async def test_update_knowledge_base_flattened_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2160,7 +2584,7 @@ async def test_update_knowledge_base_flattened_async(): @pytest.mark.asyncio async def test_update_knowledge_base_flattened_error_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2182,7 +2606,7 @@ async def test_update_knowledge_base_flattened_error_async(): ) def test_list_knowledge_bases_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2233,7 +2657,7 @@ def test_list_knowledge_bases_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_knowledge_bases._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2242,7 +2666,7 @@ def test_list_knowledge_bases_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_knowledge_bases._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2259,7 +2683,7 @@ def test_list_knowledge_bases_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2301,7 +2725,7 @@ def test_list_knowledge_bases_rest_required_fields( def test_list_knowledge_bases_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_knowledge_bases._get_unset_required_fields({}) @@ -2320,7 +2744,7 @@ def test_list_knowledge_bases_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_knowledge_bases_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -2378,7 +2802,7 @@ def test_list_knowledge_bases_rest_bad_request( transport: str = "rest", request_type=knowledge_base.ListKnowledgeBasesRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2400,7 +2824,7 @@ def test_list_knowledge_bases_rest_bad_request( def test_list_knowledge_bases_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2441,7 +2865,7 @@ def test_list_knowledge_bases_rest_flattened(): def test_list_knowledge_bases_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2456,7 +2880,7 @@ def test_list_knowledge_bases_rest_flattened_error(transport: str = "rest"): def test_list_knowledge_bases_rest_pager(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2526,7 +2950,7 @@ def test_list_knowledge_bases_rest_pager(transport: str = "rest"): ) def test_get_knowledge_base_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2581,7 +3005,7 @@ def test_get_knowledge_base_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2590,7 +3014,7 @@ def test_get_knowledge_base_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2599,7 +3023,7 @@ def test_get_knowledge_base_rest_required_fields( assert jsonified_request["name"] == "name_value" client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2641,7 +3065,7 @@ def test_get_knowledge_base_rest_required_fields( def test_get_knowledge_base_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_knowledge_base._get_unset_required_fields({}) @@ -2651,7 +3075,7 @@ def test_get_knowledge_base_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_knowledge_base_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -2709,7 +3133,7 @@ def test_get_knowledge_base_rest_bad_request( transport: str = "rest", request_type=knowledge_base.GetKnowledgeBaseRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2731,7 +3155,7 @@ def test_get_knowledge_base_rest_bad_request( def test_get_knowledge_base_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2772,7 +3196,7 @@ def test_get_knowledge_base_rest_flattened(): def test_get_knowledge_base_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2787,7 +3211,7 @@ def test_get_knowledge_base_rest_flattened_error(transport: str = "rest"): def test_get_knowledge_base_rest_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2800,7 +3224,7 @@ def test_get_knowledge_base_rest_error(): ) def test_create_knowledge_base_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2929,7 +3353,7 @@ def test_create_knowledge_base_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2938,7 +3362,7 @@ def test_create_knowledge_base_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2947,7 +3371,7 @@ def test_create_knowledge_base_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2990,7 +3414,7 @@ def test_create_knowledge_base_rest_required_fields( def test_create_knowledge_base_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_knowledge_base._get_unset_required_fields({}) @@ -3008,7 +3432,7 @@ def test_create_knowledge_base_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_knowledge_base_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -3066,7 +3490,7 @@ def test_create_knowledge_base_rest_bad_request( transport: str = "rest", request_type=gcd_knowledge_base.CreateKnowledgeBaseRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3088,7 +3512,7 @@ def test_create_knowledge_base_rest_bad_request( def test_create_knowledge_base_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3130,7 +3554,7 @@ def test_create_knowledge_base_rest_flattened(): def test_create_knowledge_base_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3146,7 +3570,7 @@ def test_create_knowledge_base_rest_flattened_error(transport: str = "rest"): def test_create_knowledge_base_rest_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3159,7 +3583,7 @@ def test_create_knowledge_base_rest_error(): ) def test_delete_knowledge_base_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3205,7 +3629,7 @@ def test_delete_knowledge_base_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3214,7 +3638,7 @@ def test_delete_knowledge_base_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_knowledge_base._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("force",)) @@ -3225,7 +3649,7 @@ def test_delete_knowledge_base_rest_required_fields( assert jsonified_request["name"] == "name_value" client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3264,7 +3688,7 @@ def test_delete_knowledge_base_rest_required_fields( def test_delete_knowledge_base_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_knowledge_base._get_unset_required_fields({}) @@ -3274,7 +3698,7 @@ def test_delete_knowledge_base_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_knowledge_base_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -3324,7 +3748,7 @@ def test_delete_knowledge_base_rest_bad_request( transport: str = "rest", request_type=knowledge_base.DeleteKnowledgeBaseRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3346,7 +3770,7 @@ def test_delete_knowledge_base_rest_bad_request( def test_delete_knowledge_base_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3385,7 +3809,7 @@ def test_delete_knowledge_base_rest_flattened(): def test_delete_knowledge_base_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3400,7 +3824,7 @@ def test_delete_knowledge_base_rest_flattened_error(transport: str = "rest"): def test_delete_knowledge_base_rest_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3413,7 +3837,7 @@ def test_delete_knowledge_base_rest_error(): ) def test_update_knowledge_base_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3543,14 +3967,14 @@ def test_update_knowledge_base_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_knowledge_base._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_knowledge_base._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3559,7 +3983,7 @@ def test_update_knowledge_base_rest_required_fields( # verify required fields with non-default values are left alone client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3602,7 +4026,7 @@ def test_update_knowledge_base_rest_required_fields( def test_update_knowledge_base_rest_unset_required_fields(): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_knowledge_base._get_unset_required_fields({}) @@ -3612,7 +4036,7 @@ def test_update_knowledge_base_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_knowledge_base_rest_interceptors(null_interceptor): transport = transports.KnowledgeBasesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.KnowledgeBasesRestInterceptor(), @@ -3670,7 +4094,7 @@ def test_update_knowledge_base_rest_bad_request( transport: str = "rest", request_type=gcd_knowledge_base.UpdateKnowledgeBaseRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3694,7 +4118,7 @@ def test_update_knowledge_base_rest_bad_request( def test_update_knowledge_base_rest_flattened(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3739,7 +4163,7 @@ def test_update_knowledge_base_rest_flattened(): def test_update_knowledge_base_rest_flattened_error(transport: str = "rest"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3755,24 +4179,24 @@ def test_update_knowledge_base_rest_flattened_error(transport: str = "rest"): def test_update_knowledge_base_rest_error(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = KnowledgeBasesClient( @@ -3782,7 +4206,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3793,16 +4217,17 @@ 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 = KnowledgeBasesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = KnowledgeBasesClient( @@ -3814,7 +4239,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = KnowledgeBasesClient(transport=transport) assert client.transport is transport @@ -3823,13 +4248,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.KnowledgeBasesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.KnowledgeBasesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3846,7 +4271,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3860,7 +4285,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = KnowledgeBasesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3868,7 +4293,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3880,7 +4305,7 @@ def test_knowledge_bases_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.KnowledgeBasesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3892,7 +4317,7 @@ def test_knowledge_bases_base_transport(): ) as Transport: Transport.return_value = None transport = transports.KnowledgeBasesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3933,7 +4358,7 @@ def test_knowledge_bases_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.KnowledgeBasesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3955,7 +4380,7 @@ def test_knowledge_bases_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.knowledge_bases.transports.KnowledgeBasesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.KnowledgeBasesTransport() adc.assert_called_once() @@ -3963,7 +4388,7 @@ def test_knowledge_bases_base_transport_with_adc(): def test_knowledge_bases_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) KnowledgeBasesClient() adc.assert_called_once_with( scopes=None, @@ -3986,7 +4411,7 @@ def test_knowledge_bases_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4036,7 +4461,7 @@ def test_knowledge_bases_transport_create_channel(transport_class, grpc_helpers) ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4067,7 +4492,7 @@ def test_knowledge_bases_transport_create_channel(transport_class, grpc_helpers) ], ) def test_knowledge_bases_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4105,7 +4530,7 @@ def test_knowledge_bases_grpc_transport_client_cert_source_for_mtls(transport_cl def test_knowledge_bases_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4125,7 +4550,7 @@ def test_knowledge_bases_http_transport_client_cert_source_for_mtls(): ) def test_knowledge_bases_host_no_port(transport_name): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4148,7 +4573,7 @@ def test_knowledge_bases_host_no_port(transport_name): ) def test_knowledge_bases_host_with_port(transport_name): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4168,8 +4593,8 @@ def test_knowledge_bases_host_with_port(transport_name): ], ) def test_knowledge_bases_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = KnowledgeBasesClient( credentials=creds1, transport=transport_name, @@ -4245,7 +4670,7 @@ def test_knowledge_bases_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4454,7 +4879,7 @@ def test_client_with_default_client_info(): transports.KnowledgeBasesTransport, "_prep_wrapped_messages" ) as prep: client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4464,7 +4889,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = KnowledgeBasesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4473,7 +4898,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4488,7 +4913,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4518,7 +4943,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4546,7 +4971,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4574,7 +4999,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4602,7 +5027,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4632,7 +5057,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4660,7 +5085,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4690,7 +5115,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4718,7 +5143,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4746,7 +5171,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4772,7 +5197,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4797,7 +5222,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4821,7 +5246,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4850,7 +5275,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4877,7 +5302,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4895,7 +5320,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4911,7 +5336,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4936,7 +5361,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4962,7 +5387,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4991,7 +5416,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5020,7 +5445,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5038,7 +5463,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5056,7 +5481,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5081,7 +5506,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5107,7 +5532,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5136,7 +5561,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5165,7 +5590,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5183,7 +5608,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5201,7 +5626,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5226,7 +5651,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5252,7 +5677,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5281,7 +5706,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5310,7 +5735,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5328,7 +5753,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5346,7 +5771,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5371,7 +5796,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5396,7 +5821,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = KnowledgeBasesClient(credentials=ga_credentials.AnonymousCredentials()) + client = KnowledgeBasesClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5424,7 +5849,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5453,7 +5878,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5471,7 +5896,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = KnowledgeBasesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5495,7 +5920,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5512,7 +5937,7 @@ def test_client_ctx(): ] for transport in transports: client = KnowledgeBasesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5543,7 +5968,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py index 67432b5a006b..08531a3b2abd 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_participants.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -81,6 +81,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -107,6 +130,255 @@ def test__get_default_mtls_endpoint(): assert ParticipantsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert ParticipantsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ParticipantsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ParticipantsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ParticipantsClient._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 ParticipantsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ParticipantsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ParticipantsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ParticipantsClient._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 ParticipantsClient._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 ParticipantsClient._get_client_cert_source(None, False) is None + assert ( + ParticipantsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + ParticipantsClient._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 ( + ParticipantsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ParticipantsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ParticipantsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsClient), +) +@mock.patch.object( + ParticipantsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ParticipantsClient._DEFAULT_UNIVERSE + default_endpoint = ParticipantsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ParticipantsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ParticipantsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ParticipantsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ParticipantsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ParticipantsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + ParticipantsClient._get_api_endpoint(None, None, default_universe, "always") + == ParticipantsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ParticipantsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ParticipantsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ParticipantsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + ParticipantsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ParticipantsClient._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 ( + ParticipantsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ParticipantsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + ParticipantsClient._get_universe_domain(None, None) + == ParticipantsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ParticipantsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (ParticipantsClient, transports.ParticipantsGrpcTransport, "grpc"), + (ParticipantsClient, transports.ParticipantsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -116,7 +388,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_participants_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -168,7 +440,7 @@ def test_participants_client_service_account_always_use_jwt( ], ) def test_participants_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -217,19 +489,23 @@ def test_participants_client_get_transport_class(): ], ) @mock.patch.object( - ParticipantsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ParticipantsClient) + ParticipantsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsClient), ) @mock.patch.object( ParticipantsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ParticipantsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsAsyncClient), ) def test_participants_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(ParticipantsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -264,7 +540,9 @@ def test_participants_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, @@ -294,15 +572,23 @@ def test_participants_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") @@ -312,7 +598,9 @@ def test_participants_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", @@ -330,7 +618,9 @@ def test_participants_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, @@ -362,12 +652,14 @@ def test_participants_client_client_options( ], ) @mock.patch.object( - ParticipantsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ParticipantsClient) + ParticipantsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsClient), ) @mock.patch.object( ParticipantsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ParticipantsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_participants_client_mtls_env_auto( @@ -390,7 +682,9 @@ def test_participants_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 @@ -422,7 +716,9 @@ def test_participants_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 @@ -456,7 +752,9 @@ def test_participants_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, @@ -542,6 +840,116 @@ def test_participants_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", [ParticipantsClient, ParticipantsAsyncClient]) +@mock.patch.object( + ParticipantsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsClient), +) +@mock.patch.object( + ParticipantsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ParticipantsAsyncClient), +) +def test_participants_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ParticipantsClient._DEFAULT_UNIVERSE + default_endpoint = ParticipantsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = ParticipantsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -568,7 +976,9 @@ def test_participants_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, @@ -608,7 +1018,9 @@ def test_participants_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, @@ -666,7 +1078,9 @@ def test_participants_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, @@ -683,8 +1097,8 @@ def test_participants_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -716,7 +1130,7 @@ def test_participants_client_create_channel_credentials_file( ) def test_create_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -752,7 +1166,7 @@ def test_create_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -772,7 +1186,7 @@ async def test_create_participant_async( request_type=gcd_participant.CreateParticipantRequest, ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -813,7 +1227,7 @@ async def test_create_participant_async_from_dict(): def test_create_participant_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -845,7 +1259,7 @@ def test_create_participant_field_headers(): @pytest.mark.asyncio async def test_create_participant_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -878,7 +1292,7 @@ async def test_create_participant_field_headers_async(): def test_create_participant_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -908,7 +1322,7 @@ def test_create_participant_flattened(): def test_create_participant_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -924,7 +1338,7 @@ def test_create_participant_flattened_error(): @pytest.mark.asyncio async def test_create_participant_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -959,7 +1373,7 @@ async def test_create_participant_flattened_async(): @pytest.mark.asyncio async def test_create_participant_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -981,7 +1395,7 @@ async def test_create_participant_flattened_error_async(): ) def test_get_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1015,7 +1429,7 @@ def test_get_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1032,7 +1446,7 @@ async def test_get_participant_async( transport: str = "grpc_asyncio", request_type=participant.GetParticipantRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1071,7 +1485,7 @@ async def test_get_participant_async_from_dict(): def test_get_participant_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1101,7 +1515,7 @@ def test_get_participant_field_headers(): @pytest.mark.asyncio async def test_get_participant_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1132,7 +1546,7 @@ async def test_get_participant_field_headers_async(): def test_get_participant_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1156,7 +1570,7 @@ def test_get_participant_flattened(): def test_get_participant_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1171,7 +1585,7 @@ def test_get_participant_flattened_error(): @pytest.mark.asyncio async def test_get_participant_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1200,7 +1614,7 @@ async def test_get_participant_flattened_async(): @pytest.mark.asyncio async def test_get_participant_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1221,7 +1635,7 @@ async def test_get_participant_flattened_error_async(): ) def test_list_participants(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1253,7 +1667,7 @@ def test_list_participants_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1272,7 +1686,7 @@ async def test_list_participants_async( transport: str = "grpc_asyncio", request_type=participant.ListParticipantsRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1309,7 +1723,7 @@ async def test_list_participants_async_from_dict(): def test_list_participants_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1341,7 +1755,7 @@ def test_list_participants_field_headers(): @pytest.mark.asyncio async def test_list_participants_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1374,7 +1788,7 @@ async def test_list_participants_field_headers_async(): def test_list_participants_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1400,7 +1814,7 @@ def test_list_participants_flattened(): def test_list_participants_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1415,7 +1829,7 @@ def test_list_participants_flattened_error(): @pytest.mark.asyncio async def test_list_participants_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1446,7 +1860,7 @@ async def test_list_participants_flattened_async(): @pytest.mark.asyncio async def test_list_participants_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1460,7 +1874,7 @@ async def test_list_participants_flattened_error_async(): def test_list_participants_pager(transport_name: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1512,7 +1926,7 @@ def test_list_participants_pager(transport_name: str = "grpc"): def test_list_participants_pages(transport_name: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1556,7 +1970,7 @@ def test_list_participants_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_participants_async_pager(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1608,7 +2022,7 @@ async def test_list_participants_async_pager(): @pytest.mark.asyncio async def test_list_participants_async_pages(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1665,7 +2079,7 @@ async def test_list_participants_async_pages(): ) def test_update_participant(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1701,7 +2115,7 @@ def test_update_participant_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1721,7 +2135,7 @@ async def test_update_participant_async( request_type=gcd_participant.UpdateParticipantRequest, ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1762,7 +2176,7 @@ async def test_update_participant_async_from_dict(): def test_update_participant_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1794,7 +2208,7 @@ def test_update_participant_field_headers(): @pytest.mark.asyncio async def test_update_participant_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1827,7 +2241,7 @@ async def test_update_participant_field_headers_async(): def test_update_participant_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1857,7 +2271,7 @@ def test_update_participant_flattened(): def test_update_participant_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1873,7 +2287,7 @@ def test_update_participant_flattened_error(): @pytest.mark.asyncio async def test_update_participant_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1908,7 +2322,7 @@ async def test_update_participant_flattened_async(): @pytest.mark.asyncio async def test_update_participant_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1930,7 +2344,7 @@ async def test_update_participant_flattened_error_async(): ) def test_analyze_content(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1960,7 +2374,7 @@ def test_analyze_content_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1977,7 +2391,7 @@ async def test_analyze_content_async( transport: str = "grpc_asyncio", request_type=gcd_participant.AnalyzeContentRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2012,7 +2426,7 @@ async def test_analyze_content_async_from_dict(): def test_analyze_content_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2042,7 +2456,7 @@ def test_analyze_content_field_headers(): @pytest.mark.asyncio async def test_analyze_content_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2073,7 +2487,7 @@ async def test_analyze_content_field_headers_async(): def test_analyze_content_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2105,7 +2519,7 @@ def test_analyze_content_flattened(): def test_analyze_content_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2127,7 +2541,7 @@ def test_analyze_content_flattened_error(): @pytest.mark.asyncio async def test_analyze_content_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2164,7 +2578,7 @@ async def test_analyze_content_flattened_async(): @pytest.mark.asyncio async def test_analyze_content_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2192,7 +2606,7 @@ async def test_analyze_content_flattened_error_async(): ) def test_streaming_analyze_content(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2225,7 +2639,7 @@ async def test_streaming_analyze_content_async( request_type=participant.StreamingAnalyzeContentRequest, ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2269,7 +2683,7 @@ async def test_streaming_analyze_content_async_from_dict(): ) def test_suggest_articles(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2301,7 +2715,7 @@ def test_suggest_articles_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2318,7 +2732,7 @@ async def test_suggest_articles_async( transport: str = "grpc_asyncio", request_type=participant.SuggestArticlesRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2355,7 +2769,7 @@ async def test_suggest_articles_async_from_dict(): def test_suggest_articles_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2385,7 +2799,7 @@ def test_suggest_articles_field_headers(): @pytest.mark.asyncio async def test_suggest_articles_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2416,7 +2830,7 @@ async def test_suggest_articles_field_headers_async(): def test_suggest_articles_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2440,7 +2854,7 @@ def test_suggest_articles_flattened(): def test_suggest_articles_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2455,7 +2869,7 @@ def test_suggest_articles_flattened_error(): @pytest.mark.asyncio async def test_suggest_articles_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2484,7 +2898,7 @@ async def test_suggest_articles_flattened_async(): @pytest.mark.asyncio async def test_suggest_articles_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2505,7 +2919,7 @@ async def test_suggest_articles_flattened_error_async(): ) def test_suggest_faq_answers(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2539,7 +2953,7 @@ def test_suggest_faq_answers_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2558,7 +2972,7 @@ async def test_suggest_faq_answers_async( transport: str = "grpc_asyncio", request_type=participant.SuggestFaqAnswersRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2597,7 +3011,7 @@ async def test_suggest_faq_answers_async_from_dict(): def test_suggest_faq_answers_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2629,7 +3043,7 @@ def test_suggest_faq_answers_field_headers(): @pytest.mark.asyncio async def test_suggest_faq_answers_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2662,7 +3076,7 @@ async def test_suggest_faq_answers_field_headers_async(): def test_suggest_faq_answers_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2688,7 +3102,7 @@ def test_suggest_faq_answers_flattened(): def test_suggest_faq_answers_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2703,7 +3117,7 @@ def test_suggest_faq_answers_flattened_error(): @pytest.mark.asyncio async def test_suggest_faq_answers_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2734,7 +3148,7 @@ async def test_suggest_faq_answers_flattened_async(): @pytest.mark.asyncio async def test_suggest_faq_answers_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2755,7 +3169,7 @@ async def test_suggest_faq_answers_flattened_error_async(): ) def test_suggest_smart_replies(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2789,7 +3203,7 @@ def test_suggest_smart_replies_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2808,7 +3222,7 @@ async def test_suggest_smart_replies_async( transport: str = "grpc_asyncio", request_type=participant.SuggestSmartRepliesRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2847,7 +3261,7 @@ async def test_suggest_smart_replies_async_from_dict(): def test_suggest_smart_replies_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2879,7 +3293,7 @@ def test_suggest_smart_replies_field_headers(): @pytest.mark.asyncio async def test_suggest_smart_replies_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2912,7 +3326,7 @@ async def test_suggest_smart_replies_field_headers_async(): def test_suggest_smart_replies_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2938,7 +3352,7 @@ def test_suggest_smart_replies_flattened(): def test_suggest_smart_replies_flattened_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2953,7 +3367,7 @@ def test_suggest_smart_replies_flattened_error(): @pytest.mark.asyncio async def test_suggest_smart_replies_flattened_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2984,7 +3398,7 @@ async def test_suggest_smart_replies_flattened_async(): @pytest.mark.asyncio async def test_suggest_smart_replies_flattened_error_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3005,7 +3419,7 @@ async def test_suggest_smart_replies_flattened_error_async(): ) def test_list_suggestions(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3035,7 +3449,7 @@ def test_list_suggestions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3052,7 +3466,7 @@ async def test_list_suggestions_async( transport: str = "grpc_asyncio", request_type=participant.ListSuggestionsRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3087,7 +3501,7 @@ async def test_list_suggestions_async_from_dict(): def test_list_suggestions_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3117,7 +3531,7 @@ def test_list_suggestions_field_headers(): @pytest.mark.asyncio async def test_list_suggestions_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3148,7 +3562,7 @@ async def test_list_suggestions_field_headers_async(): def test_list_suggestions_pager(transport_name: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3198,7 +3612,7 @@ def test_list_suggestions_pager(transport_name: str = "grpc"): def test_list_suggestions_pages(transport_name: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3240,7 +3654,7 @@ def test_list_suggestions_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_suggestions_async_pager(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3290,7 +3704,7 @@ async def test_list_suggestions_async_pager(): @pytest.mark.asyncio async def test_list_suggestions_async_pages(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3345,7 +3759,7 @@ async def test_list_suggestions_async_pages(): ) def test_compile_suggestion(request_type, transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3379,7 +3793,7 @@ def test_compile_suggestion_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3398,7 +3812,7 @@ async def test_compile_suggestion_async( transport: str = "grpc_asyncio", request_type=participant.CompileSuggestionRequest ): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3437,7 +3851,7 @@ async def test_compile_suggestion_async_from_dict(): def test_compile_suggestion_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3469,7 +3883,7 @@ def test_compile_suggestion_field_headers(): @pytest.mark.asyncio async def test_compile_suggestion_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3509,7 +3923,7 @@ async def test_compile_suggestion_field_headers_async(): ) def test_create_participant_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3637,7 +4051,7 @@ def test_create_participant_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3646,7 +4060,7 @@ def test_create_participant_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3655,7 +4069,7 @@ def test_create_participant_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3698,7 +4112,7 @@ def test_create_participant_rest_required_fields( def test_create_participant_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_participant._get_unset_required_fields({}) @@ -3716,7 +4130,7 @@ def test_create_participant_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_participant_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -3774,7 +4188,7 @@ def test_create_participant_rest_bad_request( transport: str = "rest", request_type=gcd_participant.CreateParticipantRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3796,7 +4210,7 @@ def test_create_participant_rest_bad_request( def test_create_participant_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3839,7 +4253,7 @@ def test_create_participant_rest_flattened(): def test_create_participant_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3855,7 +4269,7 @@ def test_create_participant_rest_flattened_error(transport: str = "rest"): def test_create_participant_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3868,7 +4282,7 @@ def test_create_participant_rest_error(): ) def test_get_participant_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3925,7 +4339,7 @@ def test_get_participant_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3934,7 +4348,7 @@ def test_get_participant_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3943,7 +4357,7 @@ def test_get_participant_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3985,7 +4399,7 @@ def test_get_participant_rest_required_fields( def test_get_participant_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_participant._get_unset_required_fields({}) @@ -3995,7 +4409,7 @@ def test_get_participant_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_participant_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -4053,7 +4467,7 @@ def test_get_participant_rest_bad_request( transport: str = "rest", request_type=participant.GetParticipantRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4077,7 +4491,7 @@ def test_get_participant_rest_bad_request( def test_get_participant_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4121,7 +4535,7 @@ def test_get_participant_rest_flattened(): def test_get_participant_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4136,7 +4550,7 @@ def test_get_participant_rest_flattened_error(transport: str = "rest"): def test_get_participant_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4149,7 +4563,7 @@ def test_get_participant_rest_error(): ) def test_list_participants_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4200,7 +4614,7 @@ def test_list_participants_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_participants._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4209,7 +4623,7 @@ def test_list_participants_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_participants._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4225,7 +4639,7 @@ def test_list_participants_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4267,7 +4681,7 @@ def test_list_participants_rest_required_fields( def test_list_participants_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_participants._get_unset_required_fields({}) @@ -4285,7 +4699,7 @@ def test_list_participants_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_participants_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -4343,7 +4757,7 @@ def test_list_participants_rest_bad_request( transport: str = "rest", request_type=participant.ListParticipantsRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4365,7 +4779,7 @@ def test_list_participants_rest_bad_request( def test_list_participants_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4407,7 +4821,7 @@ def test_list_participants_rest_flattened(): def test_list_participants_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4422,7 +4836,7 @@ def test_list_participants_rest_flattened_error(transport: str = "rest"): def test_list_participants_rest_pager(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4492,7 +4906,7 @@ def test_list_participants_rest_pager(transport: str = "rest"): ) def test_update_participant_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4623,14 +5037,14 @@ def test_update_participant_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_participant._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_participant._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -4639,7 +5053,7 @@ def test_update_participant_rest_required_fields( # verify required fields with non-default values are left alone client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4682,7 +5096,7 @@ def test_update_participant_rest_required_fields( def test_update_participant_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_participant._get_unset_required_fields({}) @@ -4700,7 +5114,7 @@ def test_update_participant_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_participant_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -4758,7 +5172,7 @@ def test_update_participant_rest_bad_request( transport: str = "rest", request_type=gcd_participant.UpdateParticipantRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4784,7 +5198,7 @@ def test_update_participant_rest_bad_request( def test_update_participant_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4831,7 +5245,7 @@ def test_update_participant_rest_flattened(): def test_update_participant_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4847,7 +5261,7 @@ def test_update_participant_rest_flattened_error(transport: str = "rest"): def test_update_participant_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4860,7 +5274,7 @@ def test_update_participant_rest_error(): ) def test_analyze_content_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4913,7 +5327,7 @@ def test_analyze_content_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).analyze_content._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4922,7 +5336,7 @@ def test_analyze_content_rest_required_fields( jsonified_request["participant"] = "participant_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).analyze_content._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4931,7 +5345,7 @@ def test_analyze_content_rest_required_fields( assert jsonified_request["participant"] == "participant_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4974,7 +5388,7 @@ def test_analyze_content_rest_required_fields( def test_analyze_content_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.analyze_content._get_unset_required_fields({}) @@ -4984,7 +5398,7 @@ def test_analyze_content_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_analyze_content_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -5042,7 +5456,7 @@ def test_analyze_content_rest_bad_request( transport: str = "rest", request_type=gcd_participant.AnalyzeContentRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5066,7 +5480,7 @@ def test_analyze_content_rest_bad_request( def test_analyze_content_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5110,7 +5524,7 @@ def test_analyze_content_rest_flattened(): def test_analyze_content_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5132,13 +5546,13 @@ def test_analyze_content_rest_flattened_error(transport: str = "rest"): def test_analyze_content_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_streaming_analyze_content_rest_no_http_options(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = participant.StreamingAnalyzeContentRequest() @@ -5156,7 +5570,7 @@ def test_streaming_analyze_content_rest_no_http_options(): ) def test_suggest_articles_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5211,7 +5625,7 @@ def test_suggest_articles_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_articles._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5220,7 +5634,7 @@ def test_suggest_articles_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_articles._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5229,7 +5643,7 @@ def test_suggest_articles_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5272,7 +5686,7 @@ def test_suggest_articles_rest_required_fields( def test_suggest_articles_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.suggest_articles._get_unset_required_fields({}) @@ -5282,7 +5696,7 @@ def test_suggest_articles_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_suggest_articles_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -5340,7 +5754,7 @@ def test_suggest_articles_rest_bad_request( transport: str = "rest", request_type=participant.SuggestArticlesRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5364,7 +5778,7 @@ def test_suggest_articles_rest_bad_request( def test_suggest_articles_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5408,7 +5822,7 @@ def test_suggest_articles_rest_flattened(): def test_suggest_articles_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5423,7 +5837,7 @@ def test_suggest_articles_rest_flattened_error(transport: str = "rest"): def test_suggest_articles_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5436,7 +5850,7 @@ def test_suggest_articles_rest_error(): ) def test_suggest_faq_answers_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5491,7 +5905,7 @@ def test_suggest_faq_answers_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_faq_answers._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5500,7 +5914,7 @@ def test_suggest_faq_answers_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_faq_answers._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5509,7 +5923,7 @@ def test_suggest_faq_answers_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5552,7 +5966,7 @@ def test_suggest_faq_answers_rest_required_fields( def test_suggest_faq_answers_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.suggest_faq_answers._get_unset_required_fields({}) @@ -5562,7 +5976,7 @@ def test_suggest_faq_answers_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_suggest_faq_answers_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -5620,7 +6034,7 @@ def test_suggest_faq_answers_rest_bad_request( transport: str = "rest", request_type=participant.SuggestFaqAnswersRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5644,7 +6058,7 @@ def test_suggest_faq_answers_rest_bad_request( def test_suggest_faq_answers_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5688,7 +6102,7 @@ def test_suggest_faq_answers_rest_flattened(): def test_suggest_faq_answers_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5703,7 +6117,7 @@ def test_suggest_faq_answers_rest_flattened_error(transport: str = "rest"): def test_suggest_faq_answers_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5716,7 +6130,7 @@ def test_suggest_faq_answers_rest_error(): ) def test_suggest_smart_replies_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5771,7 +6185,7 @@ def test_suggest_smart_replies_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_smart_replies._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5780,7 +6194,7 @@ def test_suggest_smart_replies_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).suggest_smart_replies._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5789,7 +6203,7 @@ def test_suggest_smart_replies_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5832,7 +6246,7 @@ def test_suggest_smart_replies_rest_required_fields( def test_suggest_smart_replies_rest_unset_required_fields(): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.suggest_smart_replies._get_unset_required_fields({}) @@ -5842,7 +6256,7 @@ def test_suggest_smart_replies_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_suggest_smart_replies_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -5900,7 +6314,7 @@ def test_suggest_smart_replies_rest_bad_request( transport: str = "rest", request_type=participant.SuggestSmartRepliesRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5924,7 +6338,7 @@ def test_suggest_smart_replies_rest_bad_request( def test_suggest_smart_replies_rest_flattened(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5968,7 +6382,7 @@ def test_suggest_smart_replies_rest_flattened(): def test_suggest_smart_replies_rest_flattened_error(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5983,7 +6397,7 @@ def test_suggest_smart_replies_rest_flattened_error(transport: str = "rest"): def test_suggest_smart_replies_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5996,7 +6410,7 @@ def test_suggest_smart_replies_rest_error(): ) def test_list_suggestions_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6032,7 +6446,7 @@ def test_list_suggestions_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_suggestions_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -6090,7 +6504,7 @@ def test_list_suggestions_rest_bad_request( transport: str = "rest", request_type=participant.ListSuggestionsRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6114,7 +6528,7 @@ def test_list_suggestions_rest_bad_request( def test_list_suggestions_rest_pager(transport: str = "rest"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6186,7 +6600,7 @@ def test_list_suggestions_rest_pager(transport: str = "rest"): ) def test_compile_suggestion_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6224,7 +6638,7 @@ def test_compile_suggestion_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_compile_suggestion_rest_interceptors(null_interceptor): transport = transports.ParticipantsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ParticipantsRestInterceptor(), @@ -6282,7 +6696,7 @@ def test_compile_suggestion_rest_bad_request( transport: str = "rest", request_type=participant.CompileSuggestionRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6306,13 +6720,13 @@ def test_compile_suggestion_rest_bad_request( def test_compile_suggestion_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_streaming_analyze_content_rest_error(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) # Since a `google.api.http` annotation is required for using a rest transport # method, this should error. @@ -6326,17 +6740,17 @@ def test_streaming_analyze_content_rest_error(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ParticipantsClient( @@ -6346,7 +6760,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -6357,16 +6771,17 @@ 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 = ParticipantsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ParticipantsClient( @@ -6378,7 +6793,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ParticipantsClient(transport=transport) assert client.transport is transport @@ -6387,13 +6802,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ParticipantsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ParticipantsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -6410,7 +6825,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -6424,7 +6839,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ParticipantsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -6432,7 +6847,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -6444,7 +6859,7 @@ def test_participants_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ParticipantsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -6456,7 +6871,7 @@ def test_participants_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ParticipantsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6503,7 +6918,7 @@ def test_participants_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ParticipantsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6525,7 +6940,7 @@ def test_participants_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.participants.transports.ParticipantsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ParticipantsTransport() adc.assert_called_once() @@ -6533,7 +6948,7 @@ def test_participants_base_transport_with_adc(): def test_participants_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ParticipantsClient() adc.assert_called_once_with( scopes=None, @@ -6556,7 +6971,7 @@ def test_participants_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -6606,7 +7021,7 @@ def test_participants_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6634,7 +7049,7 @@ def test_participants_transport_create_channel(transport_class, grpc_helpers): [transports.ParticipantsGrpcTransport, transports.ParticipantsGrpcAsyncIOTransport], ) def test_participants_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6672,7 +7087,7 @@ def test_participants_grpc_transport_client_cert_source_for_mtls(transport_class def test_participants_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -6692,7 +7107,7 @@ def test_participants_http_transport_client_cert_source_for_mtls(): ) def test_participants_host_no_port(transport_name): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -6715,7 +7130,7 @@ def test_participants_host_no_port(transport_name): ) def test_participants_host_with_port(transport_name): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -6735,8 +7150,8 @@ def test_participants_host_with_port(transport_name): ], ) def test_participants_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ParticipantsClient( credentials=creds1, transport=transport_name, @@ -6825,7 +7240,7 @@ def test_participants_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -7188,7 +7603,7 @@ def test_client_with_default_client_info(): transports.ParticipantsTransport, "_prep_wrapped_messages" ) as prep: client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7198,7 +7613,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ParticipantsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7207,7 +7622,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -7222,7 +7637,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7252,7 +7667,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -7280,7 +7695,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7308,7 +7723,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -7336,7 +7751,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7366,7 +7781,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -7394,7 +7809,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7424,7 +7839,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -7452,7 +7867,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7480,7 +7895,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -7506,7 +7921,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7531,7 +7946,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7555,7 +7970,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7584,7 +7999,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7611,7 +8026,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7629,7 +8044,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7645,7 +8060,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7670,7 +8085,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7696,7 +8111,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7725,7 +8140,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7754,7 +8169,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7772,7 +8187,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7790,7 +8205,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7815,7 +8230,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7841,7 +8256,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7870,7 +8285,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7899,7 +8314,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7917,7 +8332,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7935,7 +8350,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7960,7 +8375,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7986,7 +8401,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8015,7 +8430,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8044,7 +8459,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8062,7 +8477,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8080,7 +8495,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8105,7 +8520,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8130,7 +8545,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = ParticipantsClient(credentials=ga_credentials.AnonymousCredentials()) + client = ParticipantsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -8157,7 +8572,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = ParticipantsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = ParticipantsAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -8185,7 +8602,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8203,7 +8620,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = ParticipantsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -8227,7 +8644,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -8244,7 +8661,7 @@ def test_client_ctx(): ] for transport in transports: client = ParticipantsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -8275,7 +8692,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py index cfe5bc8edc8b..132d53e9ee5f 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_session_entity_types.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -73,6 +73,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -103,6 +126,279 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SessionEntityTypesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SessionEntityTypesClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SessionEntityTypesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SessionEntityTypesClient._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 SessionEntityTypesClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SessionEntityTypesClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SessionEntityTypesClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SessionEntityTypesClient._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 SessionEntityTypesClient._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 SessionEntityTypesClient._get_client_cert_source(None, False) is None + assert ( + SessionEntityTypesClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + SessionEntityTypesClient._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 ( + SessionEntityTypesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SessionEntityTypesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SessionEntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesClient), +) +@mock.patch.object( + SessionEntityTypesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SessionEntityTypesClient._DEFAULT_UNIVERSE + default_endpoint = SessionEntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SessionEntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SessionEntityTypesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SessionEntityTypesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionEntityTypesClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SessionEntityTypesClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionEntityTypesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SessionEntityTypesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionEntityTypesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SessionEntityTypesClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SessionEntityTypesClient._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 ( + SessionEntityTypesClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SessionEntityTypesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SessionEntityTypesClient._get_universe_domain(None, None) + == SessionEntityTypesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SessionEntityTypesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SessionEntityTypesClient, transports.SessionEntityTypesGrpcTransport, "grpc"), + (SessionEntityTypesClient, transports.SessionEntityTypesRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -114,7 +410,7 @@ def test__get_default_mtls_endpoint(): def test_session_entity_types_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -168,7 +464,7 @@ def test_session_entity_types_client_service_account_always_use_jwt( def test_session_entity_types_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -218,20 +514,22 @@ def test_session_entity_types_client_get_transport_class(): ) @mock.patch.object( SessionEntityTypesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionEntityTypesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesClient), ) @mock.patch.object( SessionEntityTypesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionEntityTypesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesAsyncClient), ) def test_session_entity_types_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SessionEntityTypesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -266,7 +564,9 @@ def test_session_entity_types_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, @@ -296,15 +596,23 @@ def test_session_entity_types_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") @@ -314,7 +622,9 @@ def test_session_entity_types_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", @@ -332,7 +642,9 @@ def test_session_entity_types_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, @@ -385,13 +697,13 @@ def test_session_entity_types_client_client_options( ) @mock.patch.object( SessionEntityTypesClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionEntityTypesClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesClient), ) @mock.patch.object( SessionEntityTypesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionEntityTypesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_session_entity_types_client_mtls_env_auto( @@ -414,7 +726,9 @@ def test_session_entity_types_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 @@ -446,7 +760,9 @@ def test_session_entity_types_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 @@ -480,7 +796,9 @@ def test_session_entity_types_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, @@ -570,6 +888,118 @@ def test_session_entity_types_client_get_mtls_endpoint_and_cert_source(client_cl 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", [SessionEntityTypesClient, SessionEntityTypesAsyncClient] +) +@mock.patch.object( + SessionEntityTypesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesClient), +) +@mock.patch.object( + SessionEntityTypesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionEntityTypesAsyncClient), +) +def test_session_entity_types_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SessionEntityTypesClient._DEFAULT_UNIVERSE + default_endpoint = SessionEntityTypesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SessionEntityTypesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -596,7 +1026,9 @@ def test_session_entity_types_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, @@ -641,7 +1073,9 @@ def test_session_entity_types_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, @@ -701,7 +1135,9 @@ def test_session_entity_types_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, @@ -718,8 +1154,8 @@ def test_session_entity_types_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -751,7 +1187,7 @@ def test_session_entity_types_client_create_channel_credentials_file( ) def test_list_session_entity_types(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -783,7 +1219,7 @@ def test_list_session_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -803,7 +1239,7 @@ async def test_list_session_entity_types_async( request_type=session_entity_type.ListSessionEntityTypesRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -840,7 +1276,7 @@ async def test_list_session_entity_types_async_from_dict(): def test_list_session_entity_types_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -872,7 +1308,7 @@ def test_list_session_entity_types_field_headers(): @pytest.mark.asyncio async def test_list_session_entity_types_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -905,7 +1341,7 @@ async def test_list_session_entity_types_field_headers_async(): def test_list_session_entity_types_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -931,7 +1367,7 @@ def test_list_session_entity_types_flattened(): def test_list_session_entity_types_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -946,7 +1382,7 @@ def test_list_session_entity_types_flattened_error(): @pytest.mark.asyncio async def test_list_session_entity_types_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -977,7 +1413,7 @@ async def test_list_session_entity_types_flattened_async(): @pytest.mark.asyncio async def test_list_session_entity_types_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -991,7 +1427,7 @@ async def test_list_session_entity_types_flattened_error_async(): def test_list_session_entity_types_pager(transport_name: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1045,7 +1481,7 @@ def test_list_session_entity_types_pager(transport_name: str = "grpc"): def test_list_session_entity_types_pages(transport_name: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1089,7 +1525,7 @@ def test_list_session_entity_types_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_session_entity_types_async_pager(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1143,7 +1579,7 @@ async def test_list_session_entity_types_async_pager(): @pytest.mark.asyncio async def test_list_session_entity_types_async_pages(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1200,7 +1636,7 @@ async def test_list_session_entity_types_async_pages(): ) def test_get_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1237,7 +1673,7 @@ def test_get_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1257,7 +1693,7 @@ async def test_get_session_entity_type_async( request_type=session_entity_type.GetSessionEntityTypeRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1299,7 +1735,7 @@ async def test_get_session_entity_type_async_from_dict(): def test_get_session_entity_type_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1331,7 +1767,7 @@ def test_get_session_entity_type_field_headers(): @pytest.mark.asyncio async def test_get_session_entity_type_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1364,7 +1800,7 @@ async def test_get_session_entity_type_field_headers_async(): def test_get_session_entity_type_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1390,7 +1826,7 @@ def test_get_session_entity_type_flattened(): def test_get_session_entity_type_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1405,7 +1841,7 @@ def test_get_session_entity_type_flattened_error(): @pytest.mark.asyncio async def test_get_session_entity_type_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1436,7 +1872,7 @@ async def test_get_session_entity_type_flattened_async(): @pytest.mark.asyncio async def test_get_session_entity_type_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1457,7 +1893,7 @@ async def test_get_session_entity_type_flattened_error_async(): ) def test_create_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1494,7 +1930,7 @@ def test_create_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1514,7 +1950,7 @@ async def test_create_session_entity_type_async( request_type=gcd_session_entity_type.CreateSessionEntityTypeRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1556,7 +1992,7 @@ async def test_create_session_entity_type_async_from_dict(): def test_create_session_entity_type_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1588,7 +2024,7 @@ def test_create_session_entity_type_field_headers(): @pytest.mark.asyncio async def test_create_session_entity_type_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1621,7 +2057,7 @@ async def test_create_session_entity_type_field_headers_async(): def test_create_session_entity_type_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1653,7 +2089,7 @@ def test_create_session_entity_type_flattened(): def test_create_session_entity_type_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1671,7 +2107,7 @@ def test_create_session_entity_type_flattened_error(): @pytest.mark.asyncio async def test_create_session_entity_type_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1708,7 +2144,7 @@ async def test_create_session_entity_type_flattened_async(): @pytest.mark.asyncio async def test_create_session_entity_type_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1732,7 +2168,7 @@ async def test_create_session_entity_type_flattened_error_async(): ) def test_update_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1769,7 +2205,7 @@ def test_update_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1789,7 +2225,7 @@ async def test_update_session_entity_type_async( request_type=gcd_session_entity_type.UpdateSessionEntityTypeRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1831,7 +2267,7 @@ async def test_update_session_entity_type_async_from_dict(): def test_update_session_entity_type_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1863,7 +2299,7 @@ def test_update_session_entity_type_field_headers(): @pytest.mark.asyncio async def test_update_session_entity_type_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1896,7 +2332,7 @@ async def test_update_session_entity_type_field_headers_async(): def test_update_session_entity_type_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1928,7 +2364,7 @@ def test_update_session_entity_type_flattened(): def test_update_session_entity_type_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1946,7 +2382,7 @@ def test_update_session_entity_type_flattened_error(): @pytest.mark.asyncio async def test_update_session_entity_type_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1983,7 +2419,7 @@ async def test_update_session_entity_type_flattened_async(): @pytest.mark.asyncio async def test_update_session_entity_type_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2007,7 +2443,7 @@ async def test_update_session_entity_type_flattened_error_async(): ) def test_delete_session_entity_type(request_type, transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2036,7 +2472,7 @@ def test_delete_session_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2056,7 +2492,7 @@ async def test_delete_session_entity_type_async( request_type=session_entity_type.DeleteSessionEntityTypeRequest, ): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2088,7 +2524,7 @@ async def test_delete_session_entity_type_async_from_dict(): def test_delete_session_entity_type_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2120,7 +2556,7 @@ def test_delete_session_entity_type_field_headers(): @pytest.mark.asyncio async def test_delete_session_entity_type_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2151,7 +2587,7 @@ async def test_delete_session_entity_type_field_headers_async(): def test_delete_session_entity_type_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2177,7 +2613,7 @@ def test_delete_session_entity_type_flattened(): def test_delete_session_entity_type_flattened_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2192,7 +2628,7 @@ def test_delete_session_entity_type_flattened_error(): @pytest.mark.asyncio async def test_delete_session_entity_type_flattened_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2221,7 +2657,7 @@ async def test_delete_session_entity_type_flattened_async(): @pytest.mark.asyncio async def test_delete_session_entity_type_flattened_error_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2242,7 +2678,7 @@ async def test_delete_session_entity_type_flattened_error_async(): ) def test_list_session_entity_types_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2295,7 +2731,7 @@ def test_list_session_entity_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_session_entity_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2304,7 +2740,7 @@ def test_list_session_entity_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_session_entity_types._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2320,7 +2756,7 @@ def test_list_session_entity_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2364,7 +2800,7 @@ def test_list_session_entity_types_rest_required_fields( def test_list_session_entity_types_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_session_entity_types._get_unset_required_fields({}) @@ -2382,7 +2818,7 @@ def test_list_session_entity_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_session_entity_types_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -2443,7 +2879,7 @@ def test_list_session_entity_types_rest_bad_request( request_type=session_entity_type.ListSessionEntityTypesRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2465,7 +2901,7 @@ def test_list_session_entity_types_rest_bad_request( def test_list_session_entity_types_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2509,7 +2945,7 @@ def test_list_session_entity_types_rest_flattened(): def test_list_session_entity_types_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2524,7 +2960,7 @@ def test_list_session_entity_types_rest_flattened_error(transport: str = "rest") def test_list_session_entity_types_rest_pager(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2597,7 +3033,7 @@ def test_list_session_entity_types_rest_pager(transport: str = "rest"): ) def test_get_session_entity_type_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2655,7 +3091,7 @@ def test_get_session_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2664,7 +3100,7 @@ def test_get_session_entity_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2673,7 +3109,7 @@ def test_get_session_entity_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2715,7 +3151,7 @@ def test_get_session_entity_type_rest_required_fields( def test_get_session_entity_type_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_session_entity_type._get_unset_required_fields({}) @@ -2725,7 +3161,7 @@ def test_get_session_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_session_entity_type_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -2784,7 +3220,7 @@ def test_get_session_entity_type_rest_bad_request( request_type=session_entity_type.GetSessionEntityTypeRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2808,7 +3244,7 @@ def test_get_session_entity_type_rest_bad_request( def test_get_session_entity_type_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2852,7 +3288,7 @@ def test_get_session_entity_type_rest_flattened(): def test_get_session_entity_type_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2867,7 +3303,7 @@ def test_get_session_entity_type_rest_flattened_error(transport: str = "rest"): def test_get_session_entity_type_rest_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2880,7 +3316,7 @@ def test_get_session_entity_type_rest_error(): ) def test_create_session_entity_type_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3012,7 +3448,7 @@ def test_create_session_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3021,7 +3457,7 @@ def test_create_session_entity_type_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3030,7 +3466,7 @@ def test_create_session_entity_type_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3073,7 +3509,7 @@ def test_create_session_entity_type_rest_required_fields( def test_create_session_entity_type_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_session_entity_type._get_unset_required_fields({}) @@ -3091,7 +3527,7 @@ def test_create_session_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_session_entity_type_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -3150,7 +3586,7 @@ def test_create_session_entity_type_rest_bad_request( request_type=gcd_session_entity_type.CreateSessionEntityTypeRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3172,7 +3608,7 @@ def test_create_session_entity_type_rest_bad_request( def test_create_session_entity_type_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3217,7 +3653,7 @@ def test_create_session_entity_type_rest_flattened(): def test_create_session_entity_type_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3235,7 +3671,7 @@ def test_create_session_entity_type_rest_flattened_error(transport: str = "rest" def test_create_session_entity_type_rest_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3248,7 +3684,7 @@ def test_create_session_entity_type_rest_error(): ) def test_update_session_entity_type_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3383,14 +3819,14 @@ def test_update_session_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_session_entity_type._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3399,7 +3835,7 @@ def test_update_session_entity_type_rest_required_fields( # verify required fields with non-default values are left alone client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3442,7 +3878,7 @@ def test_update_session_entity_type_rest_required_fields( def test_update_session_entity_type_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_session_entity_type._get_unset_required_fields({}) @@ -3452,7 +3888,7 @@ def test_update_session_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_session_entity_type_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -3511,7 +3947,7 @@ def test_update_session_entity_type_rest_bad_request( request_type=gcd_session_entity_type.UpdateSessionEntityTypeRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3537,7 +3973,7 @@ def test_update_session_entity_type_rest_bad_request( def test_update_session_entity_type_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3586,7 +4022,7 @@ def test_update_session_entity_type_rest_flattened(): def test_update_session_entity_type_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3604,7 +4040,7 @@ def test_update_session_entity_type_rest_flattened_error(transport: str = "rest" def test_update_session_entity_type_rest_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3617,7 +4053,7 @@ def test_update_session_entity_type_rest_error(): ) def test_delete_session_entity_type_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3665,7 +4101,7 @@ def test_delete_session_entity_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3674,7 +4110,7 @@ def test_delete_session_entity_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_session_entity_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3683,7 +4119,7 @@ def test_delete_session_entity_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3722,7 +4158,7 @@ def test_delete_session_entity_type_rest_required_fields( def test_delete_session_entity_type_rest_unset_required_fields(): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_session_entity_type._get_unset_required_fields({}) @@ -3732,7 +4168,7 @@ def test_delete_session_entity_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_session_entity_type_rest_interceptors(null_interceptor): transport = transports.SessionEntityTypesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionEntityTypesRestInterceptor(), @@ -3783,7 +4219,7 @@ def test_delete_session_entity_type_rest_bad_request( request_type=session_entity_type.DeleteSessionEntityTypeRequest, ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3807,7 +4243,7 @@ def test_delete_session_entity_type_rest_bad_request( def test_delete_session_entity_type_rest_flattened(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3849,7 +4285,7 @@ def test_delete_session_entity_type_rest_flattened(): def test_delete_session_entity_type_rest_flattened_error(transport: str = "rest"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3864,24 +4300,24 @@ def test_delete_session_entity_type_rest_flattened_error(transport: str = "rest" def test_delete_session_entity_type_rest_error(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionEntityTypesClient( @@ -3891,7 +4327,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3902,16 +4338,17 @@ 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 = SessionEntityTypesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionEntityTypesClient( @@ -3923,7 +4360,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SessionEntityTypesClient(transport=transport) assert client.transport is transport @@ -3932,13 +4369,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SessionEntityTypesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SessionEntityTypesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3955,7 +4392,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3969,7 +4406,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SessionEntityTypesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3977,7 +4414,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3989,7 +4426,7 @@ def test_session_entity_types_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SessionEntityTypesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4001,7 +4438,7 @@ def test_session_entity_types_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SessionEntityTypesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4042,7 +4479,7 @@ def test_session_entity_types_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SessionEntityTypesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4064,7 +4501,7 @@ def test_session_entity_types_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.session_entity_types.transports.SessionEntityTypesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SessionEntityTypesTransport() adc.assert_called_once() @@ -4072,7 +4509,7 @@ def test_session_entity_types_base_transport_with_adc(): def test_session_entity_types_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SessionEntityTypesClient() adc.assert_called_once_with( scopes=None, @@ -4095,7 +4532,7 @@ def test_session_entity_types_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4145,7 +4582,7 @@ def test_session_entity_types_transport_create_channel(transport_class, grpc_hel ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4178,7 +4615,7 @@ def test_session_entity_types_transport_create_channel(transport_class, grpc_hel def test_session_entity_types_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4216,7 +4653,7 @@ def test_session_entity_types_grpc_transport_client_cert_source_for_mtls( def test_session_entity_types_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4236,7 +4673,7 @@ def test_session_entity_types_http_transport_client_cert_source_for_mtls(): ) def test_session_entity_types_host_no_port(transport_name): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4259,7 +4696,7 @@ def test_session_entity_types_host_no_port(transport_name): ) def test_session_entity_types_host_with_port(transport_name): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4279,8 +4716,8 @@ def test_session_entity_types_host_with_port(transport_name): ], ) def test_session_entity_types_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SessionEntityTypesClient( credentials=creds1, transport=transport_name, @@ -4356,7 +4793,7 @@ def test_session_entity_types_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4572,7 +5009,7 @@ def test_client_with_default_client_info(): transports.SessionEntityTypesTransport, "_prep_wrapped_messages" ) as prep: client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4582,7 +5019,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SessionEntityTypesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4591,7 +5028,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4606,7 +5043,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4636,7 +5073,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4664,7 +5101,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4692,7 +5129,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4720,7 +5157,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4750,7 +5187,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4778,7 +5215,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4808,7 +5245,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4836,7 +5273,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4864,7 +5301,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4890,7 +5327,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4915,7 +5352,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4939,7 +5376,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4968,7 +5405,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4995,7 +5432,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5013,7 +5450,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -5029,7 +5466,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5054,7 +5491,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5080,7 +5517,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5109,7 +5546,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5138,7 +5575,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5156,7 +5593,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5174,7 +5611,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5199,7 +5636,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5225,7 +5662,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5254,7 +5691,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5283,7 +5720,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5301,7 +5738,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5319,7 +5756,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5344,7 +5781,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5370,7 +5807,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5399,7 +5836,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5428,7 +5865,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5446,7 +5883,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5464,7 +5901,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5489,7 +5926,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5514,7 +5951,9 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = SessionEntityTypesClient(credentials=ga_credentials.AnonymousCredentials()) + client = SessionEntityTypesClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5542,7 +5981,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5571,7 +6010,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5589,7 +6028,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = SessionEntityTypesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5613,7 +6052,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5630,7 +6069,7 @@ def test_client_ctx(): ] for transport in transports: client = SessionEntityTypesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5664,7 +6103,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py index 37132bd18428..d125601b24dc 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_sessions.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -80,6 +80,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -104,6 +127,244 @@ def test__get_default_mtls_endpoint(): assert SessionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert SessionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SessionsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SessionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SessionsClient._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 SessionsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SessionsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SessionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SessionsClient._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 SessionsClient._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 SessionsClient._get_client_cert_source(None, False) is None + assert ( + SessionsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + SessionsClient._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 ( + SessionsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SessionsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SessionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsClient), +) +@mock.patch.object( + SessionsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SessionsClient._DEFAULT_UNIVERSE + default_endpoint = SessionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SessionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SessionsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SessionsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SessionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SessionsClient._get_api_endpoint(None, None, default_universe, "always") + == SessionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SessionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SessionsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SessionsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SessionsClient._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 ( + SessionsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + SessionsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SessionsClient._get_universe_domain(None, None) + == SessionsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SessionsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SessionsClient, transports.SessionsGrpcTransport, "grpc"), + (SessionsClient, transports.SessionsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -113,7 +374,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_sessions_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -165,7 +426,7 @@ def test_sessions_client_service_account_always_use_jwt( ], ) def test_sessions_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -210,17 +471,21 @@ def test_sessions_client_get_transport_class(): ], ) @mock.patch.object( - SessionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SessionsClient) + SessionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsClient), ) @mock.patch.object( SessionsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsAsyncClient), ) def test_sessions_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(SessionsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -255,7 +520,9 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -285,15 +552,23 @@ def test_sessions_client_client_options(client_class, transport_class, transport # 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") @@ -303,7 +578,9 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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", @@ -321,7 +598,9 @@ def test_sessions_client_client_options(client_class, transport_class, transport 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, @@ -353,12 +632,14 @@ def test_sessions_client_client_options(client_class, transport_class, transport ], ) @mock.patch.object( - SessionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(SessionsClient) + SessionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsClient), ) @mock.patch.object( SessionsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SessionsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_sessions_client_mtls_env_auto( @@ -381,7 +662,9 @@ def test_sessions_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 @@ -413,7 +696,9 @@ def test_sessions_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 @@ -447,7 +732,9 @@ def test_sessions_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, @@ -533,6 +820,116 @@ def test_sessions_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", [SessionsClient, SessionsAsyncClient]) +@mock.patch.object( + SessionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsClient), +) +@mock.patch.object( + SessionsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SessionsAsyncClient), +) +def test_sessions_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SessionsClient._DEFAULT_UNIVERSE + default_endpoint = SessionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SessionsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -555,7 +952,9 @@ def test_sessions_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, @@ -590,7 +989,9 @@ def test_sessions_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, @@ -643,7 +1044,9 @@ def test_sessions_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, @@ -660,8 +1063,8 @@ def test_sessions_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -693,7 +1096,7 @@ def test_sessions_client_create_channel_credentials_file( ) def test_detect_intent(request_type, transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -725,7 +1128,7 @@ def test_detect_intent_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -742,7 +1145,7 @@ async def test_detect_intent_async( transport: str = "grpc_asyncio", request_type=gcd_session.DetectIntentRequest ): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -779,7 +1182,7 @@ async def test_detect_intent_async_from_dict(): def test_detect_intent_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -809,7 +1212,7 @@ def test_detect_intent_field_headers(): @pytest.mark.asyncio async def test_detect_intent_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -840,7 +1243,7 @@ async def test_detect_intent_field_headers_async(): def test_detect_intent_flattened(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -876,7 +1279,7 @@ def test_detect_intent_flattened(): def test_detect_intent_flattened_error(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -896,7 +1299,7 @@ def test_detect_intent_flattened_error(): @pytest.mark.asyncio async def test_detect_intent_flattened_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -937,7 +1340,7 @@ async def test_detect_intent_flattened_async(): @pytest.mark.asyncio async def test_detect_intent_flattened_error_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -963,7 +1366,7 @@ async def test_detect_intent_flattened_error_async(): ) def test_streaming_detect_intent(request_type, transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -995,7 +1398,7 @@ async def test_streaming_detect_intent_async( transport: str = "grpc_asyncio", request_type=session.StreamingDetectIntentRequest ): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1039,7 +1442,7 @@ async def test_streaming_detect_intent_async_from_dict(): ) def test_detect_intent_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1092,7 +1495,7 @@ def test_detect_intent_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).detect_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1101,7 +1504,7 @@ def test_detect_intent_rest_required_fields( jsonified_request["session"] = "session_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).detect_intent._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1110,7 +1513,7 @@ def test_detect_intent_rest_required_fields( assert jsonified_request["session"] == "session_value" client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1153,7 +1556,7 @@ def test_detect_intent_rest_required_fields( def test_detect_intent_rest_unset_required_fields(): transport = transports.SessionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.detect_intent._get_unset_required_fields({}) @@ -1171,7 +1574,7 @@ def test_detect_intent_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_detect_intent_rest_interceptors(null_interceptor): transport = transports.SessionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SessionsRestInterceptor(), ) client = SessionsClient(transport=transport) @@ -1227,7 +1630,7 @@ def test_detect_intent_rest_bad_request( transport: str = "rest", request_type=gcd_session.DetectIntentRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1249,7 +1652,7 @@ def test_detect_intent_rest_bad_request( def test_detect_intent_rest_flattened(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1296,7 +1699,7 @@ def test_detect_intent_rest_flattened(): def test_detect_intent_rest_flattened_error(transport: str = "rest"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1316,13 +1719,13 @@ def test_detect_intent_rest_flattened_error(transport: str = "rest"): def test_detect_intent_rest_error(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_streaming_detect_intent_rest_no_http_options(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = session.StreamingDetectIntentRequest() @@ -1333,7 +1736,7 @@ def test_streaming_detect_intent_rest_no_http_options(): def test_streaming_detect_intent_rest_error(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) # Since a `google.api.http` annotation is required for using a rest transport # method, this should error. @@ -1347,17 +1750,17 @@ def test_streaming_detect_intent_rest_error(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionsClient( @@ -1367,7 +1770,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1378,16 +1781,17 @@ 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 = SessionsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SessionsClient( @@ -1399,7 +1803,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SessionsClient(transport=transport) assert client.transport is transport @@ -1408,13 +1812,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SessionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SessionsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1431,7 +1835,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1445,7 +1849,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SessionsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1453,7 +1857,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1465,7 +1869,7 @@ def test_sessions_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SessionsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1477,7 +1881,7 @@ def test_sessions_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SessionsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1515,7 +1919,7 @@ def test_sessions_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SessionsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1537,7 +1941,7 @@ def test_sessions_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.sessions.transports.SessionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SessionsTransport() adc.assert_called_once() @@ -1545,7 +1949,7 @@ def test_sessions_base_transport_with_adc(): def test_sessions_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SessionsClient() adc.assert_called_once_with( scopes=None, @@ -1568,7 +1972,7 @@ def test_sessions_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1618,7 +2022,7 @@ def test_sessions_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1646,7 +2050,7 @@ def test_sessions_transport_create_channel(transport_class, grpc_helpers): [transports.SessionsGrpcTransport, transports.SessionsGrpcAsyncIOTransport], ) def test_sessions_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1684,7 +2088,7 @@ def test_sessions_grpc_transport_client_cert_source_for_mtls(transport_class): def test_sessions_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1704,7 +2108,7 @@ def test_sessions_http_transport_client_cert_source_for_mtls(): ) def test_sessions_host_no_port(transport_name): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -1727,7 +2131,7 @@ def test_sessions_host_no_port(transport_name): ) def test_sessions_host_with_port(transport_name): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -1747,8 +2151,8 @@ def test_sessions_host_with_port(transport_name): ], ) def test_sessions_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SessionsClient( credentials=creds1, transport=transport_name, @@ -1810,7 +2214,7 @@ def test_sessions_transport_channel_mtls_with_client_cert_source(transport_class mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2119,7 +2523,7 @@ def test_client_with_default_client_info(): transports.SessionsTransport, "_prep_wrapped_messages" ) as prep: client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2129,7 +2533,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SessionsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2138,7 +2542,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2153,7 +2557,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2183,7 +2587,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -2211,7 +2615,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2239,7 +2643,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2267,7 +2671,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2297,7 +2701,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2325,7 +2729,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2355,7 +2759,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2383,7 +2787,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2411,7 +2815,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2437,7 +2841,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2462,7 +2866,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2486,7 +2890,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2515,7 +2919,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2542,7 +2946,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -2560,7 +2964,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -2576,7 +2980,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2601,7 +3005,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2627,7 +3031,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2656,7 +3060,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2685,7 +3089,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2703,7 +3107,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2721,7 +3125,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2746,7 +3150,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2772,7 +3176,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2801,7 +3205,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2830,7 +3234,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2848,7 +3252,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2866,7 +3270,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2891,7 +3295,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2917,7 +3321,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2946,7 +3350,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2975,7 +3379,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -2993,7 +3397,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3011,7 +3415,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3036,7 +3440,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3061,7 +3465,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = SessionsClient(credentials=ga_credentials.AnonymousCredentials()) + client = SessionsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -3088,7 +3492,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = SessionsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = SessionsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -3116,7 +3520,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3134,7 +3538,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = SessionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -3158,7 +3562,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3175,7 +3579,7 @@ def test_client_ctx(): ] for transport in transports: client = SessionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3206,7 +3610,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, diff --git a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_versions.py b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_versions.py index 897c79e0246b..0834a1f64d2d 100644 --- a/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_versions.py +++ b/packages/google-cloud-dialogflow/tests/unit/gapic/dialogflow_v2beta1/test_versions.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -71,6 +71,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -95,6 +118,244 @@ def test__get_default_mtls_endpoint(): assert VersionsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert VersionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert VersionsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert VersionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + VersionsClient._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 VersionsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert VersionsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert VersionsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + VersionsClient._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 VersionsClient._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 VersionsClient._get_client_cert_source(None, False) is None + assert ( + VersionsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + VersionsClient._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 ( + VersionsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + VersionsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + VersionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsClient), +) +@mock.patch.object( + VersionsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = VersionsClient._DEFAULT_UNIVERSE + default_endpoint = VersionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = VersionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + VersionsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + VersionsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == VersionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + VersionsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + VersionsClient._get_api_endpoint(None, None, default_universe, "always") + == VersionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + VersionsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == VersionsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + VersionsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + VersionsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + VersionsClient._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 ( + VersionsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + VersionsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + VersionsClient._get_universe_domain(None, None) + == VersionsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + VersionsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (VersionsClient, transports.VersionsGrpcTransport, "grpc"), + (VersionsClient, transports.VersionsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -104,7 +365,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_versions_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -156,7 +417,7 @@ def test_versions_client_service_account_always_use_jwt( ], ) def test_versions_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -201,17 +462,21 @@ def test_versions_client_get_transport_class(): ], ) @mock.patch.object( - VersionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(VersionsClient) + VersionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsClient), ) @mock.patch.object( VersionsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(VersionsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsAsyncClient), ) def test_versions_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(VersionsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -246,7 +511,9 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -276,15 +543,23 @@ def test_versions_client_client_options(client_class, transport_class, transport # 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") @@ -294,7 +569,9 @@ def test_versions_client_client_options(client_class, transport_class, transport 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", @@ -312,7 +589,9 @@ def test_versions_client_client_options(client_class, transport_class, transport 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, @@ -344,12 +623,14 @@ def test_versions_client_client_options(client_class, transport_class, transport ], ) @mock.patch.object( - VersionsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(VersionsClient) + VersionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsClient), ) @mock.patch.object( VersionsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(VersionsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_versions_client_mtls_env_auto( @@ -372,7 +653,9 @@ def test_versions_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 @@ -404,7 +687,9 @@ def test_versions_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 @@ -438,7 +723,9 @@ def test_versions_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, @@ -524,6 +811,116 @@ def test_versions_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", [VersionsClient, VersionsAsyncClient]) +@mock.patch.object( + VersionsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsClient), +) +@mock.patch.object( + VersionsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(VersionsAsyncClient), +) +def test_versions_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = VersionsClient._DEFAULT_UNIVERSE + default_endpoint = VersionsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = VersionsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -546,7 +943,9 @@ def test_versions_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, @@ -581,7 +980,9 @@ def test_versions_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, @@ -634,7 +1035,9 @@ def test_versions_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, @@ -651,8 +1054,8 @@ def test_versions_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -684,7 +1087,7 @@ def test_versions_client_create_channel_credentials_file( ) def test_list_versions(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -714,7 +1117,7 @@ def test_list_versions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -731,7 +1134,7 @@ async def test_list_versions_async( transport: str = "grpc_asyncio", request_type=version.ListVersionsRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -766,7 +1169,7 @@ async def test_list_versions_async_from_dict(): def test_list_versions_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -796,7 +1199,7 @@ def test_list_versions_field_headers(): @pytest.mark.asyncio async def test_list_versions_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -827,7 +1230,7 @@ async def test_list_versions_field_headers_async(): def test_list_versions_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -851,7 +1254,7 @@ def test_list_versions_flattened(): def test_list_versions_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -866,7 +1269,7 @@ def test_list_versions_flattened_error(): @pytest.mark.asyncio async def test_list_versions_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -895,7 +1298,7 @@ async def test_list_versions_flattened_async(): @pytest.mark.asyncio async def test_list_versions_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -909,7 +1312,7 @@ async def test_list_versions_flattened_error_async(): def test_list_versions_pager(transport_name: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -959,7 +1362,7 @@ def test_list_versions_pager(transport_name: str = "grpc"): def test_list_versions_pages(transport_name: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1001,7 +1404,7 @@ def test_list_versions_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_versions_async_pager(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1051,7 +1454,7 @@ async def test_list_versions_async_pager(): @pytest.mark.asyncio async def test_list_versions_async_pages(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1106,7 +1509,7 @@ async def test_list_versions_async_pages(): ) def test_get_version(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1142,7 +1545,7 @@ def test_get_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1159,7 +1562,7 @@ async def test_get_version_async( transport: str = "grpc_asyncio", request_type=version.GetVersionRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1200,7 +1603,7 @@ async def test_get_version_async_from_dict(): def test_get_version_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1230,7 +1633,7 @@ def test_get_version_field_headers(): @pytest.mark.asyncio async def test_get_version_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1259,7 +1662,7 @@ async def test_get_version_field_headers_async(): def test_get_version_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1283,7 +1686,7 @@ def test_get_version_flattened(): def test_get_version_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1298,7 +1701,7 @@ def test_get_version_flattened_error(): @pytest.mark.asyncio async def test_get_version_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1325,7 +1728,7 @@ async def test_get_version_flattened_async(): @pytest.mark.asyncio async def test_get_version_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1346,7 +1749,7 @@ async def test_get_version_flattened_error_async(): ) def test_create_version(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1382,7 +1785,7 @@ def test_create_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1399,7 +1802,7 @@ async def test_create_version_async( transport: str = "grpc_asyncio", request_type=gcd_version.CreateVersionRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1440,7 +1843,7 @@ async def test_create_version_async_from_dict(): def test_create_version_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1470,7 +1873,7 @@ def test_create_version_field_headers(): @pytest.mark.asyncio async def test_create_version_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1499,7 +1902,7 @@ async def test_create_version_field_headers_async(): def test_create_version_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1527,7 +1930,7 @@ def test_create_version_flattened(): def test_create_version_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1543,7 +1946,7 @@ def test_create_version_flattened_error(): @pytest.mark.asyncio async def test_create_version_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1574,7 +1977,7 @@ async def test_create_version_flattened_async(): @pytest.mark.asyncio async def test_create_version_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1596,7 +1999,7 @@ async def test_create_version_flattened_error_async(): ) def test_update_version(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1632,7 +2035,7 @@ def test_update_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1649,7 +2052,7 @@ async def test_update_version_async( transport: str = "grpc_asyncio", request_type=gcd_version.UpdateVersionRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1690,7 +2093,7 @@ async def test_update_version_async_from_dict(): def test_update_version_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1720,7 +2123,7 @@ def test_update_version_field_headers(): @pytest.mark.asyncio async def test_update_version_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1749,7 +2152,7 @@ async def test_update_version_field_headers_async(): def test_update_version_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1777,7 +2180,7 @@ def test_update_version_flattened(): def test_update_version_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1793,7 +2196,7 @@ def test_update_version_flattened_error(): @pytest.mark.asyncio async def test_update_version_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1824,7 +2227,7 @@ async def test_update_version_flattened_async(): @pytest.mark.asyncio async def test_update_version_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1846,7 +2249,7 @@ async def test_update_version_flattened_error_async(): ) def test_delete_version(request_type, transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1873,7 +2276,7 @@ def test_delete_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1890,7 +2293,7 @@ async def test_delete_version_async( transport: str = "grpc_asyncio", request_type=version.DeleteVersionRequest ): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1920,7 +2323,7 @@ async def test_delete_version_async_from_dict(): def test_delete_version_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1950,7 +2353,7 @@ def test_delete_version_field_headers(): @pytest.mark.asyncio async def test_delete_version_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1979,7 +2382,7 @@ async def test_delete_version_field_headers_async(): def test_delete_version_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2003,7 +2406,7 @@ def test_delete_version_flattened(): def test_delete_version_flattened_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2018,7 +2421,7 @@ def test_delete_version_flattened_error(): @pytest.mark.asyncio async def test_delete_version_flattened_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2045,7 +2448,7 @@ async def test_delete_version_flattened_async(): @pytest.mark.asyncio async def test_delete_version_flattened_error_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2066,7 +2469,7 @@ async def test_delete_version_flattened_error_async(): ) def test_list_versions_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2115,7 +2518,7 @@ def test_list_versions_rest_required_fields(request_type=version.ListVersionsReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_versions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2124,7 +2527,7 @@ def test_list_versions_rest_required_fields(request_type=version.ListVersionsReq jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_versions._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2140,7 +2543,7 @@ def test_list_versions_rest_required_fields(request_type=version.ListVersionsReq assert jsonified_request["parent"] == "parent_value" client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2182,7 +2585,7 @@ def test_list_versions_rest_required_fields(request_type=version.ListVersionsReq def test_list_versions_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_versions._get_unset_required_fields({}) @@ -2200,7 +2603,7 @@ def test_list_versions_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_versions_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -2254,7 +2657,7 @@ def test_list_versions_rest_bad_request( transport: str = "rest", request_type=version.ListVersionsRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2276,7 +2679,7 @@ def test_list_versions_rest_bad_request( def test_list_versions_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2317,7 +2720,7 @@ def test_list_versions_rest_flattened(): def test_list_versions_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2332,7 +2735,7 @@ def test_list_versions_rest_flattened_error(transport: str = "rest"): def test_list_versions_rest_pager(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2400,7 +2803,7 @@ def test_list_versions_rest_pager(transport: str = "rest"): ) def test_get_version_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2455,7 +2858,7 @@ def test_get_version_rest_required_fields(request_type=version.GetVersionRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2464,7 +2867,7 @@ def test_get_version_rest_required_fields(request_type=version.GetVersionRequest jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2473,7 +2876,7 @@ def test_get_version_rest_required_fields(request_type=version.GetVersionRequest assert jsonified_request["name"] == "name_value" client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2515,7 +2918,7 @@ def test_get_version_rest_required_fields(request_type=version.GetVersionRequest def test_get_version_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_version._get_unset_required_fields({}) @@ -2525,7 +2928,7 @@ def test_get_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_version_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -2577,7 +2980,7 @@ def test_get_version_rest_bad_request( transport: str = "rest", request_type=version.GetVersionRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2599,7 +3002,7 @@ def test_get_version_rest_bad_request( def test_get_version_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2640,7 +3043,7 @@ def test_get_version_rest_flattened(): def test_get_version_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2655,7 +3058,7 @@ def test_get_version_rest_flattened_error(transport: str = "rest"): def test_get_version_rest_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2668,7 +3071,7 @@ def test_get_version_rest_error(): ) def test_create_version_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2799,7 +3202,7 @@ def test_create_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2808,7 +3211,7 @@ def test_create_version_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2817,7 +3220,7 @@ def test_create_version_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2860,7 +3263,7 @@ def test_create_version_rest_required_fields( def test_create_version_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_version._get_unset_required_fields({}) @@ -2878,7 +3281,7 @@ def test_create_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_version_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -2932,7 +3335,7 @@ def test_create_version_rest_bad_request( transport: str = "rest", request_type=gcd_version.CreateVersionRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2954,7 +3357,7 @@ def test_create_version_rest_bad_request( def test_create_version_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2996,7 +3399,7 @@ def test_create_version_rest_flattened(): def test_create_version_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3012,7 +3415,7 @@ def test_create_version_rest_flattened_error(transport: str = "rest"): def test_create_version_rest_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3025,7 +3428,7 @@ def test_create_version_rest_error(): ) def test_update_version_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3155,14 +3558,14 @@ def test_update_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_version._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3171,7 +3574,7 @@ def test_update_version_rest_required_fields( # verify required fields with non-default values are left alone client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3214,7 +3617,7 @@ def test_update_version_rest_required_fields( def test_update_version_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_version._get_unset_required_fields({}) @@ -3232,7 +3635,7 @@ def test_update_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_version_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -3286,7 +3689,7 @@ def test_update_version_rest_bad_request( transport: str = "rest", request_type=gcd_version.UpdateVersionRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3308,7 +3711,7 @@ def test_update_version_rest_bad_request( def test_update_version_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3353,7 +3756,7 @@ def test_update_version_rest_flattened(): def test_update_version_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3369,7 +3772,7 @@ def test_update_version_rest_flattened_error(transport: str = "rest"): def test_update_version_rest_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3382,7 +3785,7 @@ def test_update_version_rest_error(): ) def test_delete_version_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3426,7 +3829,7 @@ def test_delete_version_rest_required_fields(request_type=version.DeleteVersionR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3435,7 +3838,7 @@ def test_delete_version_rest_required_fields(request_type=version.DeleteVersionR jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3444,7 +3847,7 @@ def test_delete_version_rest_required_fields(request_type=version.DeleteVersionR assert jsonified_request["name"] == "name_value" client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3483,7 +3886,7 @@ def test_delete_version_rest_required_fields(request_type=version.DeleteVersionR def test_delete_version_rest_unset_required_fields(): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_version._get_unset_required_fields({}) @@ -3493,7 +3896,7 @@ def test_delete_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_version_rest_interceptors(null_interceptor): transport = transports.VersionsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.VersionsRestInterceptor(), ) client = VersionsClient(transport=transport) @@ -3539,7 +3942,7 @@ def test_delete_version_rest_bad_request( transport: str = "rest", request_type=version.DeleteVersionRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3561,7 +3964,7 @@ def test_delete_version_rest_bad_request( def test_delete_version_rest_flattened(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3600,7 +4003,7 @@ def test_delete_version_rest_flattened(): def test_delete_version_rest_flattened_error(transport: str = "rest"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3615,24 +4018,24 @@ def test_delete_version_rest_flattened_error(transport: str = "rest"): def test_delete_version_rest_error(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = VersionsClient( @@ -3642,7 +4045,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3653,16 +4056,17 @@ 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 = VersionsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = VersionsClient( @@ -3674,7 +4078,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = VersionsClient(transport=transport) assert client.transport is transport @@ -3683,13 +4087,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.VersionsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.VersionsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3706,7 +4110,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3720,7 +4124,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = VersionsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3728,7 +4132,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3740,7 +4144,7 @@ def test_versions_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.VersionsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3752,7 +4156,7 @@ def test_versions_base_transport(): ) as Transport: Transport.return_value = None transport = transports.VersionsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3793,7 +4197,7 @@ def test_versions_base_transport_with_credentials_file(): "google.cloud.dialogflow_v2beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.VersionsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3815,7 +4219,7 @@ def test_versions_base_transport_with_adc(): "google.cloud.dialogflow_v2beta1.services.versions.transports.VersionsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.VersionsTransport() adc.assert_called_once() @@ -3823,7 +4227,7 @@ def test_versions_base_transport_with_adc(): def test_versions_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) VersionsClient() adc.assert_called_once_with( scopes=None, @@ -3846,7 +4250,7 @@ def test_versions_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -3896,7 +4300,7 @@ def test_versions_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3924,7 +4328,7 @@ def test_versions_transport_create_channel(transport_class, grpc_helpers): [transports.VersionsGrpcTransport, transports.VersionsGrpcAsyncIOTransport], ) def test_versions_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3962,7 +4366,7 @@ def test_versions_grpc_transport_client_cert_source_for_mtls(transport_class): def test_versions_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -3982,7 +4386,7 @@ def test_versions_http_transport_client_cert_source_for_mtls(): ) def test_versions_host_no_port(transport_name): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com" ), @@ -4005,7 +4409,7 @@ def test_versions_host_no_port(transport_name): ) def test_versions_host_with_port(transport_name): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dialogflow.googleapis.com:8000" ), @@ -4025,8 +4429,8 @@ def test_versions_host_with_port(transport_name): ], ) def test_versions_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = VersionsClient( credentials=creds1, transport=transport_name, @@ -4097,7 +4501,7 @@ def test_versions_transport_channel_mtls_with_client_cert_source(transport_class mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4303,7 +4707,7 @@ def test_client_with_default_client_info(): transports.VersionsTransport, "_prep_wrapped_messages" ) as prep: client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4313,7 +4717,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = VersionsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4322,7 +4726,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4337,7 +4741,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4367,7 +4771,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -4395,7 +4799,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4423,7 +4827,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4451,7 +4855,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4481,7 +4885,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4509,7 +4913,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4539,7 +4943,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4567,7 +4971,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4595,7 +4999,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4621,7 +5025,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4646,7 +5050,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4670,7 +5074,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4699,7 +5103,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4726,7 +5130,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4744,7 +5148,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -4760,7 +5164,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4785,7 +5189,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4811,7 +5215,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4840,7 +5244,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4869,7 +5273,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4887,7 +5291,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4905,7 +5309,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4930,7 +5334,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4956,7 +5360,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4985,7 +5389,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5014,7 +5418,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5032,7 +5436,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5050,7 +5454,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5075,7 +5479,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5101,7 +5505,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5130,7 +5534,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5159,7 +5563,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5177,7 +5581,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5195,7 +5599,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5220,7 +5624,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5245,7 +5649,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = VersionsClient(credentials=ga_credentials.AnonymousCredentials()) + client = VersionsClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5272,7 +5676,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = VersionsAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = VersionsAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -5300,7 +5704,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5318,7 +5722,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = VersionsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -5342,7 +5746,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5359,7 +5763,7 @@ def test_client_ctx(): ] for transport in transports: client = VersionsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5390,7 +5794,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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine/gapic_version.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine/gapic_version.py index 768cd2103fa5..360a0d13ebdd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine/gapic_version.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.11.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/gapic_version.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/gapic_version.py index 768cd2103fa5..360a0d13ebdd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/gapic_version.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.11.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/async_client.py index 40637645e80f..c814601565f9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -57,8 +57,12 @@ class CompletionServiceAsyncClient: _client: CompletionServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = CompletionServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = CompletionServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(CompletionServiceClient.data_store_path) parse_data_store_path = staticmethod(CompletionServiceClient.parse_data_store_path) @@ -165,6 +169,25 @@ def transport(self) -> CompletionServiceTransport: """ 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(CompletionServiceClient).get_transport_class, type(CompletionServiceClient) ) @@ -177,7 +200,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the completion service client. + """Instantiates the completion service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -188,23 +211,38 @@ def __init__( transport (Union[str, ~.CompletionServiceTransport]): 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. @@ -291,6 +329,9 @@ async def sample_complete_query(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -345,6 +386,9 @@ async def list_operations( 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, @@ -399,6 +443,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/client.py index 7581ed855048..f2fccde33768 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -127,11 +128,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -282,7 +287,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 @@ -312,6 +317,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") @@ -345,6 +355,175 @@ 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 + + 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 + + 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 = CompletionServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = CompletionServiceClient._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 = CompletionServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = CompletionServiceClient._DEFAULT_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 CompletionServiceClient._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, *, @@ -364,22 +543,32 @@ def __init__( transport (Union[str, CompletionServiceTransport]): 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. @@ -390,17 +579,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, + ) = CompletionServiceClient._read_environment_variables() + self._client_cert_source = CompletionServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = CompletionServiceClient._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" @@ -409,20 +615,33 @@ 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, CompletionServiceTransport): + transport_provided = isinstance(transport, CompletionServiceTransport) + if transport_provided: # transport is a CompletionServiceTransport 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(CompletionServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or CompletionServiceClient._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( @@ -432,17 +651,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 complete_query( @@ -521,6 +740,9 @@ def sample_complete_query(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -588,6 +810,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -642,6 +867,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/base.py index 0abc126bcc17..be1a4caf81fa 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc.py index 289d48e74018..d03aeff728bb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc_asyncio.py index c356218365fb..40a0ac2a07e4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/rest.py index 65c179fd339a..473e5905ad40 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/completion_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -189,7 +189,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/async_client.py index 277846750242..258e252faf07 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -67,8 +67,14 @@ class ConversationalSearchServiceAsyncClient: _client: ConversationalSearchServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ConversationalSearchServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ( + ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE + ) + _DEFAULT_UNIVERSE = ConversationalSearchServiceClient._DEFAULT_UNIVERSE conversation_path = staticmethod( ConversationalSearchServiceClient.conversation_path @@ -199,6 +205,25 @@ def transport(self) -> ConversationalSearchServiceTransport: """ 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(ConversationalSearchServiceClient).get_transport_class, type(ConversationalSearchServiceClient), @@ -212,7 +237,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the conversational search service client. + """Instantiates the conversational search service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -223,23 +248,38 @@ def __init__( transport (Union[str, ~.ConversationalSearchServiceTransport]): 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. @@ -360,6 +400,9 @@ async def sample_converse_conversation(): 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, @@ -477,6 +520,9 @@ async def sample_create_conversation(): 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, @@ -577,6 +623,9 @@ async def sample_delete_conversation(): 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, @@ -697,6 +746,9 @@ async def sample_update_conversation(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -801,6 +853,9 @@ async def sample_get_conversation(): 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, @@ -909,6 +964,9 @@ async def sample_list_conversations(): 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, @@ -972,6 +1030,9 @@ async def list_operations( 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, @@ -1026,6 +1087,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/client.py index 6233493d53bb..38b0df6eabba 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -141,11 +142,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -370,7 +375,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 @@ -400,6 +405,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") @@ -433,6 +443,177 @@ 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 + + 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 + + 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 = ConversationalSearchServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + ConversationalSearchServiceClient._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 = ConversationalSearchServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ConversationalSearchServiceClient._DEFAULT_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 ConversationalSearchServiceClient._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, *, @@ -452,22 +633,32 @@ def __init__( transport (Union[str, ConversationalSearchServiceTransport]): 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. @@ -478,17 +669,36 @@ 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, + ) = ConversationalSearchServiceClient._read_environment_variables() + self._client_cert_source = ( + ConversationalSearchServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + ) + self._universe_domain = ConversationalSearchServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -497,20 +707,33 @@ 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, ConversationalSearchServiceTransport): + transport_provided = isinstance(transport, ConversationalSearchServiceTransport) + if transport_provided: # transport is a ConversationalSearchServiceTransport 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(ConversationalSearchServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or ConversationalSearchServiceClient._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( @@ -520,17 +743,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 converse_conversation( @@ -644,6 +867,9 @@ def sample_converse_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -763,6 +989,9 @@ def sample_create_conversation(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -865,6 +1094,9 @@ def sample_delete_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -987,6 +1219,9 @@ def sample_update_conversation(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1093,6 +1328,9 @@ def sample_get_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1203,6 +1441,9 @@ def sample_list_conversations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1279,6 +1520,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1333,6 +1577,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/base.py index 0282aecd2a61..28f7c2d0a5bb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/base.py @@ -61,7 +61,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -124,6 +124,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-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc.py index a2540306be33..c6e1ce16fa23 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc_asyncio.py index 08cd5e285faf..e8562b883ec1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/grpc_asyncio.py @@ -115,7 +115,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/rest.py index a50ffad1fa57..dea9df990d58 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/conversational_search_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -349,7 +349,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/async_client.py index e6682a0890ee..02b806ef657c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -70,8 +70,12 @@ class DocumentServiceAsyncClient: _client: DocumentServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DocumentServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DocumentServiceClient._DEFAULT_UNIVERSE branch_path = staticmethod(DocumentServiceClient.branch_path) parse_branch_path = staticmethod(DocumentServiceClient.parse_branch_path) @@ -180,6 +184,25 @@ def transport(self) -> DocumentServiceTransport: """ 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(DocumentServiceClient).get_transport_class, type(DocumentServiceClient) ) @@ -192,7 +215,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the document service client. + """Instantiates the document service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -203,23 +226,38 @@ def __init__( transport (Union[str, ~.DocumentServiceTransport]): 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. @@ -335,6 +373,9 @@ async def sample_get_document(): 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, @@ -452,6 +493,9 @@ async def sample_list_documents(): 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, @@ -605,6 +649,9 @@ async def sample_create_document(): 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, @@ -688,6 +735,9 @@ async def sample_update_document(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -794,6 +844,9 @@ async def sample_delete_document(): 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, @@ -896,6 +949,9 @@ async def sample_import_documents(): 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, @@ -1013,6 +1069,9 @@ async def sample_purge_documents(): 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, @@ -1075,6 +1134,9 @@ async def list_operations( 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, @@ -1129,6 +1191,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/client.py index 81a09e11afa4..a6cbe17fcaf1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -140,11 +141,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -323,7 +328,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 @@ -353,6 +358,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") @@ -386,6 +396,175 @@ 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 + + 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 + + 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 = DocumentServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DocumentServiceClient._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 = DocumentServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DocumentServiceClient._DEFAULT_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 DocumentServiceClient._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, *, @@ -405,22 +584,32 @@ def __init__( transport (Union[str, DocumentServiceTransport]): 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. @@ -431,17 +620,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, + ) = DocumentServiceClient._read_environment_variables() + self._client_cert_source = DocumentServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = DocumentServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -450,20 +656,33 @@ 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, DocumentServiceTransport): + transport_provided = isinstance(transport, DocumentServiceTransport) + if transport_provided: # transport is a DocumentServiceTransport 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(DocumentServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or DocumentServiceClient._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( @@ -473,17 +692,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 get_document( @@ -590,6 +809,9 @@ def sample_get_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -707,6 +929,9 @@ def sample_list_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -860,6 +1085,9 @@ def sample_create_document(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -944,6 +1172,9 @@ def sample_update_document(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1050,6 +1281,9 @@ def sample_delete_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1144,6 +1378,9 @@ def sample_import_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1262,6 +1499,9 @@ def sample_purge_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1337,6 +1577,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1391,6 +1634,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/base.py index 11db19eab2fc..3e4103550e2d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/base.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -128,6 +128,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-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc.py index a72e08c2cf96..c433974fc55f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc.py @@ -74,7 +74,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc_asyncio.py index 1fadd47aa875..c94183acb90d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/grpc_asyncio.py @@ -119,7 +119,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/rest.py index 34cc61bbb710..e3818ac384b3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/document_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -371,7 +371,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/async_client.py index 6330e0be64f3..a1be3c5821f0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -66,8 +66,12 @@ class SchemaServiceAsyncClient: _client: SchemaServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SchemaServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SchemaServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(SchemaServiceClient.data_store_path) parse_data_store_path = staticmethod(SchemaServiceClient.parse_data_store_path) @@ -176,6 +180,25 @@ def transport(self) -> SchemaServiceTransport: """ 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(SchemaServiceClient).get_transport_class, type(SchemaServiceClient) ) @@ -188,7 +211,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the schema service client. + """Instantiates the schema service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -199,23 +222,38 @@ def __init__( transport (Union[str, ~.SchemaServiceTransport]): 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. @@ -320,6 +358,9 @@ async def sample_get_schema(): 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, @@ -430,6 +471,9 @@ async def sample_list_schemas(): 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, @@ -579,6 +623,9 @@ async def sample_create_schema(): 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, @@ -677,6 +724,9 @@ async def sample_update_schema(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -803,6 +853,9 @@ async def sample_delete_schema(): 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, @@ -865,6 +918,9 @@ async def list_operations( 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, @@ -919,6 +975,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/client.py index 8adf5f8e2286..23a61164a0ee 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -134,11 +135,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -313,7 +318,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 @@ -343,6 +348,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") @@ -376,6 +386,175 @@ 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 + + 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 + + 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 = SchemaServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SchemaServiceClient._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 = SchemaServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SchemaServiceClient._DEFAULT_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 SchemaServiceClient._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, *, @@ -395,22 +574,32 @@ def __init__( transport (Union[str, SchemaServiceTransport]): 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. @@ -421,17 +610,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, + ) = SchemaServiceClient._read_environment_variables() + self._client_cert_source = SchemaServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = SchemaServiceClient._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" @@ -440,20 +646,33 @@ 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, SchemaServiceTransport): + transport_provided = isinstance(transport, SchemaServiceTransport) + if transport_provided: # transport is a SchemaServiceTransport 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(SchemaServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SchemaServiceClient._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( @@ -463,17 +682,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 get_schema( @@ -569,6 +788,9 @@ def sample_get_schema(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -679,6 +901,9 @@ def sample_list_schemas(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -828,6 +1053,9 @@ def sample_create_schema(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -927,6 +1155,9 @@ def sample_update_schema(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1053,6 +1284,9 @@ def sample_delete_schema(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1128,6 +1362,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1182,6 +1419,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/base.py index 932dbeb10911..e4caf73afe6b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc.py index 0af91b6a2992..ca43e36f17c3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc_asyncio.py index 38ed75c0f600..586b2369bb9a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/rest.py index 0cf8d3f891f6..3af92401db53 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/schema_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -318,7 +318,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/async_client.py index 76adca50296f..f327f304277c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -58,8 +58,12 @@ class SearchServiceAsyncClient: _client: SearchServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SearchServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SearchServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SearchServiceClient._DEFAULT_UNIVERSE branch_path = staticmethod(SearchServiceClient.branch_path) parse_branch_path = staticmethod(SearchServiceClient.parse_branch_path) @@ -172,6 +176,25 @@ def transport(self) -> SearchServiceTransport: """ 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(SearchServiceClient).get_transport_class, type(SearchServiceClient) ) @@ -184,7 +207,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the search service client. + """Instantiates the search service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -195,23 +218,38 @@ def __init__( transport (Union[str, ~.SearchServiceTransport]): 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. @@ -300,6 +338,9 @@ async def sample_search(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -363,6 +404,9 @@ async def list_operations( 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, @@ -417,6 +461,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/client.py index 828df345f2ba..8eb85d014d26 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -126,11 +127,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -333,7 +338,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 @@ -363,6 +368,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") @@ -396,6 +406,175 @@ 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 + + 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 + + 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 = SearchServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SearchServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SearchServiceClient._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 = SearchServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SearchServiceClient._DEFAULT_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 SearchServiceClient._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, *, @@ -415,22 +594,32 @@ def __init__( transport (Union[str, SearchServiceTransport]): 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. @@ -441,17 +630,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, + ) = SearchServiceClient._read_environment_variables() + self._client_cert_source = SearchServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = SearchServiceClient._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" @@ -460,20 +666,33 @@ 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, SearchServiceTransport): + transport_provided = isinstance(transport, SearchServiceTransport) + if transport_provided: # transport is a SearchServiceTransport 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(SearchServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SearchServiceClient._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( @@ -483,17 +702,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 search( @@ -574,6 +793,9 @@ def sample_search(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -650,6 +872,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -704,6 +929,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/base.py index 05d5a4a43be7..70fce00d051c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc.py index 939a5e5f2dd5..490a347fc53c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc_asyncio.py index ac54315a2af6..d9950fc1b3d0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/rest.py index 2f0c59d2e14a..c3349a73b1f7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/search_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -187,7 +187,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/async_client.py index e713082443ec..998ba78d29b6 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.api import httpbody_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -69,8 +69,12 @@ class UserEventServiceAsyncClient: _client: UserEventServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = UserEventServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = UserEventServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(UserEventServiceClient.data_store_path) parse_data_store_path = staticmethod(UserEventServiceClient.parse_data_store_path) @@ -179,6 +183,25 @@ def transport(self) -> UserEventServiceTransport: """ 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(UserEventServiceClient).get_transport_class, type(UserEventServiceClient) ) @@ -191,7 +214,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the user event service client. + """Instantiates the user event service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -202,23 +225,38 @@ def __init__( transport (Union[str, ~.UserEventServiceTransport]): 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. @@ -301,6 +339,9 @@ async def sample_write_user_event(): 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, @@ -434,6 +475,9 @@ async def sample_collect_user_event(): 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, @@ -544,6 +588,9 @@ async def sample_import_user_events(): 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, @@ -606,6 +653,9 @@ async def list_operations( 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, @@ -660,6 +710,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/client.py index 64f3ccaf9baa..9981ce150283 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1 import gapic_version as package_version 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.api import httpbody_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -139,11 +140,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -320,7 +325,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 @@ -350,6 +355,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") @@ -383,6 +393,175 @@ 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 + + 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 + + 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 = UserEventServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = UserEventServiceClient._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 = UserEventServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = UserEventServiceClient._DEFAULT_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 UserEventServiceClient._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, *, @@ -402,22 +581,32 @@ def __init__( transport (Union[str, UserEventServiceTransport]): 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. @@ -428,17 +617,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = UserEventServiceClient._read_environment_variables() + self._client_cert_source = UserEventServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = UserEventServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -447,20 +653,33 @@ 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, UserEventServiceTransport): + transport_provided = isinstance(transport, UserEventServiceTransport) + if transport_provided: # transport is a UserEventServiceTransport 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(UserEventServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or UserEventServiceClient._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( @@ -470,17 +689,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 write_user_event( @@ -555,6 +774,9 @@ def sample_write_user_event(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -689,6 +911,9 @@ def sample_collect_user_event(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -791,6 +1016,9 @@ def sample_import_user_events(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -866,6 +1094,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -920,6 +1151,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/base.py index 0e0d325391e3..38f13d85ed3b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -126,6 +126,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-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc.py index c825c4b7f2b5..8bcd526c9e9d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc.py @@ -71,7 +71,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc_asyncio.py index 6b89e4921ef4..94fc01f4e71c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/grpc_asyncio.py @@ -116,7 +116,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/rest.py index 68914d302fdc..b937466f5e1d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1/services/user_event_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.api import httpbody_pb2 # type: ignore @@ -263,7 +263,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/gapic_version.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/gapic_version.py index 768cd2103fa5..360a0d13ebdd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/gapic_version.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.11.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/async_client.py index 68c70af5c65b..ffc349baa03a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -57,8 +57,12 @@ class CompletionServiceAsyncClient: _client: CompletionServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = CompletionServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = CompletionServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(CompletionServiceClient.data_store_path) parse_data_store_path = staticmethod(CompletionServiceClient.parse_data_store_path) @@ -165,6 +169,25 @@ def transport(self) -> CompletionServiceTransport: """ 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(CompletionServiceClient).get_transport_class, type(CompletionServiceClient) ) @@ -177,7 +200,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the completion service client. + """Instantiates the completion service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -188,23 +211,38 @@ def __init__( transport (Union[str, ~.CompletionServiceTransport]): 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. @@ -291,6 +329,9 @@ async def sample_complete_query(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -345,6 +386,9 @@ async def list_operations( 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, @@ -399,6 +443,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/client.py index 5a6e52ef58b5..bfb3faf1fbba 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -127,11 +128,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -282,7 +287,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 @@ -312,6 +317,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") @@ -345,6 +355,175 @@ 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 + + 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 + + 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 = CompletionServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = CompletionServiceClient._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 = CompletionServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = CompletionServiceClient._DEFAULT_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 CompletionServiceClient._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, *, @@ -364,22 +543,32 @@ def __init__( transport (Union[str, CompletionServiceTransport]): 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. @@ -390,17 +579,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, + ) = CompletionServiceClient._read_environment_variables() + self._client_cert_source = CompletionServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = CompletionServiceClient._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" @@ -409,20 +615,33 @@ 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, CompletionServiceTransport): + transport_provided = isinstance(transport, CompletionServiceTransport) + if transport_provided: # transport is a CompletionServiceTransport 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(CompletionServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or CompletionServiceClient._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( @@ -432,17 +651,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 complete_query( @@ -521,6 +740,9 @@ def sample_complete_query(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -588,6 +810,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -642,6 +867,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/base.py index f606135eda7a..81a3e2f4f539 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc.py index 3fb0584efae2..a14d1a97aa9a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc_asyncio.py index 016db436319d..ada716028235 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/rest.py index ee50f24b9c33..3bf2e344c789 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/completion_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -189,7 +189,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/async_client.py index 64939fb36609..efb3fab8a14b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -67,8 +67,14 @@ class ConversationalSearchServiceAsyncClient: _client: ConversationalSearchServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ConversationalSearchServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ( + ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE + ) + _DEFAULT_UNIVERSE = ConversationalSearchServiceClient._DEFAULT_UNIVERSE conversation_path = staticmethod( ConversationalSearchServiceClient.conversation_path @@ -199,6 +205,25 @@ def transport(self) -> ConversationalSearchServiceTransport: """ 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(ConversationalSearchServiceClient).get_transport_class, type(ConversationalSearchServiceClient), @@ -212,7 +237,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the conversational search service client. + """Instantiates the conversational search service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -223,23 +248,38 @@ def __init__( transport (Union[str, ~.ConversationalSearchServiceTransport]): 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. @@ -360,6 +400,9 @@ async def sample_converse_conversation(): 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, @@ -477,6 +520,9 @@ async def sample_create_conversation(): 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, @@ -577,6 +623,9 @@ async def sample_delete_conversation(): 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, @@ -697,6 +746,9 @@ async def sample_update_conversation(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -801,6 +853,9 @@ async def sample_get_conversation(): 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, @@ -909,6 +964,9 @@ async def sample_list_conversations(): 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, @@ -972,6 +1030,9 @@ async def list_operations( 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, @@ -1026,6 +1087,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/client.py index f1aadf612bdc..f2c9c49cf503 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -141,11 +142,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -370,7 +375,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 @@ -400,6 +405,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") @@ -433,6 +443,177 @@ 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 + + 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 + + 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 = ConversationalSearchServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + ConversationalSearchServiceClient._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 = ConversationalSearchServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ConversationalSearchServiceClient._DEFAULT_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 ConversationalSearchServiceClient._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, *, @@ -452,22 +633,32 @@ def __init__( transport (Union[str, ConversationalSearchServiceTransport]): 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. @@ -478,17 +669,36 @@ 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, + ) = ConversationalSearchServiceClient._read_environment_variables() + self._client_cert_source = ( + ConversationalSearchServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + ) + self._universe_domain = ConversationalSearchServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -497,20 +707,33 @@ 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, ConversationalSearchServiceTransport): + transport_provided = isinstance(transport, ConversationalSearchServiceTransport) + if transport_provided: # transport is a ConversationalSearchServiceTransport 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(ConversationalSearchServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or ConversationalSearchServiceClient._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( @@ -520,17 +743,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 converse_conversation( @@ -644,6 +867,9 @@ def sample_converse_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -763,6 +989,9 @@ def sample_create_conversation(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -865,6 +1094,9 @@ def sample_delete_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -987,6 +1219,9 @@ def sample_update_conversation(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1093,6 +1328,9 @@ def sample_get_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1203,6 +1441,9 @@ def sample_list_conversations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1279,6 +1520,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1333,6 +1577,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/base.py index 125631771e9b..53bafc3c336e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/base.py @@ -61,7 +61,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -124,6 +124,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc.py index aff971857b93..d96692eff8de 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc_asyncio.py index 64a3f13fd49e..9b493fd4e3bb 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/grpc_asyncio.py @@ -115,7 +115,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/rest.py index 12b9218eb744..07a1196bc3dd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/conversational_search_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -349,7 +349,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/async_client.py index a82cc144f748..ab9902ee66fa 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -69,8 +69,12 @@ class DataStoreServiceAsyncClient: _client: DataStoreServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DataStoreServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DataStoreServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DataStoreServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DataStoreServiceClient._DEFAULT_UNIVERSE collection_path = staticmethod(DataStoreServiceClient.collection_path) parse_collection_path = staticmethod(DataStoreServiceClient.parse_collection_path) @@ -179,6 +183,25 @@ def transport(self) -> DataStoreServiceTransport: """ 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(DataStoreServiceClient).get_transport_class, type(DataStoreServiceClient) ) @@ -191,7 +214,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the data store service client. + """Instantiates the data store service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -202,23 +225,38 @@ def __init__( transport (Union[str, ~.DataStoreServiceTransport]): 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. @@ -373,6 +411,9 @@ async def sample_create_data_store(): 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, @@ -496,6 +537,9 @@ async def sample_get_data_store(): 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, @@ -611,6 +655,9 @@ async def sample_list_data_stores(): 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, @@ -751,6 +798,9 @@ async def sample_delete_data_store(): 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, @@ -894,6 +944,9 @@ async def sample_update_data_store(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -948,6 +1001,9 @@ async def list_operations( 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, @@ -1002,6 +1058,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/client.py index 449f463d2755..d8e866af3fcc 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -139,11 +140,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -318,7 +323,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 @@ -348,6 +353,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") @@ -381,6 +391,175 @@ 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 + + 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 + + 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 = DataStoreServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DataStoreServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DataStoreServiceClient._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 = DataStoreServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DataStoreServiceClient._DEFAULT_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 DataStoreServiceClient._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, *, @@ -400,22 +579,32 @@ def __init__( transport (Union[str, DataStoreServiceTransport]): 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. @@ -426,17 +615,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, + ) = DataStoreServiceClient._read_environment_variables() + self._client_cert_source = DataStoreServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = DataStoreServiceClient._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" @@ -445,20 +651,33 @@ 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, DataStoreServiceTransport): + transport_provided = isinstance(transport, DataStoreServiceTransport) + if transport_provided: # transport is a DataStoreServiceTransport 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(DataStoreServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or DataStoreServiceClient._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( @@ -468,17 +687,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 create_data_store( @@ -624,6 +843,9 @@ def sample_create_data_store(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -747,6 +969,9 @@ def sample_get_data_store(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -862,6 +1087,9 @@ def sample_list_data_stores(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1002,6 +1230,9 @@ def sample_delete_data_store(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1145,6 +1376,9 @@ def sample_update_data_store(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1212,6 +1446,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1266,6 +1503,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/base.py index 9a8b0ba5311f..2f360afc09f4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/base.py @@ -60,7 +60,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -123,6 +123,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc.py index 56ae5d0c24f2..cc57c835c298 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc.py @@ -69,7 +69,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc_asyncio.py index 95fdaeb4fee1..561dfe31e251 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/grpc_asyncio.py @@ -114,7 +114,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/rest.py index 24412299c59b..5648be51dddd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/data_store_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -323,7 +323,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/async_client.py index d71c3d08f495..f34663ccfbfe 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -70,8 +70,12 @@ class DocumentServiceAsyncClient: _client: DocumentServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DocumentServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DocumentServiceClient._DEFAULT_UNIVERSE branch_path = staticmethod(DocumentServiceClient.branch_path) parse_branch_path = staticmethod(DocumentServiceClient.parse_branch_path) @@ -180,6 +184,25 @@ def transport(self) -> DocumentServiceTransport: """ 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(DocumentServiceClient).get_transport_class, type(DocumentServiceClient) ) @@ -192,7 +215,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the document service client. + """Instantiates the document service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -203,23 +226,38 @@ def __init__( transport (Union[str, ~.DocumentServiceTransport]): 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. @@ -336,6 +374,9 @@ async def sample_get_document(): 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, @@ -453,6 +494,9 @@ async def sample_list_documents(): 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, @@ -607,6 +651,9 @@ async def sample_create_document(): 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, @@ -691,6 +738,9 @@ async def sample_update_document(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -798,6 +848,9 @@ async def sample_delete_document(): 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, @@ -900,6 +953,9 @@ async def sample_import_documents(): 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, @@ -1017,6 +1073,9 @@ async def sample_purge_documents(): 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, @@ -1079,6 +1138,9 @@ async def list_operations( 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, @@ -1133,6 +1195,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/client.py index ad735c96d31b..06e5cc679461 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -140,11 +141,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -323,7 +328,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 @@ -353,6 +358,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") @@ -386,6 +396,175 @@ 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 + + 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 + + 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 = DocumentServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DocumentServiceClient._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 = DocumentServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DocumentServiceClient._DEFAULT_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 DocumentServiceClient._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, *, @@ -405,22 +584,32 @@ def __init__( transport (Union[str, DocumentServiceTransport]): 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. @@ -431,17 +620,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, + ) = DocumentServiceClient._read_environment_variables() + self._client_cert_source = DocumentServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = DocumentServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -450,20 +656,33 @@ 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, DocumentServiceTransport): + transport_provided = isinstance(transport, DocumentServiceTransport) + if transport_provided: # transport is a DocumentServiceTransport 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(DocumentServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or DocumentServiceClient._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( @@ -473,17 +692,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 get_document( @@ -591,6 +810,9 @@ def sample_get_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -708,6 +930,9 @@ def sample_list_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -862,6 +1087,9 @@ def sample_create_document(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -947,6 +1175,9 @@ def sample_update_document(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1054,6 +1285,9 @@ def sample_delete_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1148,6 +1382,9 @@ def sample_import_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1266,6 +1503,9 @@ def sample_purge_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1341,6 +1581,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1395,6 +1638,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/base.py index 51a42b024555..c06cbffe0b15 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/base.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -128,6 +128,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc.py index ecae6d6fb3c2..bd6d81157646 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc.py @@ -74,7 +74,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc_asyncio.py index a65998d80c39..1399b110a91e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/grpc_asyncio.py @@ -119,7 +119,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/rest.py index f51fe6cb0390..1e84abde8531 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/document_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -371,7 +371,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/async_client.py index ba20e90e2136..f1c4fa67116e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -68,8 +68,12 @@ class EngineServiceAsyncClient: _client: EngineServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EngineServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EngineServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = EngineServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = EngineServiceClient._DEFAULT_UNIVERSE collection_path = staticmethod(EngineServiceClient.collection_path) parse_collection_path = staticmethod(EngineServiceClient.parse_collection_path) @@ -178,6 +182,25 @@ def transport(self) -> EngineServiceTransport: """ 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(EngineServiceClient).get_transport_class, type(EngineServiceClient) ) @@ -190,7 +213,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the engine service client. + """Instantiates the engine service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -201,23 +224,38 @@ def __init__( transport (Union[str, ~.EngineServiceTransport]): 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. @@ -362,6 +400,9 @@ async def sample_create_engine(): 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, @@ -498,6 +539,9 @@ async def sample_delete_engine(): 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, @@ -639,6 +683,9 @@ async def sample_update_engine(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -744,6 +791,9 @@ async def sample_get_engine(): 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, @@ -854,6 +904,9 @@ async def sample_list_engines(): 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, @@ -967,6 +1020,9 @@ async def sample_pause_engine(): 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, @@ -1072,6 +1128,9 @@ async def sample_resume_engine(): 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, @@ -1186,6 +1245,9 @@ async def sample_tune_engine(): 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, @@ -1248,6 +1310,9 @@ async def list_operations( 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, @@ -1302,6 +1367,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/client.py index 32abc22677cd..97f98599f823 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -136,11 +137,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -317,7 +322,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 @@ -347,6 +352,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") @@ -380,6 +390,175 @@ 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 + + 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 + + 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 = EngineServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EngineServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = EngineServiceClient._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 = EngineServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = EngineServiceClient._DEFAULT_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 EngineServiceClient._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, *, @@ -399,22 +578,32 @@ def __init__( transport (Union[str, EngineServiceTransport]): 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. @@ -425,17 +614,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, + ) = EngineServiceClient._read_environment_variables() + self._client_cert_source = EngineServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = EngineServiceClient._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" @@ -444,20 +650,33 @@ 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, EngineServiceTransport): + transport_provided = isinstance(transport, EngineServiceTransport) + if transport_provided: # transport is a EngineServiceTransport 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(EngineServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or EngineServiceClient._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( @@ -467,17 +686,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 create_engine( @@ -613,6 +832,9 @@ def sample_create_engine(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -749,6 +971,9 @@ def sample_delete_engine(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -890,6 +1115,9 @@ def sample_update_engine(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -995,6 +1223,9 @@ def sample_get_engine(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1105,6 +1336,9 @@ def sample_list_engines(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1218,6 +1452,9 @@ def sample_pause_engine(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1323,6 +1560,9 @@ def sample_resume_engine(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1437,6 +1677,9 @@ def sample_tune_engine(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1512,6 +1755,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1566,6 +1812,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/base.py index 7689690ccd76..7e200d1b5cd5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/base.py @@ -60,7 +60,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -123,6 +123,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc.py index 1cc197a163e1..91a4eb22b737 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc_asyncio.py index 688eb2b70e3b..da65c4547162 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/rest.py index ca59d9b35e45..beba11b551da 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/engine_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -407,7 +407,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/async_client.py index 9bdb1c8d7ed7..1e8ba294bfcf 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -57,8 +57,12 @@ class RecommendationServiceAsyncClient: _client: RecommendationServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = RecommendationServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = RecommendationServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = RecommendationServiceClient._DEFAULT_UNIVERSE document_path = staticmethod(RecommendationServiceClient.document_path) parse_document_path = staticmethod(RecommendationServiceClient.parse_document_path) @@ -171,6 +175,25 @@ def transport(self) -> RecommendationServiceTransport: """ 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(RecommendationServiceClient).get_transport_class, type(RecommendationServiceClient), @@ -184,7 +207,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the recommendation service client. + """Instantiates the recommendation service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -195,23 +218,38 @@ def __init__( transport (Union[str, ~.RecommendationServiceTransport]): 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. @@ -299,6 +337,9 @@ async def sample_recommend(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -353,6 +394,9 @@ async def list_operations( 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, @@ -407,6 +451,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/client.py index 1e8b12465020..f79779ee7351 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -127,11 +128,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -310,7 +315,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 @@ -340,6 +345,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") @@ -373,6 +383,177 @@ 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 + + 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 + + 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 = RecommendationServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + RecommendationServiceClient._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 = RecommendationServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = RecommendationServiceClient._DEFAULT_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 RecommendationServiceClient._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, *, @@ -392,22 +573,32 @@ def __init__( transport (Union[str, RecommendationServiceTransport]): 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. @@ -418,17 +609,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, + ) = RecommendationServiceClient._read_environment_variables() + self._client_cert_source = RecommendationServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = RecommendationServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -437,20 +645,33 @@ 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, RecommendationServiceTransport): + transport_provided = isinstance(transport, RecommendationServiceTransport) + if transport_provided: # transport is a RecommendationServiceTransport 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(RecommendationServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or RecommendationServiceClient._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( @@ -460,17 +681,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 recommend( @@ -550,6 +771,9 @@ def sample_recommend(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -617,6 +841,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -671,6 +898,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/base.py index 243eea3f6702..59160a13d3d1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc.py index 1b735299569e..455d9a7e4f0f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc_asyncio.py index 039abfb36108..14a1d73500ea 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/rest.py index 6001820c4b9e..49dbad7c9bc2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/recommendation_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -189,7 +189,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/async_client.py index 20400b9a9337..58e93aa3ae6c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -66,8 +66,12 @@ class SchemaServiceAsyncClient: _client: SchemaServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SchemaServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SchemaServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(SchemaServiceClient.data_store_path) parse_data_store_path = staticmethod(SchemaServiceClient.parse_data_store_path) @@ -176,6 +180,25 @@ def transport(self) -> SchemaServiceTransport: """ 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(SchemaServiceClient).get_transport_class, type(SchemaServiceClient) ) @@ -188,7 +211,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the schema service client. + """Instantiates the schema service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -199,23 +222,38 @@ def __init__( transport (Union[str, ~.SchemaServiceTransport]): 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. @@ -320,6 +358,9 @@ async def sample_get_schema(): 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, @@ -430,6 +471,9 @@ async def sample_list_schemas(): 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, @@ -579,6 +623,9 @@ async def sample_create_schema(): 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, @@ -677,6 +724,9 @@ async def sample_update_schema(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -803,6 +853,9 @@ async def sample_delete_schema(): 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, @@ -865,6 +918,9 @@ async def list_operations( 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, @@ -919,6 +975,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/client.py index e87e514607b1..45bea27d44a4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -134,11 +135,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -313,7 +318,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 @@ -343,6 +348,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") @@ -376,6 +386,175 @@ 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 + + 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 + + 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 = SchemaServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SchemaServiceClient._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 = SchemaServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SchemaServiceClient._DEFAULT_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 SchemaServiceClient._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, *, @@ -395,22 +574,32 @@ def __init__( transport (Union[str, SchemaServiceTransport]): 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. @@ -421,17 +610,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, + ) = SchemaServiceClient._read_environment_variables() + self._client_cert_source = SchemaServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = SchemaServiceClient._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" @@ -440,20 +646,33 @@ 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, SchemaServiceTransport): + transport_provided = isinstance(transport, SchemaServiceTransport) + if transport_provided: # transport is a SchemaServiceTransport 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(SchemaServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SchemaServiceClient._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( @@ -463,17 +682,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 get_schema( @@ -569,6 +788,9 @@ def sample_get_schema(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -679,6 +901,9 @@ def sample_list_schemas(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -828,6 +1053,9 @@ def sample_create_schema(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -927,6 +1155,9 @@ def sample_update_schema(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1053,6 +1284,9 @@ def sample_delete_schema(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1128,6 +1362,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1182,6 +1419,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/base.py index 54303d543418..f605db12e372 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc.py index 4d4921ac00c3..4bbabc68ab79 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc_asyncio.py index 742c5dbf6239..71e61f9f8ca4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/rest.py index 790ca4cfcec3..4064f3fd4eaa 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/schema_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -318,7 +318,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/async_client.py index f16ee15307ea..fc76c4055bb5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -58,8 +58,12 @@ class SearchServiceAsyncClient: _client: SearchServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SearchServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SearchServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SearchServiceClient._DEFAULT_UNIVERSE branch_path = staticmethod(SearchServiceClient.branch_path) parse_branch_path = staticmethod(SearchServiceClient.parse_branch_path) @@ -172,6 +176,25 @@ def transport(self) -> SearchServiceTransport: """ 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(SearchServiceClient).get_transport_class, type(SearchServiceClient) ) @@ -184,7 +207,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the search service client. + """Instantiates the search service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -195,23 +218,38 @@ def __init__( transport (Union[str, ~.SearchServiceTransport]): 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. @@ -300,6 +338,9 @@ async def sample_search(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -363,6 +404,9 @@ async def list_operations( 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, @@ -417,6 +461,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/client.py index f02ff6c846e4..6f0dbe5c8a02 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -126,11 +127,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -333,7 +338,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 @@ -363,6 +368,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") @@ -396,6 +406,175 @@ 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 + + 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 + + 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 = SearchServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SearchServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SearchServiceClient._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 = SearchServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SearchServiceClient._DEFAULT_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 SearchServiceClient._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, *, @@ -415,22 +594,32 @@ def __init__( transport (Union[str, SearchServiceTransport]): 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. @@ -441,17 +630,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, + ) = SearchServiceClient._read_environment_variables() + self._client_cert_source = SearchServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = SearchServiceClient._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" @@ -460,20 +666,33 @@ 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, SearchServiceTransport): + transport_provided = isinstance(transport, SearchServiceTransport) + if transport_provided: # transport is a SearchServiceTransport 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(SearchServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SearchServiceClient._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( @@ -483,17 +702,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 search( @@ -574,6 +793,9 @@ def sample_search(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -650,6 +872,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -704,6 +929,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/base.py index 68797c0b39e5..d1ddf17783f2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc.py index 3108023be46b..9aabe36c902d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc_asyncio.py index 3bda1922ed5f..ec30fac371ad 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/rest.py index e94cba3b952e..e8f442dbe552 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -187,7 +187,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/async_client.py index 729d05c5ace1..f7bd0ee159b2 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -59,8 +59,12 @@ class SearchTuningServiceAsyncClient: _client: SearchTuningServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SearchTuningServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SearchTuningServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SearchTuningServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SearchTuningServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(SearchTuningServiceClient.data_store_path) parse_data_store_path = staticmethod( @@ -169,6 +173,25 @@ def transport(self) -> SearchTuningServiceTransport: """ 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(SearchTuningServiceClient).get_transport_class, type(SearchTuningServiceClient), @@ -182,7 +205,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the search tuning service client. + """Instantiates the search tuning service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -193,23 +216,38 @@ def __init__( transport (Union[str, ~.SearchTuningServiceTransport]): 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. @@ -303,6 +341,9 @@ async def sample_train_custom_model(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -365,6 +406,9 @@ async def list_operations( 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, @@ -419,6 +463,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/client.py index 5a13c41968e3..f9645c7fc1ce 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -129,11 +130,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -284,7 +289,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 @@ -314,6 +319,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") @@ -347,6 +357,175 @@ 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 + + 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 + + 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 = SearchTuningServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SearchTuningServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SearchTuningServiceClient._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 = SearchTuningServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SearchTuningServiceClient._DEFAULT_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 SearchTuningServiceClient._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, *, @@ -366,22 +545,32 @@ def __init__( transport (Union[str, SearchTuningServiceTransport]): 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. @@ -392,17 +581,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, + ) = SearchTuningServiceClient._read_environment_variables() + self._client_cert_source = SearchTuningServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = SearchTuningServiceClient._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" @@ -411,20 +617,33 @@ 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, SearchTuningServiceTransport): + transport_provided = isinstance(transport, SearchTuningServiceTransport) + if transport_provided: # transport is a SearchTuningServiceTransport 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(SearchTuningServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SearchTuningServiceClient._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( @@ -434,17 +653,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 train_custom_model( @@ -530,6 +749,9 @@ def sample_train_custom_model(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -605,6 +827,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -659,6 +884,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/base.py index cb450063eaff..c936684b40de 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc.py index c3d05805ca1f..42ffd7aa55d3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc_asyncio.py index 3e70bb8096cd..f3b74f9330e5 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/rest.py index 825a86eccd49..4c25c6d26ace 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/search_tuning_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -197,7 +197,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/async_client.py index 9523334697c7..b9bbe63e1dc7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -67,8 +67,14 @@ class SiteSearchEngineServiceAsyncClient: _client: SiteSearchEngineServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SiteSearchEngineServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SiteSearchEngineServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ( + SiteSearchEngineServiceClient._DEFAULT_ENDPOINT_TEMPLATE + ) + _DEFAULT_UNIVERSE = SiteSearchEngineServiceClient._DEFAULT_UNIVERSE site_search_engine_path = staticmethod( SiteSearchEngineServiceClient.site_search_engine_path @@ -187,6 +193,25 @@ def transport(self) -> SiteSearchEngineServiceTransport: """ 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(SiteSearchEngineServiceClient).get_transport_class, type(SiteSearchEngineServiceClient), @@ -200,7 +225,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the site search engine service client. + """Instantiates the site search engine service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -211,23 +236,38 @@ def __init__( transport (Union[str, ~.SiteSearchEngineServiceTransport]): 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. @@ -342,6 +382,9 @@ async def sample_get_site_search_engine(): 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, @@ -472,6 +515,9 @@ async def sample_create_target_site(): 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, @@ -576,6 +622,9 @@ async def sample_batch_create_target_sites(): 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, @@ -701,6 +750,9 @@ async def sample_get_target_site(): 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, @@ -826,6 +878,9 @@ async def sample_update_target_site(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -965,6 +1020,9 @@ async def sample_delete_target_site(): 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, @@ -1091,6 +1149,9 @@ async def sample_list_target_sites(): 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, @@ -1193,6 +1254,9 @@ async def sample_enable_advanced_site_search(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1294,6 +1358,9 @@ async def sample_disable_advanced_site_search(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1395,6 +1462,9 @@ async def sample_recrawl_uris(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1495,6 +1565,9 @@ async def sample_batch_verify_target_sites(): 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, @@ -1597,6 +1670,9 @@ async def sample_fetch_domain_verification_status(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1660,6 +1736,9 @@ async def list_operations( 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, @@ -1714,6 +1793,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/client.py index b376115e0020..ec783d970424 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -137,11 +138,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -316,7 +321,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 @@ -346,6 +351,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") @@ -379,6 +389,177 @@ 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 + + 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 + + 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 = SiteSearchEngineServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SiteSearchEngineServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + SiteSearchEngineServiceClient._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 = SiteSearchEngineServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SiteSearchEngineServiceClient._DEFAULT_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 SiteSearchEngineServiceClient._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, *, @@ -398,22 +579,32 @@ def __init__( transport (Union[str, SiteSearchEngineServiceTransport]): 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. @@ -424,17 +615,36 @@ 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, + ) = SiteSearchEngineServiceClient._read_environment_variables() + self._client_cert_source = ( + SiteSearchEngineServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) ) + self._universe_domain = SiteSearchEngineServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -443,20 +653,33 @@ 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, SiteSearchEngineServiceTransport): + transport_provided = isinstance(transport, SiteSearchEngineServiceTransport) + if transport_provided: # transport is a SiteSearchEngineServiceTransport 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(SiteSearchEngineServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SiteSearchEngineServiceClient._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( @@ -466,17 +689,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 get_site_search_engine( @@ -584,6 +807,9 @@ def sample_get_site_search_engine(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -714,6 +940,9 @@ def sample_create_target_site(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -823,6 +1052,9 @@ def sample_batch_create_target_sites(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -948,6 +1180,9 @@ def sample_get_target_site(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1073,6 +1308,9 @@ def sample_update_target_site(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1212,6 +1450,9 @@ def sample_delete_target_site(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1338,6 +1579,9 @@ def sample_list_target_sites(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1447,6 +1691,9 @@ def sample_enable_advanced_site_search(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1555,6 +1802,9 @@ def sample_disable_advanced_site_search(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1657,6 +1907,9 @@ def sample_recrawl_uris(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1762,6 +2015,9 @@ def sample_batch_verify_target_sites(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1869,6 +2125,9 @@ def sample_fetch_domain_verification_status(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1945,6 +2204,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1999,6 +2261,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/base.py index 595943980b84..fcb8a6685182 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/base.py @@ -61,7 +61,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -124,6 +124,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc.py index ab8ee337cb0b..187405c1d5c4 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc_asyncio.py index 40254148b843..06a26e189c3b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/rest.py index 4bd602b0adcd..6b83579b4de3 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/site_search_engine_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -568,7 +568,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/async_client.py index f434472cbd6f..0a0f740aea2d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api import httpbody_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -70,8 +70,12 @@ class UserEventServiceAsyncClient: _client: UserEventServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = UserEventServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = UserEventServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(UserEventServiceClient.data_store_path) parse_data_store_path = staticmethod(UserEventServiceClient.parse_data_store_path) @@ -180,6 +184,25 @@ def transport(self) -> UserEventServiceTransport: """ 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(UserEventServiceClient).get_transport_class, type(UserEventServiceClient) ) @@ -192,7 +215,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the user event service client. + """Instantiates the user event service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -203,23 +226,38 @@ def __init__( transport (Union[str, ~.UserEventServiceTransport]): 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. @@ -302,6 +340,9 @@ async def sample_write_user_event(): 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, @@ -435,6 +476,9 @@ async def sample_collect_user_event(): 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, @@ -527,6 +571,9 @@ async def sample_purge_user_events(): 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, @@ -645,6 +692,9 @@ async def sample_import_user_events(): 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, @@ -707,6 +757,9 @@ async def list_operations( 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, @@ -761,6 +814,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/client.py index dfe0cf15a447..b488c90f3694 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1alpha import gapic_version as package_version 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.api import httpbody_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -140,11 +141,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -321,7 +326,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 @@ -351,6 +356,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") @@ -384,6 +394,175 @@ 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 + + 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 + + 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 = UserEventServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = UserEventServiceClient._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 = UserEventServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = UserEventServiceClient._DEFAULT_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 UserEventServiceClient._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, *, @@ -403,22 +582,32 @@ def __init__( transport (Union[str, UserEventServiceTransport]): 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. @@ -429,17 +618,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, + ) = UserEventServiceClient._read_environment_variables() + self._client_cert_source = UserEventServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = UserEventServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -448,20 +654,33 @@ 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, UserEventServiceTransport): + transport_provided = isinstance(transport, UserEventServiceTransport) + if transport_provided: # transport is a UserEventServiceTransport 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(UserEventServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or UserEventServiceClient._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( @@ -471,17 +690,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 write_user_event( @@ -556,6 +775,9 @@ def sample_write_user_event(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -690,6 +912,9 @@ def sample_collect_user_event(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -783,6 +1008,9 @@ def sample_purge_user_events(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -893,6 +1121,9 @@ def sample_import_user_events(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -968,6 +1199,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1022,6 +1256,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/base.py index 10152c0e93c5..cff7d1769f3f 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/base.py @@ -64,7 +64,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -127,6 +127,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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc.py index b7a99b8114a5..047b78516d5a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc.py @@ -72,7 +72,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc_asyncio.py index 6b4d666743a7..5395d2b7f8ae 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/grpc_asyncio.py @@ -117,7 +117,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/rest.py index cd67558e89af..f8061f6e32a1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1alpha/services/user_event_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.api import httpbody_pb2 # type: ignore @@ -295,7 +295,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/gapic_version.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/gapic_version.py index 768cd2103fa5..360a0d13ebdd 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/gapic_version.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.11.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/async_client.py index e7a9b5f3bc68..2cc802cd3e43 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -57,8 +57,12 @@ class CompletionServiceAsyncClient: _client: CompletionServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = CompletionServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = CompletionServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(CompletionServiceClient.data_store_path) parse_data_store_path = staticmethod(CompletionServiceClient.parse_data_store_path) @@ -165,6 +169,25 @@ def transport(self) -> CompletionServiceTransport: """ 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(CompletionServiceClient).get_transport_class, type(CompletionServiceClient) ) @@ -177,7 +200,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the completion service client. + """Instantiates the completion service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -188,23 +211,38 @@ def __init__( transport (Union[str, ~.CompletionServiceTransport]): 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. @@ -291,6 +329,9 @@ async def sample_complete_query(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -345,6 +386,9 @@ async def list_operations( 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, @@ -399,6 +443,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/client.py index 6f0dec551389..357d49aac678 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -127,11 +128,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -282,7 +287,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 @@ -312,6 +317,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") @@ -345,6 +355,175 @@ 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 + + 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 + + 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 = CompletionServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = CompletionServiceClient._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 = CompletionServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = CompletionServiceClient._DEFAULT_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 CompletionServiceClient._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, *, @@ -364,22 +543,32 @@ def __init__( transport (Union[str, CompletionServiceTransport]): 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. @@ -390,17 +579,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, + ) = CompletionServiceClient._read_environment_variables() + self._client_cert_source = CompletionServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = CompletionServiceClient._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" @@ -409,20 +615,33 @@ 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, CompletionServiceTransport): + transport_provided = isinstance(transport, CompletionServiceTransport) + if transport_provided: # transport is a CompletionServiceTransport 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(CompletionServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or CompletionServiceClient._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( @@ -432,17 +651,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 complete_query( @@ -521,6 +740,9 @@ def sample_complete_query(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -588,6 +810,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -642,6 +867,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/base.py index 3f2241c49bf8..9a0a6b7e46ec 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc.py index 85856819b37d..a5fc86174ed9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc_asyncio.py index 964d3e60ec0d..49b557874534 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/rest.py index dc8c9bf75d7e..cf7af366c03c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/completion_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -189,7 +189,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/async_client.py index 42842384dfe9..693343257012 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -67,8 +67,14 @@ class ConversationalSearchServiceAsyncClient: _client: ConversationalSearchServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = ConversationalSearchServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ( + ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE + ) + _DEFAULT_UNIVERSE = ConversationalSearchServiceClient._DEFAULT_UNIVERSE conversation_path = staticmethod( ConversationalSearchServiceClient.conversation_path @@ -199,6 +205,25 @@ def transport(self) -> ConversationalSearchServiceTransport: """ 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(ConversationalSearchServiceClient).get_transport_class, type(ConversationalSearchServiceClient), @@ -212,7 +237,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the conversational search service client. + """Instantiates the conversational search service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -223,23 +248,38 @@ def __init__( transport (Union[str, ~.ConversationalSearchServiceTransport]): 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. @@ -360,6 +400,9 @@ async def sample_converse_conversation(): 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, @@ -477,6 +520,9 @@ async def sample_create_conversation(): 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, @@ -577,6 +623,9 @@ async def sample_delete_conversation(): 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, @@ -697,6 +746,9 @@ async def sample_update_conversation(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -801,6 +853,9 @@ async def sample_get_conversation(): 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, @@ -909,6 +964,9 @@ async def sample_list_conversations(): 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, @@ -972,6 +1030,9 @@ async def list_operations( 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, @@ -1026,6 +1087,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/client.py index f0934c297bd6..7e60b080ca69 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -141,11 +142,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -370,7 +375,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 @@ -400,6 +405,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") @@ -433,6 +443,177 @@ 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 + + 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 + + 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 = ConversationalSearchServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + ConversationalSearchServiceClient._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 = ConversationalSearchServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ConversationalSearchServiceClient._DEFAULT_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 ConversationalSearchServiceClient._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, *, @@ -452,22 +633,32 @@ def __init__( transport (Union[str, ConversationalSearchServiceTransport]): 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. @@ -478,17 +669,36 @@ 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, + ) = ConversationalSearchServiceClient._read_environment_variables() + self._client_cert_source = ( + ConversationalSearchServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + ) + self._universe_domain = ConversationalSearchServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -497,20 +707,33 @@ 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, ConversationalSearchServiceTransport): + transport_provided = isinstance(transport, ConversationalSearchServiceTransport) + if transport_provided: # transport is a ConversationalSearchServiceTransport 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(ConversationalSearchServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or ConversationalSearchServiceClient._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( @@ -520,17 +743,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 converse_conversation( @@ -644,6 +867,9 @@ def sample_converse_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -763,6 +989,9 @@ def sample_create_conversation(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -865,6 +1094,9 @@ def sample_delete_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -987,6 +1219,9 @@ def sample_update_conversation(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1093,6 +1328,9 @@ def sample_get_conversation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1203,6 +1441,9 @@ def sample_list_conversations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1279,6 +1520,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1333,6 +1577,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/base.py index bc33ebfe0bce..60de570ed1e0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/base.py @@ -61,7 +61,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -124,6 +124,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-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc.py index 79e071f4b762..b1be60b59f4b 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc_asyncio.py index 19e8402fac17..16e2b988bcf8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/grpc_asyncio.py @@ -115,7 +115,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/rest.py index 05482bfea420..e5d12ef26574 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/conversational_search_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -349,7 +349,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/async_client.py index 3f4f61df05f4..d8b6849a9261 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -70,8 +70,12 @@ class DocumentServiceAsyncClient: _client: DocumentServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DocumentServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DocumentServiceClient._DEFAULT_UNIVERSE branch_path = staticmethod(DocumentServiceClient.branch_path) parse_branch_path = staticmethod(DocumentServiceClient.parse_branch_path) @@ -180,6 +184,25 @@ def transport(self) -> DocumentServiceTransport: """ 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(DocumentServiceClient).get_transport_class, type(DocumentServiceClient) ) @@ -192,7 +215,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the document service client. + """Instantiates the document service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -203,23 +226,38 @@ def __init__( transport (Union[str, ~.DocumentServiceTransport]): 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. @@ -335,6 +373,9 @@ async def sample_get_document(): 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, @@ -452,6 +493,9 @@ async def sample_list_documents(): 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, @@ -606,6 +650,9 @@ async def sample_create_document(): 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, @@ -690,6 +737,9 @@ async def sample_update_document(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -797,6 +847,9 @@ async def sample_delete_document(): 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, @@ -899,6 +952,9 @@ async def sample_import_documents(): 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, @@ -1016,6 +1072,9 @@ async def sample_purge_documents(): 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, @@ -1078,6 +1137,9 @@ async def list_operations( 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, @@ -1132,6 +1194,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/client.py index 72d8c815a6fe..9e9a0d2c7ce7 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -140,11 +141,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -323,7 +328,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 @@ -353,6 +358,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") @@ -386,6 +396,175 @@ 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 + + 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 + + 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 = DocumentServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DocumentServiceClient._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 = DocumentServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DocumentServiceClient._DEFAULT_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 DocumentServiceClient._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, *, @@ -405,22 +584,32 @@ def __init__( transport (Union[str, DocumentServiceTransport]): 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. @@ -431,17 +620,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, + ) = DocumentServiceClient._read_environment_variables() + self._client_cert_source = DocumentServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = DocumentServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -450,20 +656,33 @@ 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, DocumentServiceTransport): + transport_provided = isinstance(transport, DocumentServiceTransport) + if transport_provided: # transport is a DocumentServiceTransport 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(DocumentServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or DocumentServiceClient._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( @@ -473,17 +692,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 get_document( @@ -590,6 +809,9 @@ def sample_get_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -707,6 +929,9 @@ def sample_list_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -861,6 +1086,9 @@ def sample_create_document(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -946,6 +1174,9 @@ def sample_update_document(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1053,6 +1284,9 @@ def sample_delete_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1147,6 +1381,9 @@ def sample_import_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1265,6 +1502,9 @@ def sample_purge_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1340,6 +1580,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1394,6 +1637,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/base.py index 6ab8061c7b3b..903ca5e86cfa 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/base.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -128,6 +128,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-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc.py index 8dfe6ff14968..34c7eff3f483 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc.py @@ -74,7 +74,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc_asyncio.py index 650ac977d3aa..e2153ea0f956 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/grpc_asyncio.py @@ -119,7 +119,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/rest.py index 73c060777dfb..28a5a482e525 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/document_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -371,7 +371,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/async_client.py index c24ca0c25acd..9320a96ec311 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -57,8 +57,12 @@ class RecommendationServiceAsyncClient: _client: RecommendationServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = RecommendationServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = RecommendationServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = RecommendationServiceClient._DEFAULT_UNIVERSE document_path = staticmethod(RecommendationServiceClient.document_path) parse_document_path = staticmethod(RecommendationServiceClient.parse_document_path) @@ -171,6 +175,25 @@ def transport(self) -> RecommendationServiceTransport: """ 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(RecommendationServiceClient).get_transport_class, type(RecommendationServiceClient), @@ -184,7 +207,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the recommendation service client. + """Instantiates the recommendation service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -195,23 +218,38 @@ def __init__( transport (Union[str, ~.RecommendationServiceTransport]): 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. @@ -299,6 +337,9 @@ async def sample_recommend(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -353,6 +394,9 @@ async def list_operations( 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, @@ -407,6 +451,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/client.py index 46ccce5311f0..7c165e74d545 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -127,11 +128,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -310,7 +315,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 @@ -340,6 +345,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") @@ -373,6 +383,177 @@ 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 + + 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 + + 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 = RecommendationServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + RecommendationServiceClient._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 = RecommendationServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = RecommendationServiceClient._DEFAULT_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 RecommendationServiceClient._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, *, @@ -392,22 +573,32 @@ def __init__( transport (Union[str, RecommendationServiceTransport]): 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. @@ -418,17 +609,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, + ) = RecommendationServiceClient._read_environment_variables() + self._client_cert_source = RecommendationServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = RecommendationServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -437,20 +645,33 @@ 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, RecommendationServiceTransport): + transport_provided = isinstance(transport, RecommendationServiceTransport) + if transport_provided: # transport is a RecommendationServiceTransport 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(RecommendationServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or RecommendationServiceClient._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( @@ -460,17 +681,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 recommend( @@ -550,6 +771,9 @@ def sample_recommend(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -617,6 +841,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -671,6 +898,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/base.py index cd3d36709612..e3fb6ff5dbc8 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc.py index d97959cd1e27..7c7d88ebdbce 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc_asyncio.py index cd85267c3c08..071e6c862c7d 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/rest.py index 96446d1ad302..179f26290792 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/recommendation_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -189,7 +189,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/async_client.py index 12312f1e71db..4c26f6bb2497 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -66,8 +66,12 @@ class SchemaServiceAsyncClient: _client: SchemaServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SchemaServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SchemaServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(SchemaServiceClient.data_store_path) parse_data_store_path = staticmethod(SchemaServiceClient.parse_data_store_path) @@ -176,6 +180,25 @@ def transport(self) -> SchemaServiceTransport: """ 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(SchemaServiceClient).get_transport_class, type(SchemaServiceClient) ) @@ -188,7 +211,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the schema service client. + """Instantiates the schema service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -199,23 +222,38 @@ def __init__( transport (Union[str, ~.SchemaServiceTransport]): 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. @@ -320,6 +358,9 @@ async def sample_get_schema(): 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, @@ -430,6 +471,9 @@ async def sample_list_schemas(): 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, @@ -579,6 +623,9 @@ async def sample_create_schema(): 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, @@ -677,6 +724,9 @@ async def sample_update_schema(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -803,6 +853,9 @@ async def sample_delete_schema(): 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, @@ -865,6 +918,9 @@ async def list_operations( 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, @@ -919,6 +975,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/client.py index 677f08ec3620..b8f75f8c7897 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -134,11 +135,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -313,7 +318,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 @@ -343,6 +348,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") @@ -376,6 +386,175 @@ 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 + + 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 + + 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 = SchemaServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SchemaServiceClient._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 = SchemaServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SchemaServiceClient._DEFAULT_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 SchemaServiceClient._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, *, @@ -395,22 +574,32 @@ def __init__( transport (Union[str, SchemaServiceTransport]): 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. @@ -421,17 +610,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, + ) = SchemaServiceClient._read_environment_variables() + self._client_cert_source = SchemaServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = SchemaServiceClient._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" @@ -440,20 +646,33 @@ 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, SchemaServiceTransport): + transport_provided = isinstance(transport, SchemaServiceTransport) + if transport_provided: # transport is a SchemaServiceTransport 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(SchemaServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SchemaServiceClient._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( @@ -463,17 +682,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 get_schema( @@ -569,6 +788,9 @@ def sample_get_schema(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -679,6 +901,9 @@ def sample_list_schemas(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -828,6 +1053,9 @@ def sample_create_schema(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -927,6 +1155,9 @@ def sample_update_schema(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1053,6 +1284,9 @@ def sample_delete_schema(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1128,6 +1362,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1182,6 +1419,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/base.py index 63c2a0e368c0..e537b13812be 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc.py index 3dfe87605309..d708f522ee54 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc_asyncio.py index 689bfb8a7da3..b00158837177 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/rest.py index 8056b28568ce..bf8371b16ff1 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/schema_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -318,7 +318,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/async_client.py index 67a98e445aef..8ba16ddb98ba 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -58,8 +58,12 @@ class SearchServiceAsyncClient: _client: SearchServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = SearchServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = SearchServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = SearchServiceClient._DEFAULT_UNIVERSE branch_path = staticmethod(SearchServiceClient.branch_path) parse_branch_path = staticmethod(SearchServiceClient.parse_branch_path) @@ -172,6 +176,25 @@ def transport(self) -> SearchServiceTransport: """ 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(SearchServiceClient).get_transport_class, type(SearchServiceClient) ) @@ -184,7 +207,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the search service client. + """Instantiates the search service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -195,23 +218,38 @@ def __init__( transport (Union[str, ~.SearchServiceTransport]): 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. @@ -300,6 +338,9 @@ async def sample_search(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -363,6 +404,9 @@ async def list_operations( 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, @@ -417,6 +461,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/client.py index be675f80f7e1..16b86d85e4c0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.longrunning import operations_pb2 # type: ignore @@ -126,11 +127,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -333,7 +338,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 @@ -363,6 +368,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") @@ -396,6 +406,175 @@ 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 + + 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 + + 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 = SearchServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = SearchServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = SearchServiceClient._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 = SearchServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = SearchServiceClient._DEFAULT_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 SearchServiceClient._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, *, @@ -415,22 +594,32 @@ def __init__( transport (Union[str, SearchServiceTransport]): 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. @@ -441,17 +630,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, + ) = SearchServiceClient._read_environment_variables() + self._client_cert_source = SearchServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = SearchServiceClient._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" @@ -460,20 +666,33 @@ 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, SearchServiceTransport): + transport_provided = isinstance(transport, SearchServiceTransport) + if transport_provided: # transport is a SearchServiceTransport 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(SearchServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or SearchServiceClient._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( @@ -483,17 +702,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 search( @@ -574,6 +793,9 @@ def sample_search(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -650,6 +872,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -704,6 +929,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/base.py index 594225268e68..9b94ea6c7a2e 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -121,6 +121,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-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc.py index 259a3b2020dd..9397052dc4be 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc_asyncio.py index 23621f07b2db..254f85e729e0 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/rest.py index f8581c812195..952d74176406 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/search_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -187,7 +187,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/async_client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/async_client.py index 9944944c2587..a993be884806 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/async_client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.api import httpbody_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -69,8 +69,12 @@ class UserEventServiceAsyncClient: _client: UserEventServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = UserEventServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = UserEventServiceClient._DEFAULT_UNIVERSE data_store_path = staticmethod(UserEventServiceClient.data_store_path) parse_data_store_path = staticmethod(UserEventServiceClient.parse_data_store_path) @@ -179,6 +183,25 @@ def transport(self) -> UserEventServiceTransport: """ 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(UserEventServiceClient).get_transport_class, type(UserEventServiceClient) ) @@ -191,7 +214,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the user event service client. + """Instantiates the user event service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -202,23 +225,38 @@ def __init__( transport (Union[str, ~.UserEventServiceTransport]): 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. @@ -301,6 +339,9 @@ async def sample_write_user_event(): 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, @@ -434,6 +475,9 @@ async def sample_collect_user_event(): 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, @@ -544,6 +588,9 @@ async def sample_import_user_events(): 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, @@ -606,6 +653,9 @@ async def list_operations( 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, @@ -660,6 +710,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/client.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/client.py index 1d913c133c59..b97df8a9b0c9 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/client.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.discoveryengine_v1beta import gapic_version as package_version 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.api import httpbody_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -139,11 +140,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 = "discoveryengine.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "discoveryengine.{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 @@ -320,7 +325,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 @@ -350,6 +355,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") @@ -383,6 +393,175 @@ 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 + + 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 + + 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 = UserEventServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = UserEventServiceClient._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 = UserEventServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = UserEventServiceClient._DEFAULT_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 UserEventServiceClient._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, *, @@ -402,22 +581,32 @@ def __init__( transport (Union[str, UserEventServiceTransport]): 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. @@ -428,17 +617,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = UserEventServiceClient._read_environment_variables() + self._client_cert_source = UserEventServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = UserEventServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -447,20 +653,33 @@ 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, UserEventServiceTransport): + transport_provided = isinstance(transport, UserEventServiceTransport) + if transport_provided: # transport is a UserEventServiceTransport 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(UserEventServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or UserEventServiceClient._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( @@ -470,17 +689,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 write_user_event( @@ -555,6 +774,9 @@ def sample_write_user_event(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -689,6 +911,9 @@ def sample_collect_user_event(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -791,6 +1016,9 @@ def sample_import_user_events(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -866,6 +1094,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -920,6 +1151,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/base.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/base.py index ef814230e7a2..48dacd4f6f85 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/base.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/base.py @@ -63,7 +63,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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 @@ -126,6 +126,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-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc.py index 7751410791e1..eee7308f2714 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc.py @@ -71,7 +71,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc_asyncio.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc_asyncio.py index b78e3f6274d5..c50203a0754c 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/grpc_asyncio.py @@ -116,7 +116,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/rest.py b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/rest.py index 2fddf90d0981..6c8696fe326a 100644 --- a/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/rest.py +++ b/packages/google-cloud-discoveryengine/google/cloud/discoveryengine_v1beta/services/user_event_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.api import httpbody_pb2 # type: ignore @@ -263,7 +263,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'discoveryengine.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-discoveryengine/noxfile.py b/packages/google-cloud-discoveryengine/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-discoveryengine/noxfile.py +++ b/packages/google-cloud-discoveryengine/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1.json b/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1.json index 62400ff6ec43..7c1bfd82952e 100644 --- a/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1.json +++ b/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-discoveryengine", - "version": "0.11.5" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1alpha.json b/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1alpha.json index 67d077989daf..77b380b21703 100644 --- a/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1alpha.json +++ b/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1alpha.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-discoveryengine", - "version": "0.11.5" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1beta.json b/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1beta.json index eab8b26480f3..5ef34e5b313b 100644 --- a/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1beta.json +++ b/packages/google-cloud-discoveryengine/samples/generated_samples/snippet_metadata_google.cloud.discoveryengine.v1beta.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-discoveryengine", - "version": "0.11.5" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_completion_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_completion_service.py index f95cc67b4911..7504d4fa2c78 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_completion_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_completion_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -67,6 +67,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -97,6 +120,275 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert CompletionServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + CompletionServiceClient._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 CompletionServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + CompletionServiceClient._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 CompletionServiceClient._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 CompletionServiceClient._get_client_cert_source(None, False) is None + assert ( + CompletionServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + CompletionServiceClient._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 ( + CompletionServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + CompletionServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + CompletionServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), +) +@mock.patch.object( + CompletionServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = CompletionServiceClient._DEFAULT_UNIVERSE + default_endpoint = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + CompletionServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + CompletionServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CompletionServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + CompletionServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CompletionServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CompletionServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + CompletionServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + CompletionServiceClient._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 ( + CompletionServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + CompletionServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + CompletionServiceClient._get_universe_domain(None, None) + == CompletionServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + CompletionServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (CompletionServiceClient, transports.CompletionServiceGrpcTransport, "grpc"), + (CompletionServiceClient, transports.CompletionServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -108,7 +400,7 @@ def test__get_default_mtls_endpoint(): def test_completion_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -162,7 +454,7 @@ def test_completion_service_client_service_account_always_use_jwt( def test_completion_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -212,20 +504,22 @@ def test_completion_service_client_get_transport_class(): ) @mock.patch.object( CompletionServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), ) @mock.patch.object( CompletionServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), ) def test_completion_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CompletionServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -260,7 +554,9 @@ def test_completion_service_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, @@ -290,15 +586,23 @@ def test_completion_service_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") @@ -308,7 +612,9 @@ def test_completion_service_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", @@ -326,7 +632,9 @@ def test_completion_service_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, @@ -379,13 +687,13 @@ def test_completion_service_client_client_options( ) @mock.patch.object( CompletionServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), ) @mock.patch.object( CompletionServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_completion_service_client_mtls_env_auto( @@ -408,7 +716,9 @@ def test_completion_service_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 @@ -440,7 +750,9 @@ def test_completion_service_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 @@ -474,7 +786,9 @@ def test_completion_service_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, @@ -564,6 +878,118 @@ def test_completion_service_client_get_mtls_endpoint_and_cert_source(client_clas 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", [CompletionServiceClient, CompletionServiceAsyncClient] +) +@mock.patch.object( + CompletionServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), +) +@mock.patch.object( + CompletionServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), +) +def test_completion_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = CompletionServiceClient._DEFAULT_UNIVERSE + default_endpoint = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CompletionServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -590,7 +1016,9 @@ def test_completion_service_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, @@ -635,7 +1063,9 @@ def test_completion_service_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, @@ -695,7 +1125,9 @@ def test_completion_service_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, @@ -712,8 +1144,8 @@ def test_completion_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -742,7 +1174,7 @@ def test_completion_service_client_create_channel_credentials_file( ) def test_complete_query(request_type, transport: str = "grpc"): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -772,7 +1204,7 @@ def test_complete_query_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -790,7 +1222,7 @@ async def test_complete_query_async( request_type=completion_service.CompleteQueryRequest, ): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -825,7 +1257,7 @@ async def test_complete_query_async_from_dict(): def test_complete_query_field_headers(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -855,7 +1287,7 @@ def test_complete_query_field_headers(): @pytest.mark.asyncio async def test_complete_query_field_headers_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -893,7 +1325,7 @@ async def test_complete_query_field_headers_async(): ) def test_complete_query_rest(request_type): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -948,7 +1380,7 @@ def test_complete_query_rest_required_fields( assert "query" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_query._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -960,7 +1392,7 @@ def test_complete_query_rest_required_fields( jsonified_request["query"] = "query_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_query._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -980,7 +1412,7 @@ def test_complete_query_rest_required_fields( assert jsonified_request["query"] == "query_value" client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1028,7 +1460,7 @@ def test_complete_query_rest_required_fields( def test_complete_query_rest_unset_required_fields(): transport = transports.CompletionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.complete_query._get_unset_required_fields({}) @@ -1053,7 +1485,7 @@ def test_complete_query_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_complete_query_rest_interceptors(null_interceptor): transport = transports.CompletionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CompletionServiceRestInterceptor(), @@ -1111,7 +1543,7 @@ def test_complete_query_rest_bad_request( transport: str = "rest", request_type=completion_service.CompleteQueryRequest ): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1135,24 +1567,24 @@ def test_complete_query_rest_bad_request( def test_complete_query_rest_error(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CompletionServiceClient( @@ -1162,7 +1594,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1173,16 +1605,17 @@ 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 = CompletionServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CompletionServiceClient( @@ -1194,7 +1627,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = CompletionServiceClient(transport=transport) assert client.transport is transport @@ -1203,13 +1636,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.CompletionServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1226,7 +1659,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1240,7 +1673,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = CompletionServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1248,7 +1681,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1260,7 +1693,7 @@ def test_completion_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.CompletionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1272,7 +1705,7 @@ def test_completion_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CompletionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1306,7 +1739,7 @@ def test_completion_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CompletionServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1325,7 +1758,7 @@ def test_completion_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CompletionServiceTransport() adc.assert_called_once() @@ -1333,7 +1766,7 @@ def test_completion_service_base_transport_with_adc(): def test_completion_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) CompletionServiceClient() adc.assert_called_once_with( scopes=None, @@ -1353,7 +1786,7 @@ def test_completion_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1400,7 +1833,7 @@ def test_completion_service_transport_create_channel(transport_class, grpc_helpe ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1428,7 +1861,7 @@ def test_completion_service_transport_create_channel(transport_class, grpc_helpe ], ) def test_completion_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1466,7 +1899,7 @@ def test_completion_service_grpc_transport_client_cert_source_for_mtls(transport def test_completion_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1486,7 +1919,7 @@ def test_completion_service_http_transport_client_cert_source_for_mtls(): ) def test_completion_service_host_no_port(transport_name): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -1509,7 +1942,7 @@ def test_completion_service_host_no_port(transport_name): ) def test_completion_service_host_with_port(transport_name): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -1529,8 +1962,8 @@ def test_completion_service_host_with_port(transport_name): ], ) def test_completion_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = CompletionServiceClient( credentials=creds1, transport=transport_name, @@ -1594,7 +2027,7 @@ def test_completion_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -1806,7 +2239,7 @@ def test_client_with_default_client_info(): transports.CompletionServiceTransport, "_prep_wrapped_messages" ) as prep: client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1816,7 +2249,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = CompletionServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1825,7 +2258,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -1840,7 +2273,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1870,7 +2303,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -1898,7 +2331,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1926,7 +2359,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -1952,7 +2385,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1977,7 +2410,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2003,7 +2436,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2032,7 +2465,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2061,7 +2494,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2079,7 +2512,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2097,7 +2530,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2122,7 +2555,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2148,7 +2581,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2177,7 +2610,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2206,7 +2639,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2224,7 +2657,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2248,7 +2681,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2265,7 +2698,7 @@ def test_client_ctx(): ] for transport in transports: client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2299,7 +2732,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_conversational_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_conversational_search_service.py index 2357bf06feff..2652b5a997f0 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_conversational_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_conversational_search_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -75,6 +75,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -107,6 +130,297 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ConversationalSearchServiceClient._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 ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationalSearchServiceClient._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 ConversationalSearchServiceClient._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 ( + ConversationalSearchServiceClient._get_client_cert_source(None, False) is None + ) + assert ( + ConversationalSearchServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + ConversationalSearchServiceClient._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 ( + ConversationalSearchServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ConversationalSearchServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ConversationalSearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), +) +@mock.patch.object( + ConversationalSearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ConversationalSearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationalSearchServiceClient._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 ( + ConversationalSearchServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ConversationalSearchServiceClient._get_universe_domain( + None, universe_domain_env + ) + == universe_domain_env + ) + assert ( + ConversationalSearchServiceClient._get_universe_domain(None, None) + == ConversationalSearchServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ConversationalSearchServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + ConversationalSearchServiceClient, + transports.ConversationalSearchServiceGrpcTransport, + "grpc", + ), + ( + ConversationalSearchServiceClient, + transports.ConversationalSearchServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -118,7 +432,7 @@ def test__get_default_mtls_endpoint(): def test_conversational_search_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -172,7 +486,7 @@ def test_conversational_search_service_client_service_account_always_use_jwt( def test_conversational_search_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -230,13 +544,13 @@ def test_conversational_search_service_client_get_transport_class(): ) @mock.patch.object( ConversationalSearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), ) @mock.patch.object( ConversationalSearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), ) def test_conversational_search_service_client_client_options( client_class, transport_class, transport_name @@ -245,7 +559,9 @@ def test_conversational_search_service_client_client_options( with mock.patch.object( ConversationalSearchServiceClient, "get_transport_class" ) as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -282,7 +598,9 @@ def test_conversational_search_service_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, @@ -312,15 +630,23 @@ def test_conversational_search_service_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") @@ -330,7 +656,9 @@ def test_conversational_search_service_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", @@ -348,7 +676,9 @@ def test_conversational_search_service_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, @@ -401,13 +731,13 @@ def test_conversational_search_service_client_client_options( ) @mock.patch.object( ConversationalSearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), ) @mock.patch.object( ConversationalSearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_conversational_search_service_client_mtls_env_auto( @@ -430,7 +760,9 @@ def test_conversational_search_service_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 @@ -462,7 +794,9 @@ def test_conversational_search_service_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 @@ -496,7 +830,9 @@ def test_conversational_search_service_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, @@ -589,6 +925,121 @@ def test_conversational_search_service_client_get_mtls_endpoint_and_cert_source( 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", + [ConversationalSearchServiceClient, ConversationalSearchServiceAsyncClient], +) +@mock.patch.object( + ConversationalSearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), +) +@mock.patch.object( + ConversationalSearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), +) +def test_conversational_search_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ConversationalSearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ConversationalSearchServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -623,7 +1074,9 @@ def test_conversational_search_service_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, @@ -668,7 +1121,9 @@ def test_conversational_search_service_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, @@ -728,7 +1183,9 @@ def test_conversational_search_service_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, @@ -745,8 +1202,8 @@ def test_conversational_search_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -775,7 +1232,7 @@ def test_conversational_search_service_client_create_channel_credentials_file( ) def test_converse_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -806,7 +1263,7 @@ def test_converse_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -826,7 +1283,7 @@ async def test_converse_conversation_async( request_type=conversational_search_service.ConverseConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -862,7 +1319,7 @@ async def test_converse_conversation_async_from_dict(): def test_converse_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -894,7 +1351,7 @@ def test_converse_conversation_field_headers(): @pytest.mark.asyncio async def test_converse_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -927,7 +1384,7 @@ async def test_converse_conversation_field_headers_async(): def test_converse_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -957,7 +1414,7 @@ def test_converse_conversation_flattened(): def test_converse_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -973,7 +1430,7 @@ def test_converse_conversation_flattened_error(): @pytest.mark.asyncio async def test_converse_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1008,7 +1465,7 @@ async def test_converse_conversation_flattened_async(): @pytest.mark.asyncio async def test_converse_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1030,7 +1487,7 @@ async def test_converse_conversation_flattened_error_async(): ) def test_create_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1066,7 +1523,7 @@ def test_create_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1086,7 +1543,7 @@ async def test_create_conversation_async( request_type=conversational_search_service.CreateConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1127,7 +1584,7 @@ async def test_create_conversation_async_from_dict(): def test_create_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1159,7 +1616,7 @@ def test_create_conversation_field_headers(): @pytest.mark.asyncio async def test_create_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1192,7 +1649,7 @@ async def test_create_conversation_field_headers_async(): def test_create_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1222,7 +1679,7 @@ def test_create_conversation_flattened(): def test_create_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1238,7 +1695,7 @@ def test_create_conversation_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1273,7 +1730,7 @@ async def test_create_conversation_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1295,7 +1752,7 @@ async def test_create_conversation_flattened_error_async(): ) def test_delete_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1324,7 +1781,7 @@ def test_delete_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1344,7 +1801,7 @@ async def test_delete_conversation_async( request_type=conversational_search_service.DeleteConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1376,7 +1833,7 @@ async def test_delete_conversation_async_from_dict(): def test_delete_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1408,7 +1865,7 @@ def test_delete_conversation_field_headers(): @pytest.mark.asyncio async def test_delete_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1439,7 +1896,7 @@ async def test_delete_conversation_field_headers_async(): def test_delete_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1465,7 +1922,7 @@ def test_delete_conversation_flattened(): def test_delete_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1480,7 +1937,7 @@ def test_delete_conversation_flattened_error(): @pytest.mark.asyncio async def test_delete_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1509,7 +1966,7 @@ async def test_delete_conversation_flattened_async(): @pytest.mark.asyncio async def test_delete_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1530,7 +1987,7 @@ async def test_delete_conversation_flattened_error_async(): ) def test_update_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1566,7 +2023,7 @@ def test_update_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1586,7 +2043,7 @@ async def test_update_conversation_async( request_type=conversational_search_service.UpdateConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1627,7 +2084,7 @@ async def test_update_conversation_async_from_dict(): def test_update_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1659,7 +2116,7 @@ def test_update_conversation_field_headers(): @pytest.mark.asyncio async def test_update_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1692,7 +2149,7 @@ async def test_update_conversation_field_headers_async(): def test_update_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1722,7 +2179,7 @@ def test_update_conversation_flattened(): def test_update_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1738,7 +2195,7 @@ def test_update_conversation_flattened_error(): @pytest.mark.asyncio async def test_update_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1773,7 +2230,7 @@ async def test_update_conversation_flattened_async(): @pytest.mark.asyncio async def test_update_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1795,7 +2252,7 @@ async def test_update_conversation_flattened_error_async(): ) def test_get_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1829,7 +2286,7 @@ def test_get_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1847,7 +2304,7 @@ async def test_get_conversation_async( request_type=conversational_search_service.GetConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1886,7 +2343,7 @@ async def test_get_conversation_async_from_dict(): def test_get_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1916,7 +2373,7 @@ def test_get_conversation_field_headers(): @pytest.mark.asyncio async def test_get_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1947,7 +2404,7 @@ async def test_get_conversation_field_headers_async(): def test_get_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1971,7 +2428,7 @@ def test_get_conversation_flattened(): def test_get_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1986,7 +2443,7 @@ def test_get_conversation_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2015,7 +2472,7 @@ async def test_get_conversation_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2036,7 +2493,7 @@ async def test_get_conversation_flattened_error_async(): ) def test_list_conversations(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2068,7 +2525,7 @@ def test_list_conversations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2088,7 +2545,7 @@ async def test_list_conversations_async( request_type=conversational_search_service.ListConversationsRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2125,7 +2582,7 @@ async def test_list_conversations_async_from_dict(): def test_list_conversations_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2157,7 +2614,7 @@ def test_list_conversations_field_headers(): @pytest.mark.asyncio async def test_list_conversations_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2190,7 +2647,7 @@ async def test_list_conversations_field_headers_async(): def test_list_conversations_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2216,7 +2673,7 @@ def test_list_conversations_flattened(): def test_list_conversations_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2231,7 +2688,7 @@ def test_list_conversations_flattened_error(): @pytest.mark.asyncio async def test_list_conversations_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2262,7 +2719,7 @@ async def test_list_conversations_flattened_async(): @pytest.mark.asyncio async def test_list_conversations_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2276,7 +2733,7 @@ async def test_list_conversations_flattened_error_async(): def test_list_conversations_pager(transport_name: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2328,7 +2785,7 @@ def test_list_conversations_pager(transport_name: str = "grpc"): def test_list_conversations_pages(transport_name: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2372,7 +2829,7 @@ def test_list_conversations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversations_async_pager(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2424,7 +2881,7 @@ async def test_list_conversations_async_pager(): @pytest.mark.asyncio async def test_list_conversations_async_pages(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2481,7 +2938,7 @@ async def test_list_conversations_async_pages(): ) def test_converse_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2535,7 +2992,7 @@ def test_converse_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).converse_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2544,7 +3001,7 @@ def test_converse_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).converse_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2553,7 +3010,7 @@ def test_converse_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2600,7 +3057,7 @@ def test_converse_conversation_rest_required_fields( def test_converse_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.converse_conversation._get_unset_required_fields({}) @@ -2618,7 +3075,7 @@ def test_converse_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_converse_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -2681,7 +3138,7 @@ def test_converse_conversation_rest_bad_request( request_type=conversational_search_service.ConverseConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2705,7 +3162,7 @@ def test_converse_conversation_rest_bad_request( def test_converse_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2752,7 +3209,7 @@ def test_converse_conversation_rest_flattened(): def test_converse_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2768,7 +3225,7 @@ def test_converse_conversation_rest_flattened_error(transport: str = "rest"): def test_converse_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2781,7 +3238,7 @@ def test_converse_conversation_rest_error(): ) def test_create_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2937,7 +3394,7 @@ def test_create_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2946,7 +3403,7 @@ def test_create_conversation_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2955,7 +3412,7 @@ def test_create_conversation_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2998,7 +3455,7 @@ def test_create_conversation_rest_required_fields( def test_create_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_conversation._get_unset_required_fields({}) @@ -3016,7 +3473,7 @@ def test_create_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -3076,7 +3533,7 @@ def test_create_conversation_rest_bad_request( request_type=conversational_search_service.CreateConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3098,7 +3555,7 @@ def test_create_conversation_rest_bad_request( def test_create_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3143,7 +3600,7 @@ def test_create_conversation_rest_flattened(): def test_create_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3159,7 +3616,7 @@ def test_create_conversation_rest_flattened_error(transport: str = "rest"): def test_create_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3172,7 +3629,7 @@ def test_create_conversation_rest_error(): ) def test_delete_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3220,7 +3677,7 @@ def test_delete_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3229,7 +3686,7 @@ def test_delete_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3238,7 +3695,7 @@ def test_delete_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3277,7 +3734,7 @@ def test_delete_conversation_rest_required_fields( def test_delete_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_conversation._get_unset_required_fields({}) @@ -3287,7 +3744,7 @@ def test_delete_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -3338,7 +3795,7 @@ def test_delete_conversation_rest_bad_request( request_type=conversational_search_service.DeleteConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3362,7 +3819,7 @@ def test_delete_conversation_rest_bad_request( def test_delete_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3404,7 +3861,7 @@ def test_delete_conversation_rest_flattened(): def test_delete_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3419,7 +3876,7 @@ def test_delete_conversation_rest_flattened_error(transport: str = "rest"): def test_delete_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3432,7 +3889,7 @@ def test_delete_conversation_rest_error(): ) def test_update_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3591,14 +4048,14 @@ def test_update_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3607,7 +4064,7 @@ def test_update_conversation_rest_required_fields( # verify required fields with non-default values are left alone client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3650,7 +4107,7 @@ def test_update_conversation_rest_required_fields( def test_update_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_conversation._get_unset_required_fields({}) @@ -3660,7 +4117,7 @@ def test_update_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -3720,7 +4177,7 @@ def test_update_conversation_rest_bad_request( request_type=conversational_search_service.UpdateConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3746,7 +4203,7 @@ def test_update_conversation_rest_bad_request( def test_update_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3793,7 +4250,7 @@ def test_update_conversation_rest_flattened(): def test_update_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3809,7 +4266,7 @@ def test_update_conversation_rest_flattened_error(transport: str = "rest"): def test_update_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3822,7 +4279,7 @@ def test_update_conversation_rest_error(): ) def test_get_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3879,7 +4336,7 @@ def test_get_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3888,7 +4345,7 @@ def test_get_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3897,7 +4354,7 @@ def test_get_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3939,7 +4396,7 @@ def test_get_conversation_rest_required_fields( def test_get_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_conversation._get_unset_required_fields({}) @@ -3949,7 +4406,7 @@ def test_get_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -4008,7 +4465,7 @@ def test_get_conversation_rest_bad_request( request_type=conversational_search_service.GetConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4032,7 +4489,7 @@ def test_get_conversation_rest_bad_request( def test_get_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4076,7 +4533,7 @@ def test_get_conversation_rest_flattened(): def test_get_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4091,7 +4548,7 @@ def test_get_conversation_rest_flattened_error(transport: str = "rest"): def test_get_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4104,7 +4561,7 @@ def test_get_conversation_rest_error(): ) def test_list_conversations_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4157,7 +4614,7 @@ def test_list_conversations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4166,7 +4623,7 @@ def test_list_conversations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4184,7 +4641,7 @@ def test_list_conversations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4228,7 +4685,7 @@ def test_list_conversations_rest_required_fields( def test_list_conversations_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_conversations._get_unset_required_fields({}) @@ -4248,7 +4705,7 @@ def test_list_conversations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversations_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -4309,7 +4766,7 @@ def test_list_conversations_rest_bad_request( request_type=conversational_search_service.ListConversationsRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4331,7 +4788,7 @@ def test_list_conversations_rest_bad_request( def test_list_conversations_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4377,7 +4834,7 @@ def test_list_conversations_rest_flattened(): def test_list_conversations_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4392,7 +4849,7 @@ def test_list_conversations_rest_flattened_error(transport: str = "rest"): def test_list_conversations_rest_pager(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4459,17 +4916,17 @@ def test_list_conversations_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationalSearchServiceClient( @@ -4479,7 +4936,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4490,16 +4947,17 @@ 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 = ConversationalSearchServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationalSearchServiceClient( @@ -4511,7 +4969,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ConversationalSearchServiceClient(transport=transport) assert client.transport is transport @@ -4520,13 +4978,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ConversationalSearchServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4543,7 +5001,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4557,7 +5015,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ConversationalSearchServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4565,7 +5023,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4577,7 +5035,7 @@ def test_conversational_search_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ConversationalSearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4589,7 +5047,7 @@ def test_conversational_search_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConversationalSearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4628,7 +5086,7 @@ def test_conversational_search_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationalSearchServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4647,7 +5105,7 @@ def test_conversational_search_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationalSearchServiceTransport() adc.assert_called_once() @@ -4655,7 +5113,7 @@ def test_conversational_search_service_base_transport_with_adc(): def test_conversational_search_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ConversationalSearchServiceClient() adc.assert_called_once_with( scopes=None, @@ -4675,7 +5133,7 @@ def test_conversational_search_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4727,7 +5185,7 @@ def test_conversational_search_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4757,7 +5215,7 @@ def test_conversational_search_service_transport_create_channel( def test_conversational_search_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4795,7 +5253,7 @@ def test_conversational_search_service_grpc_transport_client_cert_source_for_mtl def test_conversational_search_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4815,7 +5273,7 @@ def test_conversational_search_service_http_transport_client_cert_source_for_mtl ) def test_conversational_search_service_host_no_port(transport_name): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -4838,7 +5296,7 @@ def test_conversational_search_service_host_no_port(transport_name): ) def test_conversational_search_service_host_with_port(transport_name): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4860,8 +5318,8 @@ def test_conversational_search_service_host_with_port(transport_name): def test_conversational_search_service_client_transport_session_collision( transport_name, ): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ConversationalSearchServiceClient( credentials=creds1, transport=transport_name, @@ -4940,7 +5398,7 @@ def test_conversational_search_service_transport_channel_mtls_with_client_cert_s mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5252,7 +5710,7 @@ def test_client_with_default_client_info(): transports.ConversationalSearchServiceTransport, "_prep_wrapped_messages" ) as prep: client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5262,7 +5720,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ConversationalSearchServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5271,7 +5729,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5286,7 +5744,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5316,7 +5774,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -5344,7 +5802,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5372,7 +5830,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -5398,7 +5856,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5423,7 +5881,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5449,7 +5907,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5478,7 +5936,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5507,7 +5965,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5525,7 +5983,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5543,7 +6001,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5568,7 +6026,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5594,7 +6052,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5623,7 +6081,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5652,7 +6110,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5670,7 +6128,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5694,7 +6152,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5711,7 +6169,7 @@ def test_client_ctx(): ] for transport in transports: client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5748,7 +6206,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_document_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_document_service.py index e5ffd7e12315..70cfbf5c93b6 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_document_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_document_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -85,6 +85,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -114,6 +137,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert DocumentServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DocumentServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DocumentServiceClient._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 DocumentServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentServiceClient._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 DocumentServiceClient._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 DocumentServiceClient._get_client_cert_source(None, False) is None + assert ( + DocumentServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + DocumentServiceClient._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 ( + DocumentServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DocumentServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DocumentServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), +) +@mock.patch.object( + DocumentServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DocumentServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DocumentServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DocumentServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "always") + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentServiceClient._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 ( + DocumentServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DocumentServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DocumentServiceClient._get_universe_domain(None, None) + == DocumentServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DocumentServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DocumentServiceClient, transports.DocumentServiceGrpcTransport, "grpc"), + (DocumentServiceClient, transports.DocumentServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -125,7 +409,7 @@ def test__get_default_mtls_endpoint(): def test_document_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -179,7 +463,7 @@ def test_document_service_client_service_account_always_use_jwt( def test_document_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -229,20 +513,22 @@ def test_document_service_client_get_transport_class(): ) @mock.patch.object( DocumentServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), ) @mock.patch.object( DocumentServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), ) def test_document_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(DocumentServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -277,7 +563,9 @@ def test_document_service_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, @@ -307,15 +595,23 @@ def test_document_service_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") @@ -325,7 +621,9 @@ def test_document_service_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", @@ -343,7 +641,9 @@ def test_document_service_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, @@ -396,13 +696,13 @@ def test_document_service_client_client_options( ) @mock.patch.object( DocumentServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), ) @mock.patch.object( DocumentServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_document_service_client_mtls_env_auto( @@ -425,7 +725,9 @@ def test_document_service_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 @@ -457,7 +759,9 @@ def test_document_service_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 @@ -491,7 +795,9 @@ def test_document_service_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, @@ -581,6 +887,118 @@ def test_document_service_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", [DocumentServiceClient, DocumentServiceAsyncClient] +) +@mock.patch.object( + DocumentServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), +) +@mock.patch.object( + DocumentServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), +) +def test_document_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DocumentServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -607,7 +1025,9 @@ def test_document_service_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, @@ -647,7 +1067,9 @@ def test_document_service_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, @@ -707,7 +1129,9 @@ def test_document_service_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, @@ -724,8 +1148,8 @@ def test_document_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -754,7 +1178,7 @@ def test_document_service_client_create_channel_credentials_file( ) def test_get_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -791,7 +1215,7 @@ def test_get_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -808,7 +1232,7 @@ async def test_get_document_async( transport: str = "grpc_asyncio", request_type=document_service.GetDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -849,7 +1273,7 @@ async def test_get_document_async_from_dict(): def test_get_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -879,7 +1303,7 @@ def test_get_document_field_headers(): @pytest.mark.asyncio async def test_get_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -908,7 +1332,7 @@ async def test_get_document_field_headers_async(): def test_get_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -932,7 +1356,7 @@ def test_get_document_flattened(): def test_get_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -947,7 +1371,7 @@ def test_get_document_flattened_error(): @pytest.mark.asyncio async def test_get_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -974,7 +1398,7 @@ async def test_get_document_flattened_async(): @pytest.mark.asyncio async def test_get_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -995,7 +1419,7 @@ async def test_get_document_flattened_error_async(): ) def test_list_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1025,7 +1449,7 @@ def test_list_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1042,7 +1466,7 @@ async def test_list_documents_async( transport: str = "grpc_asyncio", request_type=document_service.ListDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1077,7 +1501,7 @@ async def test_list_documents_async_from_dict(): def test_list_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1107,7 +1531,7 @@ def test_list_documents_field_headers(): @pytest.mark.asyncio async def test_list_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1138,7 +1562,7 @@ async def test_list_documents_field_headers_async(): def test_list_documents_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1162,7 +1586,7 @@ def test_list_documents_flattened(): def test_list_documents_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1177,7 +1601,7 @@ def test_list_documents_flattened_error(): @pytest.mark.asyncio async def test_list_documents_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1206,7 +1630,7 @@ async def test_list_documents_flattened_async(): @pytest.mark.asyncio async def test_list_documents_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1220,7 +1644,7 @@ async def test_list_documents_flattened_error_async(): def test_list_documents_pager(transport_name: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1270,7 +1694,7 @@ def test_list_documents_pager(transport_name: str = "grpc"): def test_list_documents_pages(transport_name: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1312,7 +1736,7 @@ def test_list_documents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_documents_async_pager(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1362,7 +1786,7 @@ async def test_list_documents_async_pager(): @pytest.mark.asyncio async def test_list_documents_async_pages(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1417,7 +1841,7 @@ async def test_list_documents_async_pages(): ) def test_create_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1454,7 +1878,7 @@ def test_create_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1471,7 +1895,7 @@ async def test_create_document_async( transport: str = "grpc_asyncio", request_type=document_service.CreateDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1512,7 +1936,7 @@ async def test_create_document_async_from_dict(): def test_create_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1542,7 +1966,7 @@ def test_create_document_field_headers(): @pytest.mark.asyncio async def test_create_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1573,7 +1997,7 @@ async def test_create_document_field_headers_async(): def test_create_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1621,7 +2045,7 @@ def test_create_document_flattened(): def test_create_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1646,7 +2070,7 @@ def test_create_document_flattened_error(): @pytest.mark.asyncio async def test_create_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1699,7 +2123,7 @@ async def test_create_document_flattened_async(): @pytest.mark.asyncio async def test_create_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1730,7 +2154,7 @@ async def test_create_document_flattened_error_async(): ) def test_update_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1767,7 +2191,7 @@ def test_update_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1784,7 +2208,7 @@ async def test_update_document_async( transport: str = "grpc_asyncio", request_type=document_service.UpdateDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1825,7 +2249,7 @@ async def test_update_document_async_from_dict(): def test_update_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1855,7 +2279,7 @@ def test_update_document_field_headers(): @pytest.mark.asyncio async def test_update_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1891,7 +2315,7 @@ async def test_update_document_field_headers_async(): ) def test_delete_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1918,7 +2342,7 @@ def test_delete_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1935,7 +2359,7 @@ async def test_delete_document_async( transport: str = "grpc_asyncio", request_type=document_service.DeleteDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1965,7 +2389,7 @@ async def test_delete_document_async_from_dict(): def test_delete_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1995,7 +2419,7 @@ def test_delete_document_field_headers(): @pytest.mark.asyncio async def test_delete_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2024,7 +2448,7 @@ async def test_delete_document_field_headers_async(): def test_delete_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2048,7 +2472,7 @@ def test_delete_document_flattened(): def test_delete_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2063,7 +2487,7 @@ def test_delete_document_flattened_error(): @pytest.mark.asyncio async def test_delete_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2090,7 +2514,7 @@ async def test_delete_document_flattened_async(): @pytest.mark.asyncio async def test_delete_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2111,7 +2535,7 @@ async def test_delete_document_flattened_error_async(): ) def test_import_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2138,7 +2562,7 @@ def test_import_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2155,7 +2579,7 @@ async def test_import_documents_async( transport: str = "grpc_asyncio", request_type=import_config.ImportDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2187,7 +2611,7 @@ async def test_import_documents_async_from_dict(): def test_import_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2217,7 +2641,7 @@ def test_import_documents_field_headers(): @pytest.mark.asyncio async def test_import_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2255,7 +2679,7 @@ async def test_import_documents_field_headers_async(): ) def test_purge_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2282,7 +2706,7 @@ def test_purge_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2299,7 +2723,7 @@ async def test_purge_documents_async( transport: str = "grpc_asyncio", request_type=purge_config.PurgeDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2331,7 +2755,7 @@ async def test_purge_documents_async_from_dict(): def test_purge_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2361,7 +2785,7 @@ def test_purge_documents_field_headers(): @pytest.mark.asyncio async def test_purge_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2399,7 +2823,7 @@ async def test_purge_documents_field_headers_async(): ) def test_get_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2459,7 +2883,7 @@ def test_get_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2468,7 +2892,7 @@ def test_get_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2477,7 +2901,7 @@ def test_get_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2519,7 +2943,7 @@ def test_get_document_rest_required_fields( def test_get_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_document._get_unset_required_fields({}) @@ -2529,7 +2953,7 @@ def test_get_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -2585,7 +3009,7 @@ def test_get_document_rest_bad_request( transport: str = "rest", request_type=document_service.GetDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2609,7 +3033,7 @@ def test_get_document_rest_bad_request( def test_get_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2653,7 +3077,7 @@ def test_get_document_rest_flattened(): def test_get_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2668,7 +3092,7 @@ def test_get_document_rest_flattened_error(transport: str = "rest"): def test_get_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2681,7 +3105,7 @@ def test_get_document_rest_error(): ) def test_list_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2734,7 +3158,7 @@ def test_list_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2743,7 +3167,7 @@ def test_list_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2759,7 +3183,7 @@ def test_list_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2801,7 +3225,7 @@ def test_list_documents_rest_required_fields( def test_list_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_documents._get_unset_required_fields({}) @@ -2819,7 +3243,7 @@ def test_list_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -2877,7 +3301,7 @@ def test_list_documents_rest_bad_request( transport: str = "rest", request_type=document_service.ListDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2901,7 +3325,7 @@ def test_list_documents_rest_bad_request( def test_list_documents_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2945,7 +3369,7 @@ def test_list_documents_rest_flattened(): def test_list_documents_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2960,7 +3384,7 @@ def test_list_documents_rest_flattened_error(transport: str = "rest"): def test_list_documents_rest_pager(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3032,7 +3456,7 @@ def test_list_documents_rest_pager(transport: str = "rest"): ) def test_create_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3175,7 +3599,7 @@ def test_create_document_rest_required_fields( assert "documentId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3187,7 +3611,7 @@ def test_create_document_rest_required_fields( jsonified_request["documentId"] = "document_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("document_id",)) @@ -3200,7 +3624,7 @@ def test_create_document_rest_required_fields( assert jsonified_request["documentId"] == "document_id_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3249,7 +3673,7 @@ def test_create_document_rest_required_fields( def test_create_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_document._get_unset_required_fields({}) @@ -3268,7 +3692,7 @@ def test_create_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3326,7 +3750,7 @@ def test_create_document_rest_bad_request( transport: str = "rest", request_type=document_service.CreateDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3350,7 +3774,7 @@ def test_create_document_rest_bad_request( def test_create_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3404,7 +3828,7 @@ def test_create_document_rest_flattened(): def test_create_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3429,7 +3853,7 @@ def test_create_document_rest_flattened_error(transport: str = "rest"): def test_create_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3442,7 +3866,7 @@ def test_create_document_rest_error(): ) def test_update_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3584,14 +4008,14 @@ def test_update_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("allow_missing",)) @@ -3600,7 +4024,7 @@ def test_update_document_rest_required_fields( # verify required fields with non-default values are left alone client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3643,7 +4067,7 @@ def test_update_document_rest_required_fields( def test_update_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_document._get_unset_required_fields({}) @@ -3653,7 +4077,7 @@ def test_update_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3709,7 +4133,7 @@ def test_update_document_rest_bad_request( transport: str = "rest", request_type=document_service.UpdateDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3735,7 +4159,7 @@ def test_update_document_rest_bad_request( def test_update_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3748,7 +4172,7 @@ def test_update_document_rest_error(): ) def test_delete_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3796,7 +4220,7 @@ def test_delete_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3805,7 +4229,7 @@ def test_delete_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3814,7 +4238,7 @@ def test_delete_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3853,7 +4277,7 @@ def test_delete_document_rest_required_fields( def test_delete_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_document._get_unset_required_fields({}) @@ -3863,7 +4287,7 @@ def test_delete_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3913,7 +4337,7 @@ def test_delete_document_rest_bad_request( transport: str = "rest", request_type=document_service.DeleteDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3937,7 +4361,7 @@ def test_delete_document_rest_bad_request( def test_delete_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3979,7 +4403,7 @@ def test_delete_document_rest_flattened(): def test_delete_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3994,7 +4418,7 @@ def test_delete_document_rest_flattened_error(transport: str = "rest"): def test_delete_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4007,7 +4431,7 @@ def test_delete_document_rest_error(): ) def test_import_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4055,7 +4479,7 @@ def test_import_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4064,7 +4488,7 @@ def test_import_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4073,7 +4497,7 @@ def test_import_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4113,7 +4537,7 @@ def test_import_documents_rest_required_fields( def test_import_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_documents._get_unset_required_fields({}) @@ -4123,7 +4547,7 @@ def test_import_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -4183,7 +4607,7 @@ def test_import_documents_rest_bad_request( transport: str = "rest", request_type=import_config.ImportDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4207,7 +4631,7 @@ def test_import_documents_rest_bad_request( def test_import_documents_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4220,7 +4644,7 @@ def test_import_documents_rest_error(): ) def test_purge_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4269,7 +4693,7 @@ def test_purge_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).purge_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4279,7 +4703,7 @@ def test_purge_documents_rest_required_fields( jsonified_request["filter"] = "filter_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).purge_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4290,7 +4714,7 @@ def test_purge_documents_rest_required_fields( assert jsonified_request["filter"] == "filter_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4330,7 +4754,7 @@ def test_purge_documents_rest_required_fields( def test_purge_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.purge_documents._get_unset_required_fields({}) @@ -4348,7 +4772,7 @@ def test_purge_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_purge_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -4408,7 +4832,7 @@ def test_purge_documents_rest_bad_request( transport: str = "rest", request_type=purge_config.PurgeDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4432,24 +4856,24 @@ def test_purge_documents_rest_bad_request( def test_purge_documents_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( @@ -4459,7 +4883,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4470,16 +4894,17 @@ 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 = DocumentServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( @@ -4491,7 +4916,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DocumentServiceClient(transport=transport) assert client.transport is transport @@ -4500,13 +4925,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DocumentServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4523,7 +4948,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4537,7 +4962,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DocumentServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4545,7 +4970,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4557,7 +4982,7 @@ def test_document_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DocumentServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4569,7 +4994,7 @@ def test_document_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DocumentServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4614,7 +5039,7 @@ def test_document_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4633,7 +5058,7 @@ def test_document_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentServiceTransport() adc.assert_called_once() @@ -4641,7 +5066,7 @@ def test_document_service_base_transport_with_adc(): def test_document_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DocumentServiceClient() adc.assert_called_once_with( scopes=None, @@ -4661,7 +5086,7 @@ def test_document_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4708,7 +5133,7 @@ def test_document_service_transport_create_channel(transport_class, grpc_helpers ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4736,7 +5161,7 @@ def test_document_service_transport_create_channel(transport_class, grpc_helpers ], ) def test_document_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4774,7 +5199,7 @@ def test_document_service_grpc_transport_client_cert_source_for_mtls(transport_c def test_document_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4786,7 +5211,7 @@ def test_document_service_http_transport_client_cert_source_for_mtls(): def test_document_service_rest_lro_client(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -4811,7 +5236,7 @@ def test_document_service_rest_lro_client(): ) def test_document_service_host_no_port(transport_name): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -4834,7 +5259,7 @@ def test_document_service_host_no_port(transport_name): ) def test_document_service_host_with_port(transport_name): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4854,8 +5279,8 @@ def test_document_service_host_with_port(transport_name): ], ) def test_document_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DocumentServiceClient( credentials=creds1, transport=transport_name, @@ -4937,7 +5362,7 @@ def test_document_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5015,7 +5440,7 @@ def test_document_service_transport_channel_mtls_with_adc(transport_class): def test_document_service_grpc_lro_client(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5032,7 +5457,7 @@ def test_document_service_grpc_lro_client(): def test_document_service_grpc_lro_async_client(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -5220,7 +5645,7 @@ def test_client_with_default_client_info(): transports.DocumentServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5230,7 +5655,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5239,7 +5664,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5254,7 +5679,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5284,7 +5709,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -5312,7 +5737,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5340,7 +5765,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -5366,7 +5791,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5391,7 +5816,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5417,7 +5842,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5446,7 +5871,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5475,7 +5900,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5493,7 +5918,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5511,7 +5936,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5536,7 +5961,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5562,7 +5987,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5591,7 +6016,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5620,7 +6045,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5638,7 +6063,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5662,7 +6087,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5679,7 +6104,7 @@ def test_client_ctx(): ] for transport in transports: client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5710,7 +6135,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_schema_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_schema_service.py index fa968cf6b5d4..e561f048a876 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_schema_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_schema_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -81,6 +81,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -110,6 +133,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SchemaServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SchemaServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SchemaServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SchemaServiceClient._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 SchemaServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SchemaServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SchemaServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SchemaServiceClient._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 SchemaServiceClient._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 SchemaServiceClient._get_client_cert_source(None, False) is None + assert ( + SchemaServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + SchemaServiceClient._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 ( + SchemaServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SchemaServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SchemaServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), +) +@mock.patch.object( + SchemaServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SchemaServiceClient._DEFAULT_UNIVERSE + default_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SchemaServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SchemaServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, default_universe, "always") + == SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SchemaServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SchemaServiceClient._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 ( + SchemaServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SchemaServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SchemaServiceClient._get_universe_domain(None, None) + == SchemaServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SchemaServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SchemaServiceClient, transports.SchemaServiceGrpcTransport, "grpc"), + (SchemaServiceClient, transports.SchemaServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -119,7 +399,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_schema_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -171,7 +451,7 @@ def test_schema_service_client_service_account_always_use_jwt( ], ) def test_schema_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -221,20 +501,22 @@ def test_schema_service_client_get_transport_class(): ) @mock.patch.object( SchemaServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), ) @mock.patch.object( SchemaServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), ) def test_schema_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SchemaServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -269,7 +551,9 @@ def test_schema_service_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, @@ -299,15 +583,23 @@ def test_schema_service_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") @@ -317,7 +609,9 @@ def test_schema_service_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", @@ -335,7 +629,9 @@ def test_schema_service_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, @@ -368,13 +664,13 @@ def test_schema_service_client_client_options( ) @mock.patch.object( SchemaServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), ) @mock.patch.object( SchemaServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_schema_service_client_mtls_env_auto( @@ -397,7 +693,9 @@ def test_schema_service_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 @@ -429,7 +727,9 @@ def test_schema_service_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 @@ -463,7 +763,9 @@ def test_schema_service_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, @@ -553,6 +855,118 @@ def test_schema_service_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", [SchemaServiceClient, SchemaServiceAsyncClient] +) +@mock.patch.object( + SchemaServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), +) +@mock.patch.object( + SchemaServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), +) +def test_schema_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SchemaServiceClient._DEFAULT_UNIVERSE + default_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SchemaServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -579,7 +993,9 @@ def test_schema_service_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, @@ -619,7 +1035,9 @@ def test_schema_service_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, @@ -679,7 +1097,9 @@ def test_schema_service_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, @@ -696,8 +1116,8 @@ def test_schema_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -726,7 +1146,7 @@ def test_schema_service_client_create_channel_credentials_file( ) def test_get_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -757,7 +1177,7 @@ def test_get_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -774,7 +1194,7 @@ async def test_get_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.GetSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -809,7 +1229,7 @@ async def test_get_schema_async_from_dict(): def test_get_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -839,7 +1259,7 @@ def test_get_schema_field_headers(): @pytest.mark.asyncio async def test_get_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -868,7 +1288,7 @@ async def test_get_schema_field_headers_async(): def test_get_schema_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -892,7 +1312,7 @@ def test_get_schema_flattened(): def test_get_schema_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -907,7 +1327,7 @@ def test_get_schema_flattened_error(): @pytest.mark.asyncio async def test_get_schema_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -934,7 +1354,7 @@ async def test_get_schema_flattened_async(): @pytest.mark.asyncio async def test_get_schema_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -955,7 +1375,7 @@ async def test_get_schema_flattened_error_async(): ) def test_list_schemas(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -985,7 +1405,7 @@ def test_list_schemas_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1002,7 +1422,7 @@ async def test_list_schemas_async( transport: str = "grpc_asyncio", request_type=schema_service.ListSchemasRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1037,7 +1457,7 @@ async def test_list_schemas_async_from_dict(): def test_list_schemas_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1067,7 +1487,7 @@ def test_list_schemas_field_headers(): @pytest.mark.asyncio async def test_list_schemas_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1098,7 +1518,7 @@ async def test_list_schemas_field_headers_async(): def test_list_schemas_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1122,7 +1542,7 @@ def test_list_schemas_flattened(): def test_list_schemas_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1137,7 +1557,7 @@ def test_list_schemas_flattened_error(): @pytest.mark.asyncio async def test_list_schemas_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1166,7 +1586,7 @@ async def test_list_schemas_flattened_async(): @pytest.mark.asyncio async def test_list_schemas_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1180,7 +1600,7 @@ async def test_list_schemas_flattened_error_async(): def test_list_schemas_pager(transport_name: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1230,7 +1650,7 @@ def test_list_schemas_pager(transport_name: str = "grpc"): def test_list_schemas_pages(transport_name: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1272,7 +1692,7 @@ def test_list_schemas_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_schemas_async_pager(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1322,7 +1742,7 @@ async def test_list_schemas_async_pager(): @pytest.mark.asyncio async def test_list_schemas_async_pages(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1377,7 +1797,7 @@ async def test_list_schemas_async_pages(): ) def test_create_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1404,7 +1824,7 @@ def test_create_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1421,7 +1841,7 @@ async def test_create_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.CreateSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1453,7 +1873,7 @@ async def test_create_schema_async_from_dict(): def test_create_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1483,7 +1903,7 @@ def test_create_schema_field_headers(): @pytest.mark.asyncio async def test_create_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1514,7 +1934,7 @@ async def test_create_schema_field_headers_async(): def test_create_schema_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1562,7 +1982,7 @@ def test_create_schema_flattened(): def test_create_schema_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1587,7 +2007,7 @@ def test_create_schema_flattened_error(): @pytest.mark.asyncio async def test_create_schema_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1640,7 +2060,7 @@ async def test_create_schema_flattened_async(): @pytest.mark.asyncio async def test_create_schema_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1671,7 +2091,7 @@ async def test_create_schema_flattened_error_async(): ) def test_update_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1698,7 +2118,7 @@ def test_update_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1715,7 +2135,7 @@ async def test_update_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.UpdateSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1747,7 +2167,7 @@ async def test_update_schema_async_from_dict(): def test_update_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1777,7 +2197,7 @@ def test_update_schema_field_headers(): @pytest.mark.asyncio async def test_update_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1815,7 +2235,7 @@ async def test_update_schema_field_headers_async(): ) def test_delete_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1842,7 +2262,7 @@ def test_delete_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1859,7 +2279,7 @@ async def test_delete_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.DeleteSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1891,7 +2311,7 @@ async def test_delete_schema_async_from_dict(): def test_delete_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1921,7 +2341,7 @@ def test_delete_schema_field_headers(): @pytest.mark.asyncio async def test_delete_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1952,7 +2372,7 @@ async def test_delete_schema_field_headers_async(): def test_delete_schema_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1976,7 +2396,7 @@ def test_delete_schema_flattened(): def test_delete_schema_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1991,7 +2411,7 @@ def test_delete_schema_flattened_error(): @pytest.mark.asyncio async def test_delete_schema_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2020,7 +2440,7 @@ async def test_delete_schema_flattened_async(): @pytest.mark.asyncio async def test_delete_schema_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2041,7 +2461,7 @@ async def test_delete_schema_flattened_error_async(): ) def test_get_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2093,7 +2513,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2102,7 +2522,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2111,7 +2531,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe assert jsonified_request["name"] == "name_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2153,7 +2573,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe def test_get_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_schema._get_unset_required_fields({}) @@ -2163,7 +2583,7 @@ def test_get_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -2219,7 +2639,7 @@ def test_get_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.GetSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2243,7 +2663,7 @@ def test_get_schema_rest_bad_request( def test_get_schema_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2287,7 +2707,7 @@ def test_get_schema_rest_flattened(): def test_get_schema_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2302,7 +2722,7 @@ def test_get_schema_rest_flattened_error(transport: str = "rest"): def test_get_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2315,7 +2735,7 @@ def test_get_schema_rest_error(): ) def test_list_schemas_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2366,7 +2786,7 @@ def test_list_schemas_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_schemas._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2375,7 +2795,7 @@ def test_list_schemas_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_schemas._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2391,7 +2811,7 @@ def test_list_schemas_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2433,7 +2853,7 @@ def test_list_schemas_rest_required_fields( def test_list_schemas_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_schemas._get_unset_required_fields({}) @@ -2451,7 +2871,7 @@ def test_list_schemas_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_schemas_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -2509,7 +2929,7 @@ def test_list_schemas_rest_bad_request( transport: str = "rest", request_type=schema_service.ListSchemasRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2531,7 +2951,7 @@ def test_list_schemas_rest_bad_request( def test_list_schemas_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2575,7 +2995,7 @@ def test_list_schemas_rest_flattened(): def test_list_schemas_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2590,7 +3010,7 @@ def test_list_schemas_rest_flattened_error(transport: str = "rest"): def test_list_schemas_rest_pager(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2662,7 +3082,7 @@ def test_list_schemas_rest_pager(transport: str = "rest"): ) def test_create_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2782,7 +3202,7 @@ def test_create_schema_rest_required_fields( assert "schemaId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2794,7 +3214,7 @@ def test_create_schema_rest_required_fields( jsonified_request["schemaId"] = "schema_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_schema._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("schema_id",)) @@ -2807,7 +3227,7 @@ def test_create_schema_rest_required_fields( assert jsonified_request["schemaId"] == "schema_id_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2853,7 +3273,7 @@ def test_create_schema_rest_required_fields( def test_create_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_schema._get_unset_required_fields({}) @@ -2872,7 +3292,7 @@ def test_create_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -2932,7 +3352,7 @@ def test_create_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.CreateSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2954,7 +3374,7 @@ def test_create_schema_rest_bad_request( def test_create_schema_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3006,7 +3426,7 @@ def test_create_schema_rest_flattened(): def test_create_schema_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3031,7 +3451,7 @@ def test_create_schema_rest_flattened_error(transport: str = "rest"): def test_create_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3044,7 +3464,7 @@ def test_create_schema_rest_error(): ) def test_update_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3165,14 +3585,14 @@ def test_update_schema_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_schema._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("allow_missing",)) @@ -3181,7 +3601,7 @@ def test_update_schema_rest_required_fields( # verify required fields with non-default values are left alone client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3221,7 +3641,7 @@ def test_update_schema_rest_required_fields( def test_update_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_schema._get_unset_required_fields({}) @@ -3231,7 +3651,7 @@ def test_update_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -3291,7 +3711,7 @@ def test_update_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.UpdateSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3317,7 +3737,7 @@ def test_update_schema_rest_bad_request( def test_update_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3330,7 +3750,7 @@ def test_update_schema_rest_error(): ) def test_delete_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3378,7 +3798,7 @@ def test_delete_schema_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3387,7 +3807,7 @@ def test_delete_schema_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3396,7 +3816,7 @@ def test_delete_schema_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3435,7 +3855,7 @@ def test_delete_schema_rest_required_fields( def test_delete_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_schema._get_unset_required_fields({}) @@ -3445,7 +3865,7 @@ def test_delete_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -3505,7 +3925,7 @@ def test_delete_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.DeleteSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3529,7 +3949,7 @@ def test_delete_schema_rest_bad_request( def test_delete_schema_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3571,7 +3991,7 @@ def test_delete_schema_rest_flattened(): def test_delete_schema_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3586,24 +4006,24 @@ def test_delete_schema_rest_flattened_error(transport: str = "rest"): def test_delete_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SchemaServiceClient( @@ -3613,7 +4033,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3624,16 +4044,17 @@ 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 = SchemaServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SchemaServiceClient( @@ -3645,7 +4066,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SchemaServiceClient(transport=transport) assert client.transport is transport @@ -3654,13 +4075,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SchemaServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3677,7 +4098,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3691,7 +4112,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SchemaServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3699,7 +4120,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3711,7 +4132,7 @@ def test_schema_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SchemaServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3723,7 +4144,7 @@ def test_schema_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SchemaServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3766,7 +4187,7 @@ def test_schema_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SchemaServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3785,7 +4206,7 @@ def test_schema_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SchemaServiceTransport() adc.assert_called_once() @@ -3793,7 +4214,7 @@ def test_schema_service_base_transport_with_adc(): def test_schema_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SchemaServiceClient() adc.assert_called_once_with( scopes=None, @@ -3813,7 +4234,7 @@ def test_schema_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -3860,7 +4281,7 @@ def test_schema_service_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3888,7 +4309,7 @@ def test_schema_service_transport_create_channel(transport_class, grpc_helpers): ], ) def test_schema_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3926,7 +4347,7 @@ def test_schema_service_grpc_transport_client_cert_source_for_mtls(transport_cla def test_schema_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -3938,7 +4359,7 @@ def test_schema_service_http_transport_client_cert_source_for_mtls(): def test_schema_service_rest_lro_client(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -3963,7 +4384,7 @@ def test_schema_service_rest_lro_client(): ) def test_schema_service_host_no_port(transport_name): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -3986,7 +4407,7 @@ def test_schema_service_host_no_port(transport_name): ) def test_schema_service_host_with_port(transport_name): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4006,8 +4427,8 @@ def test_schema_service_host_with_port(transport_name): ], ) def test_schema_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SchemaServiceClient( credentials=creds1, transport=transport_name, @@ -4081,7 +4502,7 @@ def test_schema_service_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4159,7 +4580,7 @@ def test_schema_service_transport_channel_mtls_with_adc(transport_class): def test_schema_service_grpc_lro_client(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -4176,7 +4597,7 @@ def test_schema_service_grpc_lro_client(): def test_schema_service_grpc_lro_async_client(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -4356,7 +4777,7 @@ def test_client_with_default_client_info(): transports.SchemaServiceTransport, "_prep_wrapped_messages" ) as prep: client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4366,7 +4787,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SchemaServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4375,7 +4796,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4390,7 +4811,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4420,7 +4841,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -4448,7 +4869,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4476,7 +4897,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -4502,7 +4923,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4527,7 +4948,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4553,7 +4974,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4582,7 +5003,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4611,7 +5032,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4629,7 +5050,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4647,7 +5068,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4672,7 +5093,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4698,7 +5119,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4727,7 +5148,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4756,7 +5177,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -4774,7 +5195,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -4798,7 +5219,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -4815,7 +5236,7 @@ def test_client_ctx(): ] for transport in transports: client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -4846,7 +5267,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_service.py index 7e4e35e5d418..6b54b9d03478 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_search_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -69,6 +69,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -98,6 +121,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SearchServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SearchServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SearchServiceClient._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 SearchServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SearchServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SearchServiceClient._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 SearchServiceClient._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 SearchServiceClient._get_client_cert_source(None, False) is None + assert ( + SearchServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + SearchServiceClient._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 ( + SearchServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SearchServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), +) +@mock.patch.object( + SearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SearchServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, default_universe, "always") + == SearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SearchServiceClient._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 ( + SearchServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SearchServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SearchServiceClient._get_universe_domain(None, None) + == SearchServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SearchServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SearchServiceClient, transports.SearchServiceGrpcTransport, "grpc"), + (SearchServiceClient, transports.SearchServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -107,7 +387,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_search_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -159,7 +439,7 @@ def test_search_service_client_service_account_always_use_jwt( ], ) def test_search_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -209,20 +489,22 @@ def test_search_service_client_get_transport_class(): ) @mock.patch.object( SearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), ) @mock.patch.object( SearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), ) def test_search_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SearchServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -257,7 +539,9 @@ def test_search_service_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, @@ -287,15 +571,23 @@ def test_search_service_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") @@ -305,7 +597,9 @@ def test_search_service_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", @@ -323,7 +617,9 @@ def test_search_service_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, @@ -356,13 +652,13 @@ def test_search_service_client_client_options( ) @mock.patch.object( SearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), ) @mock.patch.object( SearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_search_service_client_mtls_env_auto( @@ -385,7 +681,9 @@ def test_search_service_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 @@ -417,7 +715,9 @@ def test_search_service_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 @@ -451,7 +751,9 @@ def test_search_service_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, @@ -541,6 +843,118 @@ def test_search_service_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", [SearchServiceClient, SearchServiceAsyncClient] +) +@mock.patch.object( + SearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), +) +@mock.patch.object( + SearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), +) +def test_search_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SearchServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -567,7 +981,9 @@ def test_search_service_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, @@ -607,7 +1023,9 @@ def test_search_service_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, @@ -667,7 +1085,9 @@ def test_search_service_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, @@ -684,8 +1104,8 @@ def test_search_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -714,7 +1134,7 @@ def test_search_service_client_create_channel_credentials_file( ) def test_search(request_type, transport: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -752,7 +1172,7 @@ def test_search_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -769,7 +1189,7 @@ async def test_search_async( transport: str = "grpc_asyncio", request_type=search_service.SearchRequest ): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -812,7 +1232,7 @@ async def test_search_async_from_dict(): def test_search_field_headers(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -842,7 +1262,7 @@ def test_search_field_headers(): @pytest.mark.asyncio async def test_search_field_headers_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -873,7 +1293,7 @@ async def test_search_field_headers_async(): def test_search_pager(transport_name: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -925,7 +1345,7 @@ def test_search_pager(transport_name: str = "grpc"): def test_search_pages(transport_name: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -967,7 +1387,7 @@ def test_search_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_search_async_pager(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1019,7 +1439,7 @@ async def test_search_async_pager(): @pytest.mark.asyncio async def test_search_async_pages(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1072,7 +1492,7 @@ async def test_search_async_pages(): ) def test_search_rest(request_type): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1131,7 +1551,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1140,7 +1560,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): jsonified_request["servingConfig"] = "serving_config_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1149,7 +1569,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): assert jsonified_request["servingConfig"] == "serving_config_value" client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1192,7 +1612,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): def test_search_rest_unset_required_fields(): transport = transports.SearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search._get_unset_required_fields({}) @@ -1202,7 +1622,7 @@ def test_search_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_rest_interceptors(null_interceptor): transport = transports.SearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SearchServiceRestInterceptor(), @@ -1258,7 +1678,7 @@ def test_search_rest_bad_request( transport: str = "rest", request_type=search_service.SearchRequest ): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1282,7 +1702,7 @@ def test_search_rest_bad_request( def test_search_rest_pager(transport: str = "rest"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1348,17 +1768,17 @@ def test_search_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchServiceClient( @@ -1368,7 +1788,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1379,16 +1799,17 @@ 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 = SearchServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchServiceClient( @@ -1400,7 +1821,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SearchServiceClient(transport=transport) assert client.transport is transport @@ -1409,13 +1830,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SearchServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1432,7 +1853,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1446,7 +1867,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SearchServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1454,7 +1875,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1466,7 +1887,7 @@ def test_search_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1478,7 +1899,7 @@ def test_search_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1512,7 +1933,7 @@ def test_search_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SearchServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1531,7 +1952,7 @@ def test_search_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SearchServiceTransport() adc.assert_called_once() @@ -1539,7 +1960,7 @@ def test_search_service_base_transport_with_adc(): def test_search_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SearchServiceClient() adc.assert_called_once_with( scopes=None, @@ -1559,7 +1980,7 @@ def test_search_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1606,7 +2027,7 @@ def test_search_service_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1634,7 +2055,7 @@ def test_search_service_transport_create_channel(transport_class, grpc_helpers): ], ) def test_search_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1672,7 +2093,7 @@ def test_search_service_grpc_transport_client_cert_source_for_mtls(transport_cla def test_search_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1692,7 +2113,7 @@ def test_search_service_http_transport_client_cert_source_for_mtls(): ) def test_search_service_host_no_port(transport_name): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -1715,7 +2136,7 @@ def test_search_service_host_no_port(transport_name): ) def test_search_service_host_with_port(transport_name): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -1735,8 +2156,8 @@ def test_search_service_host_with_port(transport_name): ], ) def test_search_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SearchServiceClient( credentials=creds1, transport=transport_name, @@ -1798,7 +2219,7 @@ def test_search_service_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2078,7 +2499,7 @@ def test_client_with_default_client_info(): transports.SearchServiceTransport, "_prep_wrapped_messages" ) as prep: client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2088,7 +2509,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SearchServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2097,7 +2518,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2112,7 +2533,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2142,7 +2563,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2170,7 +2591,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2198,7 +2619,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2224,7 +2645,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2249,7 +2670,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2275,7 +2696,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2304,7 +2725,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2333,7 +2754,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2351,7 +2772,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2369,7 +2790,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2394,7 +2815,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2420,7 +2841,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2449,7 +2870,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2478,7 +2899,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2496,7 +2917,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2520,7 +2941,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2537,7 +2958,7 @@ def test_client_ctx(): ] for transport in transports: client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2568,7 +2989,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_event_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_event_service.py index e43fbad0c07c..58f2b1bdc5c3 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_event_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1/test_user_event_service.py @@ -36,7 +36,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -86,6 +86,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -116,6 +139,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert UserEventServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert UserEventServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert UserEventServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + UserEventServiceClient._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 UserEventServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert UserEventServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert UserEventServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + UserEventServiceClient._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 UserEventServiceClient._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 UserEventServiceClient._get_client_cert_source(None, False) is None + assert ( + UserEventServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + UserEventServiceClient._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 ( + UserEventServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + UserEventServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + UserEventServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), +) +@mock.patch.object( + UserEventServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = UserEventServiceClient._DEFAULT_UNIVERSE + default_endpoint = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + UserEventServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + UserEventServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, default_universe, "always") + == UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + UserEventServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + UserEventServiceClient._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 ( + UserEventServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + UserEventServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + UserEventServiceClient._get_universe_domain(None, None) + == UserEventServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + UserEventServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (UserEventServiceClient, transports.UserEventServiceGrpcTransport, "grpc"), + (UserEventServiceClient, transports.UserEventServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -127,7 +411,7 @@ def test__get_default_mtls_endpoint(): def test_user_event_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -181,7 +465,7 @@ def test_user_event_service_client_service_account_always_use_jwt( def test_user_event_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -231,20 +515,22 @@ def test_user_event_service_client_get_transport_class(): ) @mock.patch.object( UserEventServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), ) @mock.patch.object( UserEventServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), ) def test_user_event_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(UserEventServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -279,7 +565,9 @@ def test_user_event_service_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, @@ -309,15 +597,23 @@ def test_user_event_service_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") @@ -327,7 +623,9 @@ def test_user_event_service_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", @@ -345,7 +643,9 @@ def test_user_event_service_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, @@ -398,13 +698,13 @@ def test_user_event_service_client_client_options( ) @mock.patch.object( UserEventServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), ) @mock.patch.object( UserEventServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_user_event_service_client_mtls_env_auto( @@ -427,7 +727,9 @@ def test_user_event_service_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 @@ -459,7 +761,9 @@ def test_user_event_service_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 @@ -493,7 +797,9 @@ def test_user_event_service_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, @@ -583,6 +889,118 @@ def test_user_event_service_client_get_mtls_endpoint_and_cert_source(client_clas 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", [UserEventServiceClient, UserEventServiceAsyncClient] +) +@mock.patch.object( + UserEventServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), +) +@mock.patch.object( + UserEventServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), +) +def test_user_event_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = UserEventServiceClient._DEFAULT_UNIVERSE + default_endpoint = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = UserEventServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -609,7 +1027,9 @@ def test_user_event_service_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, @@ -654,7 +1074,9 @@ def test_user_event_service_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, @@ -714,7 +1136,9 @@ def test_user_event_service_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, @@ -731,8 +1155,8 @@ def test_user_event_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -761,7 +1185,7 @@ def test_user_event_service_client_create_channel_credentials_file( ) def test_write_user_event(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -805,7 +1229,7 @@ def test_write_user_event_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -823,7 +1247,7 @@ async def test_write_user_event_async( request_type=user_event_service.WriteUserEventRequest, ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -872,7 +1296,7 @@ async def test_write_user_event_async_from_dict(): def test_write_user_event_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -902,7 +1326,7 @@ def test_write_user_event_field_headers(): @pytest.mark.asyncio async def test_write_user_event_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -940,7 +1364,7 @@ async def test_write_user_event_field_headers_async(): ) def test_collect_user_event(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -974,7 +1398,7 @@ def test_collect_user_event_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -994,7 +1418,7 @@ async def test_collect_user_event_async( request_type=user_event_service.CollectUserEventRequest, ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1033,7 +1457,7 @@ async def test_collect_user_event_async_from_dict(): def test_collect_user_event_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1065,7 +1489,7 @@ def test_collect_user_event_field_headers(): @pytest.mark.asyncio async def test_collect_user_event_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1105,7 +1529,7 @@ async def test_collect_user_event_field_headers_async(): ) def test_import_user_events(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1134,7 +1558,7 @@ def test_import_user_events_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1153,7 +1577,7 @@ async def test_import_user_events_async( transport: str = "grpc_asyncio", request_type=import_config.ImportUserEventsRequest ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1187,7 +1611,7 @@ async def test_import_user_events_async_from_dict(): def test_import_user_events_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1219,7 +1643,7 @@ def test_import_user_events_field_headers(): @pytest.mark.asyncio async def test_import_user_events_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1259,7 +1683,7 @@ async def test_import_user_events_field_headers_async(): ) def test_write_user_event_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1446,7 +1870,7 @@ def test_write_user_event_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).write_user_event._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1455,7 +1879,7 @@ def test_write_user_event_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).write_user_event._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1464,7 +1888,7 @@ def test_write_user_event_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1507,7 +1931,7 @@ def test_write_user_event_rest_required_fields( def test_write_user_event_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.write_user_event._get_unset_required_fields({}) @@ -1525,7 +1949,7 @@ def test_write_user_event_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_write_user_event_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -1581,7 +2005,7 @@ def test_write_user_event_rest_bad_request( transport: str = "rest", request_type=user_event_service.WriteUserEventRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1603,7 +2027,7 @@ def test_write_user_event_rest_bad_request( def test_write_user_event_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -1616,7 +2040,7 @@ def test_write_user_event_rest_error(): ) def test_collect_user_event_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1669,7 +2093,7 @@ def test_collect_user_event_rest_required_fields( assert "userEvent" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).collect_user_event._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1681,7 +2105,7 @@ def test_collect_user_event_rest_required_fields( jsonified_request["userEvent"] = "user_event_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).collect_user_event._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -1700,7 +2124,7 @@ def test_collect_user_event_rest_required_fields( assert jsonified_request["userEvent"] == "user_event_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1746,7 +2170,7 @@ def test_collect_user_event_rest_required_fields( def test_collect_user_event_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.collect_user_event._get_unset_required_fields({}) @@ -1770,7 +2194,7 @@ def test_collect_user_event_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_collect_user_event_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -1826,7 +2250,7 @@ def test_collect_user_event_rest_bad_request( transport: str = "rest", request_type=user_event_service.CollectUserEventRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1848,7 +2272,7 @@ def test_collect_user_event_rest_bad_request( def test_collect_user_event_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -1861,7 +2285,7 @@ def test_collect_user_event_rest_error(): ) def test_import_user_events_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1907,7 +2331,7 @@ def test_import_user_events_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_user_events._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1916,7 +2340,7 @@ def test_import_user_events_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_user_events._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1925,7 +2349,7 @@ def test_import_user_events_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1965,7 +2389,7 @@ def test_import_user_events_rest_required_fields( def test_import_user_events_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_user_events._get_unset_required_fields({}) @@ -1975,7 +2399,7 @@ def test_import_user_events_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_user_events_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -2035,7 +2459,7 @@ def test_import_user_events_rest_bad_request( transport: str = "rest", request_type=import_config.ImportUserEventsRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2057,24 +2481,24 @@ def test_import_user_events_rest_bad_request( def test_import_user_events_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = UserEventServiceClient( @@ -2084,7 +2508,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -2095,16 +2519,17 @@ 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 = UserEventServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = UserEventServiceClient( @@ -2116,7 +2541,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = UserEventServiceClient(transport=transport) assert client.transport is transport @@ -2125,13 +2550,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.UserEventServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -2148,7 +2573,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -2162,7 +2587,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = UserEventServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -2170,7 +2595,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -2182,7 +2607,7 @@ def test_user_event_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.UserEventServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -2194,7 +2619,7 @@ def test_user_event_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.UserEventServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -2235,7 +2660,7 @@ def test_user_event_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.UserEventServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2254,7 +2679,7 @@ def test_user_event_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.UserEventServiceTransport() adc.assert_called_once() @@ -2262,7 +2687,7 @@ def test_user_event_service_base_transport_with_adc(): def test_user_event_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) UserEventServiceClient() adc.assert_called_once_with( scopes=None, @@ -2282,7 +2707,7 @@ def test_user_event_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2329,7 +2754,7 @@ def test_user_event_service_transport_create_channel(transport_class, grpc_helpe ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2357,7 +2782,7 @@ def test_user_event_service_transport_create_channel(transport_class, grpc_helpe ], ) def test_user_event_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2395,7 +2820,7 @@ def test_user_event_service_grpc_transport_client_cert_source_for_mtls(transport def test_user_event_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -2407,7 +2832,7 @@ def test_user_event_service_http_transport_client_cert_source_for_mtls(): def test_user_event_service_rest_lro_client(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -2432,7 +2857,7 @@ def test_user_event_service_rest_lro_client(): ) def test_user_event_service_host_no_port(transport_name): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -2455,7 +2880,7 @@ def test_user_event_service_host_no_port(transport_name): ) def test_user_event_service_host_with_port(transport_name): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -2475,8 +2900,8 @@ def test_user_event_service_host_with_port(transport_name): ], ) def test_user_event_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = UserEventServiceClient( credentials=creds1, transport=transport_name, @@ -2546,7 +2971,7 @@ def test_user_event_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2624,7 +3049,7 @@ def test_user_event_service_transport_channel_mtls_with_adc(transport_class): def test_user_event_service_grpc_lro_client(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -2641,7 +3066,7 @@ def test_user_event_service_grpc_lro_client(): def test_user_event_service_grpc_lro_async_client(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -2826,7 +3251,7 @@ def test_client_with_default_client_info(): transports.UserEventServiceTransport, "_prep_wrapped_messages" ) as prep: client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2836,7 +3261,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = UserEventServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2845,7 +3270,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2860,7 +3285,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2890,7 +3315,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -2918,7 +3343,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2946,7 +3371,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -2972,7 +3397,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2997,7 +3422,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3023,7 +3448,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3052,7 +3477,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3081,7 +3506,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3099,7 +3524,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3117,7 +3542,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3142,7 +3567,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3168,7 +3593,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3197,7 +3622,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3226,7 +3651,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3244,7 +3669,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3268,7 +3693,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3285,7 +3710,7 @@ def test_client_ctx(): ] for transport in transports: client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3316,7 +3741,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_completion_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_completion_service.py index 7b1a3a4ccd98..a4673b9f1258 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_completion_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_completion_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -67,6 +67,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -97,6 +120,275 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert CompletionServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + CompletionServiceClient._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 CompletionServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + CompletionServiceClient._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 CompletionServiceClient._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 CompletionServiceClient._get_client_cert_source(None, False) is None + assert ( + CompletionServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + CompletionServiceClient._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 ( + CompletionServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + CompletionServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + CompletionServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), +) +@mock.patch.object( + CompletionServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = CompletionServiceClient._DEFAULT_UNIVERSE + default_endpoint = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + CompletionServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + CompletionServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CompletionServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + CompletionServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CompletionServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CompletionServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + CompletionServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + CompletionServiceClient._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 ( + CompletionServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + CompletionServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + CompletionServiceClient._get_universe_domain(None, None) + == CompletionServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + CompletionServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (CompletionServiceClient, transports.CompletionServiceGrpcTransport, "grpc"), + (CompletionServiceClient, transports.CompletionServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -108,7 +400,7 @@ def test__get_default_mtls_endpoint(): def test_completion_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -162,7 +454,7 @@ def test_completion_service_client_service_account_always_use_jwt( def test_completion_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -212,20 +504,22 @@ def test_completion_service_client_get_transport_class(): ) @mock.patch.object( CompletionServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), ) @mock.patch.object( CompletionServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), ) def test_completion_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CompletionServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -260,7 +554,9 @@ def test_completion_service_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, @@ -290,15 +586,23 @@ def test_completion_service_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") @@ -308,7 +612,9 @@ def test_completion_service_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", @@ -326,7 +632,9 @@ def test_completion_service_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, @@ -379,13 +687,13 @@ def test_completion_service_client_client_options( ) @mock.patch.object( CompletionServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), ) @mock.patch.object( CompletionServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_completion_service_client_mtls_env_auto( @@ -408,7 +716,9 @@ def test_completion_service_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 @@ -440,7 +750,9 @@ def test_completion_service_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 @@ -474,7 +786,9 @@ def test_completion_service_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, @@ -564,6 +878,118 @@ def test_completion_service_client_get_mtls_endpoint_and_cert_source(client_clas 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", [CompletionServiceClient, CompletionServiceAsyncClient] +) +@mock.patch.object( + CompletionServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), +) +@mock.patch.object( + CompletionServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), +) +def test_completion_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = CompletionServiceClient._DEFAULT_UNIVERSE + default_endpoint = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CompletionServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -590,7 +1016,9 @@ def test_completion_service_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, @@ -635,7 +1063,9 @@ def test_completion_service_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, @@ -695,7 +1125,9 @@ def test_completion_service_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, @@ -712,8 +1144,8 @@ def test_completion_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -742,7 +1174,7 @@ def test_completion_service_client_create_channel_credentials_file( ) def test_complete_query(request_type, transport: str = "grpc"): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -772,7 +1204,7 @@ def test_complete_query_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -790,7 +1222,7 @@ async def test_complete_query_async( request_type=completion_service.CompleteQueryRequest, ): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -825,7 +1257,7 @@ async def test_complete_query_async_from_dict(): def test_complete_query_field_headers(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -855,7 +1287,7 @@ def test_complete_query_field_headers(): @pytest.mark.asyncio async def test_complete_query_field_headers_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -893,7 +1325,7 @@ async def test_complete_query_field_headers_async(): ) def test_complete_query_rest(request_type): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -948,7 +1380,7 @@ def test_complete_query_rest_required_fields( assert "query" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_query._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -960,7 +1392,7 @@ def test_complete_query_rest_required_fields( jsonified_request["query"] = "query_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_query._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -980,7 +1412,7 @@ def test_complete_query_rest_required_fields( assert jsonified_request["query"] == "query_value" client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1028,7 +1460,7 @@ def test_complete_query_rest_required_fields( def test_complete_query_rest_unset_required_fields(): transport = transports.CompletionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.complete_query._get_unset_required_fields({}) @@ -1053,7 +1485,7 @@ def test_complete_query_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_complete_query_rest_interceptors(null_interceptor): transport = transports.CompletionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CompletionServiceRestInterceptor(), @@ -1111,7 +1543,7 @@ def test_complete_query_rest_bad_request( transport: str = "rest", request_type=completion_service.CompleteQueryRequest ): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1135,24 +1567,24 @@ def test_complete_query_rest_bad_request( def test_complete_query_rest_error(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CompletionServiceClient( @@ -1162,7 +1594,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1173,16 +1605,17 @@ 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 = CompletionServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CompletionServiceClient( @@ -1194,7 +1627,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = CompletionServiceClient(transport=transport) assert client.transport is transport @@ -1203,13 +1636,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.CompletionServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1226,7 +1659,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1240,7 +1673,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = CompletionServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1248,7 +1681,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1260,7 +1693,7 @@ def test_completion_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.CompletionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1272,7 +1705,7 @@ def test_completion_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CompletionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1306,7 +1739,7 @@ def test_completion_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CompletionServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1325,7 +1758,7 @@ def test_completion_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CompletionServiceTransport() adc.assert_called_once() @@ -1333,7 +1766,7 @@ def test_completion_service_base_transport_with_adc(): def test_completion_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) CompletionServiceClient() adc.assert_called_once_with( scopes=None, @@ -1353,7 +1786,7 @@ def test_completion_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1400,7 +1833,7 @@ def test_completion_service_transport_create_channel(transport_class, grpc_helpe ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1428,7 +1861,7 @@ def test_completion_service_transport_create_channel(transport_class, grpc_helpe ], ) def test_completion_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1466,7 +1899,7 @@ def test_completion_service_grpc_transport_client_cert_source_for_mtls(transport def test_completion_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1486,7 +1919,7 @@ def test_completion_service_http_transport_client_cert_source_for_mtls(): ) def test_completion_service_host_no_port(transport_name): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -1509,7 +1942,7 @@ def test_completion_service_host_no_port(transport_name): ) def test_completion_service_host_with_port(transport_name): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -1529,8 +1962,8 @@ def test_completion_service_host_with_port(transport_name): ], ) def test_completion_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = CompletionServiceClient( credentials=creds1, transport=transport_name, @@ -1594,7 +2027,7 @@ def test_completion_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -1806,7 +2239,7 @@ def test_client_with_default_client_info(): transports.CompletionServiceTransport, "_prep_wrapped_messages" ) as prep: client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1816,7 +2249,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = CompletionServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1825,7 +2258,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -1840,7 +2273,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1873,7 +2306,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -1903,7 +2336,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1936,7 +2369,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -1964,7 +2397,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1989,7 +2422,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2015,7 +2448,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2044,7 +2477,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2073,7 +2506,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2091,7 +2524,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2109,7 +2542,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2134,7 +2567,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2160,7 +2593,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2189,7 +2622,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2218,7 +2651,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2236,7 +2669,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2260,7 +2693,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2277,7 +2710,7 @@ def test_client_ctx(): ] for transport in transports: client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2311,7 +2744,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_conversational_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_conversational_search_service.py index f81db6e0b84f..0ce7b85cbda9 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_conversational_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_conversational_search_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -75,6 +75,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -107,6 +130,297 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ConversationalSearchServiceClient._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 ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationalSearchServiceClient._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 ConversationalSearchServiceClient._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 ( + ConversationalSearchServiceClient._get_client_cert_source(None, False) is None + ) + assert ( + ConversationalSearchServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + ConversationalSearchServiceClient._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 ( + ConversationalSearchServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ConversationalSearchServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ConversationalSearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), +) +@mock.patch.object( + ConversationalSearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ConversationalSearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationalSearchServiceClient._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 ( + ConversationalSearchServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ConversationalSearchServiceClient._get_universe_domain( + None, universe_domain_env + ) + == universe_domain_env + ) + assert ( + ConversationalSearchServiceClient._get_universe_domain(None, None) + == ConversationalSearchServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ConversationalSearchServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + ConversationalSearchServiceClient, + transports.ConversationalSearchServiceGrpcTransport, + "grpc", + ), + ( + ConversationalSearchServiceClient, + transports.ConversationalSearchServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -118,7 +432,7 @@ def test__get_default_mtls_endpoint(): def test_conversational_search_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -172,7 +486,7 @@ def test_conversational_search_service_client_service_account_always_use_jwt( def test_conversational_search_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -230,13 +544,13 @@ def test_conversational_search_service_client_get_transport_class(): ) @mock.patch.object( ConversationalSearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), ) @mock.patch.object( ConversationalSearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), ) def test_conversational_search_service_client_client_options( client_class, transport_class, transport_name @@ -245,7 +559,9 @@ def test_conversational_search_service_client_client_options( with mock.patch.object( ConversationalSearchServiceClient, "get_transport_class" ) as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -282,7 +598,9 @@ def test_conversational_search_service_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, @@ -312,15 +630,23 @@ def test_conversational_search_service_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") @@ -330,7 +656,9 @@ def test_conversational_search_service_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", @@ -348,7 +676,9 @@ def test_conversational_search_service_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, @@ -401,13 +731,13 @@ def test_conversational_search_service_client_client_options( ) @mock.patch.object( ConversationalSearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), ) @mock.patch.object( ConversationalSearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_conversational_search_service_client_mtls_env_auto( @@ -430,7 +760,9 @@ def test_conversational_search_service_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 @@ -462,7 +794,9 @@ def test_conversational_search_service_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 @@ -496,7 +830,9 @@ def test_conversational_search_service_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, @@ -589,6 +925,121 @@ def test_conversational_search_service_client_get_mtls_endpoint_and_cert_source( 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", + [ConversationalSearchServiceClient, ConversationalSearchServiceAsyncClient], +) +@mock.patch.object( + ConversationalSearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), +) +@mock.patch.object( + ConversationalSearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), +) +def test_conversational_search_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ConversationalSearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ConversationalSearchServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -623,7 +1074,9 @@ def test_conversational_search_service_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, @@ -668,7 +1121,9 @@ def test_conversational_search_service_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, @@ -728,7 +1183,9 @@ def test_conversational_search_service_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, @@ -745,8 +1202,8 @@ def test_conversational_search_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -775,7 +1232,7 @@ def test_conversational_search_service_client_create_channel_credentials_file( ) def test_converse_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -809,7 +1266,7 @@ def test_converse_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -829,7 +1286,7 @@ async def test_converse_conversation_async( request_type=conversational_search_service.ConverseConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -868,7 +1325,7 @@ async def test_converse_conversation_async_from_dict(): def test_converse_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -900,7 +1357,7 @@ def test_converse_conversation_field_headers(): @pytest.mark.asyncio async def test_converse_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -933,7 +1390,7 @@ async def test_converse_conversation_field_headers_async(): def test_converse_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -963,7 +1420,7 @@ def test_converse_conversation_flattened(): def test_converse_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -979,7 +1436,7 @@ def test_converse_conversation_flattened_error(): @pytest.mark.asyncio async def test_converse_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1014,7 +1471,7 @@ async def test_converse_conversation_flattened_async(): @pytest.mark.asyncio async def test_converse_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1036,7 +1493,7 @@ async def test_converse_conversation_flattened_error_async(): ) def test_create_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1072,7 +1529,7 @@ def test_create_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1092,7 +1549,7 @@ async def test_create_conversation_async( request_type=conversational_search_service.CreateConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1133,7 +1590,7 @@ async def test_create_conversation_async_from_dict(): def test_create_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1165,7 +1622,7 @@ def test_create_conversation_field_headers(): @pytest.mark.asyncio async def test_create_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1198,7 +1655,7 @@ async def test_create_conversation_field_headers_async(): def test_create_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1228,7 +1685,7 @@ def test_create_conversation_flattened(): def test_create_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1244,7 +1701,7 @@ def test_create_conversation_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1279,7 +1736,7 @@ async def test_create_conversation_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1301,7 +1758,7 @@ async def test_create_conversation_flattened_error_async(): ) def test_delete_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1330,7 +1787,7 @@ def test_delete_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1350,7 +1807,7 @@ async def test_delete_conversation_async( request_type=conversational_search_service.DeleteConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1382,7 +1839,7 @@ async def test_delete_conversation_async_from_dict(): def test_delete_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1414,7 +1871,7 @@ def test_delete_conversation_field_headers(): @pytest.mark.asyncio async def test_delete_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1445,7 +1902,7 @@ async def test_delete_conversation_field_headers_async(): def test_delete_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1471,7 +1928,7 @@ def test_delete_conversation_flattened(): def test_delete_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1486,7 +1943,7 @@ def test_delete_conversation_flattened_error(): @pytest.mark.asyncio async def test_delete_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1515,7 +1972,7 @@ async def test_delete_conversation_flattened_async(): @pytest.mark.asyncio async def test_delete_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1536,7 +1993,7 @@ async def test_delete_conversation_flattened_error_async(): ) def test_update_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1572,7 +2029,7 @@ def test_update_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1592,7 +2049,7 @@ async def test_update_conversation_async( request_type=conversational_search_service.UpdateConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1633,7 +2090,7 @@ async def test_update_conversation_async_from_dict(): def test_update_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1665,7 +2122,7 @@ def test_update_conversation_field_headers(): @pytest.mark.asyncio async def test_update_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1698,7 +2155,7 @@ async def test_update_conversation_field_headers_async(): def test_update_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1728,7 +2185,7 @@ def test_update_conversation_flattened(): def test_update_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1744,7 +2201,7 @@ def test_update_conversation_flattened_error(): @pytest.mark.asyncio async def test_update_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1779,7 +2236,7 @@ async def test_update_conversation_flattened_async(): @pytest.mark.asyncio async def test_update_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1801,7 +2258,7 @@ async def test_update_conversation_flattened_error_async(): ) def test_get_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1835,7 +2292,7 @@ def test_get_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1853,7 +2310,7 @@ async def test_get_conversation_async( request_type=conversational_search_service.GetConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1892,7 +2349,7 @@ async def test_get_conversation_async_from_dict(): def test_get_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1922,7 +2379,7 @@ def test_get_conversation_field_headers(): @pytest.mark.asyncio async def test_get_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1953,7 +2410,7 @@ async def test_get_conversation_field_headers_async(): def test_get_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1977,7 +2434,7 @@ def test_get_conversation_flattened(): def test_get_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1992,7 +2449,7 @@ def test_get_conversation_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2021,7 +2478,7 @@ async def test_get_conversation_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2042,7 +2499,7 @@ async def test_get_conversation_flattened_error_async(): ) def test_list_conversations(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2074,7 +2531,7 @@ def test_list_conversations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2094,7 +2551,7 @@ async def test_list_conversations_async( request_type=conversational_search_service.ListConversationsRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2131,7 +2588,7 @@ async def test_list_conversations_async_from_dict(): def test_list_conversations_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2163,7 +2620,7 @@ def test_list_conversations_field_headers(): @pytest.mark.asyncio async def test_list_conversations_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2196,7 +2653,7 @@ async def test_list_conversations_field_headers_async(): def test_list_conversations_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2222,7 +2679,7 @@ def test_list_conversations_flattened(): def test_list_conversations_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2237,7 +2694,7 @@ def test_list_conversations_flattened_error(): @pytest.mark.asyncio async def test_list_conversations_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2268,7 +2725,7 @@ async def test_list_conversations_flattened_async(): @pytest.mark.asyncio async def test_list_conversations_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2282,7 +2739,7 @@ async def test_list_conversations_flattened_error_async(): def test_list_conversations_pager(transport_name: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2334,7 +2791,7 @@ def test_list_conversations_pager(transport_name: str = "grpc"): def test_list_conversations_pages(transport_name: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2378,7 +2835,7 @@ def test_list_conversations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversations_async_pager(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2430,7 +2887,7 @@ async def test_list_conversations_async_pager(): @pytest.mark.asyncio async def test_list_conversations_async_pages(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2487,7 +2944,7 @@ async def test_list_conversations_async_pages(): ) def test_converse_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2544,7 +3001,7 @@ def test_converse_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).converse_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2553,7 +3010,7 @@ def test_converse_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).converse_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2562,7 +3019,7 @@ def test_converse_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2609,7 +3066,7 @@ def test_converse_conversation_rest_required_fields( def test_converse_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.converse_conversation._get_unset_required_fields({}) @@ -2627,7 +3084,7 @@ def test_converse_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_converse_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -2690,7 +3147,7 @@ def test_converse_conversation_rest_bad_request( request_type=conversational_search_service.ConverseConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2714,7 +3171,7 @@ def test_converse_conversation_rest_bad_request( def test_converse_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2761,7 +3218,7 @@ def test_converse_conversation_rest_flattened(): def test_converse_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2777,7 +3234,7 @@ def test_converse_conversation_rest_flattened_error(transport: str = "rest"): def test_converse_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2790,7 +3247,7 @@ def test_converse_conversation_rest_error(): ) def test_create_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2974,7 +3431,7 @@ def test_create_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2983,7 +3440,7 @@ def test_create_conversation_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2992,7 +3449,7 @@ def test_create_conversation_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3035,7 +3492,7 @@ def test_create_conversation_rest_required_fields( def test_create_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_conversation._get_unset_required_fields({}) @@ -3053,7 +3510,7 @@ def test_create_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -3113,7 +3570,7 @@ def test_create_conversation_rest_bad_request( request_type=conversational_search_service.CreateConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3135,7 +3592,7 @@ def test_create_conversation_rest_bad_request( def test_create_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3180,7 +3637,7 @@ def test_create_conversation_rest_flattened(): def test_create_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3196,7 +3653,7 @@ def test_create_conversation_rest_flattened_error(transport: str = "rest"): def test_create_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3209,7 +3666,7 @@ def test_create_conversation_rest_error(): ) def test_delete_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3257,7 +3714,7 @@ def test_delete_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3266,7 +3723,7 @@ def test_delete_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3275,7 +3732,7 @@ def test_delete_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3314,7 +3771,7 @@ def test_delete_conversation_rest_required_fields( def test_delete_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_conversation._get_unset_required_fields({}) @@ -3324,7 +3781,7 @@ def test_delete_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -3375,7 +3832,7 @@ def test_delete_conversation_rest_bad_request( request_type=conversational_search_service.DeleteConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3399,7 +3856,7 @@ def test_delete_conversation_rest_bad_request( def test_delete_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3441,7 +3898,7 @@ def test_delete_conversation_rest_flattened(): def test_delete_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3456,7 +3913,7 @@ def test_delete_conversation_rest_flattened_error(transport: str = "rest"): def test_delete_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3469,7 +3926,7 @@ def test_delete_conversation_rest_error(): ) def test_update_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3656,14 +4113,14 @@ def test_update_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3672,7 +4129,7 @@ def test_update_conversation_rest_required_fields( # verify required fields with non-default values are left alone client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3715,7 +4172,7 @@ def test_update_conversation_rest_required_fields( def test_update_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_conversation._get_unset_required_fields({}) @@ -3725,7 +4182,7 @@ def test_update_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -3785,7 +4242,7 @@ def test_update_conversation_rest_bad_request( request_type=conversational_search_service.UpdateConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3811,7 +4268,7 @@ def test_update_conversation_rest_bad_request( def test_update_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3858,7 +4315,7 @@ def test_update_conversation_rest_flattened(): def test_update_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3874,7 +4331,7 @@ def test_update_conversation_rest_flattened_error(transport: str = "rest"): def test_update_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3887,7 +4344,7 @@ def test_update_conversation_rest_error(): ) def test_get_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3944,7 +4401,7 @@ def test_get_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3953,7 +4410,7 @@ def test_get_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3962,7 +4419,7 @@ def test_get_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4004,7 +4461,7 @@ def test_get_conversation_rest_required_fields( def test_get_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_conversation._get_unset_required_fields({}) @@ -4014,7 +4471,7 @@ def test_get_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -4073,7 +4530,7 @@ def test_get_conversation_rest_bad_request( request_type=conversational_search_service.GetConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4097,7 +4554,7 @@ def test_get_conversation_rest_bad_request( def test_get_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4141,7 +4598,7 @@ def test_get_conversation_rest_flattened(): def test_get_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4156,7 +4613,7 @@ def test_get_conversation_rest_flattened_error(transport: str = "rest"): def test_get_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4169,7 +4626,7 @@ def test_get_conversation_rest_error(): ) def test_list_conversations_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4222,7 +4679,7 @@ def test_list_conversations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4231,7 +4688,7 @@ def test_list_conversations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4249,7 +4706,7 @@ def test_list_conversations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4293,7 +4750,7 @@ def test_list_conversations_rest_required_fields( def test_list_conversations_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_conversations._get_unset_required_fields({}) @@ -4313,7 +4770,7 @@ def test_list_conversations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversations_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -4374,7 +4831,7 @@ def test_list_conversations_rest_bad_request( request_type=conversational_search_service.ListConversationsRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4396,7 +4853,7 @@ def test_list_conversations_rest_bad_request( def test_list_conversations_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4442,7 +4899,7 @@ def test_list_conversations_rest_flattened(): def test_list_conversations_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4457,7 +4914,7 @@ def test_list_conversations_rest_flattened_error(transport: str = "rest"): def test_list_conversations_rest_pager(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4524,17 +4981,17 @@ def test_list_conversations_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationalSearchServiceClient( @@ -4544,7 +5001,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4555,16 +5012,17 @@ 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 = ConversationalSearchServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationalSearchServiceClient( @@ -4576,7 +5034,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ConversationalSearchServiceClient(transport=transport) assert client.transport is transport @@ -4585,13 +5043,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ConversationalSearchServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4608,7 +5066,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4622,7 +5080,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ConversationalSearchServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4630,7 +5088,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4642,7 +5100,7 @@ def test_conversational_search_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ConversationalSearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4654,7 +5112,7 @@ def test_conversational_search_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConversationalSearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4693,7 +5151,7 @@ def test_conversational_search_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationalSearchServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4712,7 +5170,7 @@ def test_conversational_search_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationalSearchServiceTransport() adc.assert_called_once() @@ -4720,7 +5178,7 @@ def test_conversational_search_service_base_transport_with_adc(): def test_conversational_search_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ConversationalSearchServiceClient() adc.assert_called_once_with( scopes=None, @@ -4740,7 +5198,7 @@ def test_conversational_search_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4792,7 +5250,7 @@ def test_conversational_search_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4822,7 +5280,7 @@ def test_conversational_search_service_transport_create_channel( def test_conversational_search_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4860,7 +5318,7 @@ def test_conversational_search_service_grpc_transport_client_cert_source_for_mtl def test_conversational_search_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4880,7 +5338,7 @@ def test_conversational_search_service_http_transport_client_cert_source_for_mtl ) def test_conversational_search_service_host_no_port(transport_name): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -4903,7 +5361,7 @@ def test_conversational_search_service_host_no_port(transport_name): ) def test_conversational_search_service_host_with_port(transport_name): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4925,8 +5383,8 @@ def test_conversational_search_service_host_with_port(transport_name): def test_conversational_search_service_client_transport_session_collision( transport_name, ): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ConversationalSearchServiceClient( credentials=creds1, transport=transport_name, @@ -5005,7 +5463,7 @@ def test_conversational_search_service_transport_channel_mtls_with_client_cert_s mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5317,7 +5775,7 @@ def test_client_with_default_client_info(): transports.ConversationalSearchServiceTransport, "_prep_wrapped_messages" ) as prep: client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5327,7 +5785,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ConversationalSearchServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5336,7 +5794,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5351,7 +5809,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5384,7 +5842,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -5414,7 +5872,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5447,7 +5905,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -5475,7 +5933,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5500,7 +5958,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5526,7 +5984,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5555,7 +6013,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5584,7 +6042,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5602,7 +6060,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5620,7 +6078,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5645,7 +6103,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5671,7 +6129,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5700,7 +6158,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5729,7 +6187,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5747,7 +6205,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5771,7 +6229,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5788,7 +6246,7 @@ def test_client_ctx(): ] for transport in transports: client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5825,7 +6283,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_data_store_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_data_store_service.py index a2c255b71a24..90e81354d144 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_data_store_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_data_store_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -83,6 +83,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -113,6 +136,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert DataStoreServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DataStoreServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DataStoreServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DataStoreServiceClient._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 DataStoreServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DataStoreServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DataStoreServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DataStoreServiceClient._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 DataStoreServiceClient._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 DataStoreServiceClient._get_client_cert_source(None, False) is None + assert ( + DataStoreServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + DataStoreServiceClient._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 ( + DataStoreServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DataStoreServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DataStoreServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataStoreServiceClient), +) +@mock.patch.object( + DataStoreServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataStoreServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DataStoreServiceClient._DEFAULT_UNIVERSE + default_endpoint = DataStoreServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DataStoreServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DataStoreServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DataStoreServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DataStoreServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DataStoreServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DataStoreServiceClient._get_api_endpoint(None, None, default_universe, "always") + == DataStoreServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DataStoreServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DataStoreServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DataStoreServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DataStoreServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DataStoreServiceClient._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 ( + DataStoreServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DataStoreServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DataStoreServiceClient._get_universe_domain(None, None) + == DataStoreServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DataStoreServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DataStoreServiceClient, transports.DataStoreServiceGrpcTransport, "grpc"), + (DataStoreServiceClient, transports.DataStoreServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -124,7 +408,7 @@ def test__get_default_mtls_endpoint(): def test_data_store_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -178,7 +462,7 @@ def test_data_store_service_client_service_account_always_use_jwt( def test_data_store_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -228,20 +512,22 @@ def test_data_store_service_client_get_transport_class(): ) @mock.patch.object( DataStoreServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DataStoreServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataStoreServiceClient), ) @mock.patch.object( DataStoreServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DataStoreServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataStoreServiceAsyncClient), ) def test_data_store_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(DataStoreServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -276,7 +562,9 @@ def test_data_store_service_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, @@ -306,15 +594,23 @@ def test_data_store_service_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") @@ -324,7 +620,9 @@ def test_data_store_service_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", @@ -342,7 +640,9 @@ def test_data_store_service_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, @@ -395,13 +695,13 @@ def test_data_store_service_client_client_options( ) @mock.patch.object( DataStoreServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DataStoreServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataStoreServiceClient), ) @mock.patch.object( DataStoreServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DataStoreServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataStoreServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_data_store_service_client_mtls_env_auto( @@ -424,7 +724,9 @@ def test_data_store_service_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 @@ -456,7 +758,9 @@ def test_data_store_service_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 @@ -490,7 +794,9 @@ def test_data_store_service_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, @@ -580,6 +886,118 @@ def test_data_store_service_client_get_mtls_endpoint_and_cert_source(client_clas 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", [DataStoreServiceClient, DataStoreServiceAsyncClient] +) +@mock.patch.object( + DataStoreServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataStoreServiceClient), +) +@mock.patch.object( + DataStoreServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataStoreServiceAsyncClient), +) +def test_data_store_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DataStoreServiceClient._DEFAULT_UNIVERSE + default_endpoint = DataStoreServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DataStoreServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -606,7 +1024,9 @@ def test_data_store_service_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, @@ -651,7 +1071,9 @@ def test_data_store_service_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, @@ -711,7 +1133,9 @@ def test_data_store_service_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, @@ -728,8 +1152,8 @@ def test_data_store_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -758,7 +1182,7 @@ def test_data_store_service_client_create_channel_credentials_file( ) def test_create_data_store(request_type, transport: str = "grpc"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -787,7 +1211,7 @@ def test_create_data_store_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -807,7 +1231,7 @@ async def test_create_data_store_async( request_type=data_store_service.CreateDataStoreRequest, ): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -841,7 +1265,7 @@ async def test_create_data_store_async_from_dict(): def test_create_data_store_field_headers(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -873,7 +1297,7 @@ def test_create_data_store_field_headers(): @pytest.mark.asyncio async def test_create_data_store_field_headers_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -906,7 +1330,7 @@ async def test_create_data_store_field_headers_async(): def test_create_data_store_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -940,7 +1364,7 @@ def test_create_data_store_flattened(): def test_create_data_store_flattened_error(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -957,7 +1381,7 @@ def test_create_data_store_flattened_error(): @pytest.mark.asyncio async def test_create_data_store_flattened_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -996,7 +1420,7 @@ async def test_create_data_store_flattened_async(): @pytest.mark.asyncio async def test_create_data_store_flattened_error_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1019,7 +1443,7 @@ async def test_create_data_store_flattened_error_async(): ) def test_get_data_store(request_type, transport: str = "grpc"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1059,7 +1483,7 @@ def test_get_data_store_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1076,7 +1500,7 @@ async def test_get_data_store_async( transport: str = "grpc_asyncio", request_type=data_store_service.GetDataStoreRequest ): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1121,7 +1545,7 @@ async def test_get_data_store_async_from_dict(): def test_get_data_store_field_headers(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1151,7 +1575,7 @@ def test_get_data_store_field_headers(): @pytest.mark.asyncio async def test_get_data_store_field_headers_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1182,7 +1606,7 @@ async def test_get_data_store_field_headers_async(): def test_get_data_store_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1206,7 +1630,7 @@ def test_get_data_store_flattened(): def test_get_data_store_flattened_error(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1221,7 +1645,7 @@ def test_get_data_store_flattened_error(): @pytest.mark.asyncio async def test_get_data_store_flattened_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1250,7 +1674,7 @@ async def test_get_data_store_flattened_async(): @pytest.mark.asyncio async def test_get_data_store_flattened_error_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1271,7 +1695,7 @@ async def test_get_data_store_flattened_error_async(): ) def test_list_data_stores(request_type, transport: str = "grpc"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1301,7 +1725,7 @@ def test_list_data_stores_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1319,7 +1743,7 @@ async def test_list_data_stores_async( request_type=data_store_service.ListDataStoresRequest, ): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1354,7 +1778,7 @@ async def test_list_data_stores_async_from_dict(): def test_list_data_stores_field_headers(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1384,7 +1808,7 @@ def test_list_data_stores_field_headers(): @pytest.mark.asyncio async def test_list_data_stores_field_headers_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1415,7 +1839,7 @@ async def test_list_data_stores_field_headers_async(): def test_list_data_stores_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1439,7 +1863,7 @@ def test_list_data_stores_flattened(): def test_list_data_stores_flattened_error(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1454,7 +1878,7 @@ def test_list_data_stores_flattened_error(): @pytest.mark.asyncio async def test_list_data_stores_flattened_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1483,7 +1907,7 @@ async def test_list_data_stores_flattened_async(): @pytest.mark.asyncio async def test_list_data_stores_flattened_error_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1497,7 +1921,7 @@ async def test_list_data_stores_flattened_error_async(): def test_list_data_stores_pager(transport_name: str = "grpc"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1547,7 +1971,7 @@ def test_list_data_stores_pager(transport_name: str = "grpc"): def test_list_data_stores_pages(transport_name: str = "grpc"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1589,7 +2013,7 @@ def test_list_data_stores_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_data_stores_async_pager(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1639,7 +2063,7 @@ async def test_list_data_stores_async_pager(): @pytest.mark.asyncio async def test_list_data_stores_async_pages(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1694,7 +2118,7 @@ async def test_list_data_stores_async_pages(): ) def test_delete_data_store(request_type, transport: str = "grpc"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1723,7 +2147,7 @@ def test_delete_data_store_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1743,7 +2167,7 @@ async def test_delete_data_store_async( request_type=data_store_service.DeleteDataStoreRequest, ): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1777,7 +2201,7 @@ async def test_delete_data_store_async_from_dict(): def test_delete_data_store_field_headers(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1809,7 +2233,7 @@ def test_delete_data_store_field_headers(): @pytest.mark.asyncio async def test_delete_data_store_field_headers_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1842,7 +2266,7 @@ async def test_delete_data_store_field_headers_async(): def test_delete_data_store_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1868,7 +2292,7 @@ def test_delete_data_store_flattened(): def test_delete_data_store_flattened_error(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1883,7 +2307,7 @@ def test_delete_data_store_flattened_error(): @pytest.mark.asyncio async def test_delete_data_store_flattened_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1914,7 +2338,7 @@ async def test_delete_data_store_flattened_async(): @pytest.mark.asyncio async def test_delete_data_store_flattened_error_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1935,7 +2359,7 @@ async def test_delete_data_store_flattened_error_async(): ) def test_update_data_store(request_type, transport: str = "grpc"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1977,7 +2401,7 @@ def test_update_data_store_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1997,7 +2421,7 @@ async def test_update_data_store_async( request_type=data_store_service.UpdateDataStoreRequest, ): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2044,7 +2468,7 @@ async def test_update_data_store_async_from_dict(): def test_update_data_store_field_headers(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2076,7 +2500,7 @@ def test_update_data_store_field_headers(): @pytest.mark.asyncio async def test_update_data_store_field_headers_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2109,7 +2533,7 @@ async def test_update_data_store_field_headers_async(): def test_update_data_store_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2139,7 +2563,7 @@ def test_update_data_store_flattened(): def test_update_data_store_flattened_error(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2155,7 +2579,7 @@ def test_update_data_store_flattened_error(): @pytest.mark.asyncio async def test_update_data_store_flattened_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2190,7 +2614,7 @@ async def test_update_data_store_flattened_async(): @pytest.mark.asyncio async def test_update_data_store_flattened_error_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2212,7 +2636,7 @@ async def test_update_data_store_flattened_error_async(): ) def test_create_data_store_rest(request_type): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2336,7 +2760,7 @@ def test_create_data_store_rest_required_fields( assert "dataStoreId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_data_store._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2348,7 +2772,7 @@ def test_create_data_store_rest_required_fields( jsonified_request["dataStoreId"] = "data_store_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_data_store._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2366,7 +2790,7 @@ def test_create_data_store_rest_required_fields( assert jsonified_request["dataStoreId"] == "data_store_id_value" client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2412,7 +2836,7 @@ def test_create_data_store_rest_required_fields( def test_create_data_store_rest_unset_required_fields(): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_data_store._get_unset_required_fields({}) @@ -2436,7 +2860,7 @@ def test_create_data_store_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_data_store_rest_interceptors(null_interceptor): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DataStoreServiceRestInterceptor(), @@ -2496,7 +2920,7 @@ def test_create_data_store_rest_bad_request( transport: str = "rest", request_type=data_store_service.CreateDataStoreRequest ): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2518,7 +2942,7 @@ def test_create_data_store_rest_bad_request( def test_create_data_store_rest_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2560,7 +2984,7 @@ def test_create_data_store_rest_flattened(): def test_create_data_store_rest_flattened_error(transport: str = "rest"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2577,7 +3001,7 @@ def test_create_data_store_rest_flattened_error(transport: str = "rest"): def test_create_data_store_rest_error(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2590,7 +3014,7 @@ def test_create_data_store_rest_error(): ) def test_get_data_store_rest(request_type): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2651,7 +3075,7 @@ def test_get_data_store_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_data_store._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2660,7 +3084,7 @@ def test_get_data_store_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_data_store._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2669,7 +3093,7 @@ def test_get_data_store_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2711,7 +3135,7 @@ def test_get_data_store_rest_required_fields( def test_get_data_store_rest_unset_required_fields(): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_data_store._get_unset_required_fields({}) @@ -2721,7 +3145,7 @@ def test_get_data_store_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_data_store_rest_interceptors(null_interceptor): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DataStoreServiceRestInterceptor(), @@ -2777,7 +3201,7 @@ def test_get_data_store_rest_bad_request( transport: str = "rest", request_type=data_store_service.GetDataStoreRequest ): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2799,7 +3223,7 @@ def test_get_data_store_rest_bad_request( def test_get_data_store_rest_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2843,7 +3267,7 @@ def test_get_data_store_rest_flattened(): def test_get_data_store_rest_flattened_error(transport: str = "rest"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2858,7 +3282,7 @@ def test_get_data_store_rest_flattened_error(transport: str = "rest"): def test_get_data_store_rest_error(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2871,7 +3295,7 @@ def test_get_data_store_rest_error(): ) def test_list_data_stores_rest(request_type): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2922,7 +3346,7 @@ def test_list_data_stores_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_data_stores._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2931,7 +3355,7 @@ def test_list_data_stores_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_data_stores._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2948,7 +3372,7 @@ def test_list_data_stores_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2990,7 +3414,7 @@ def test_list_data_stores_rest_required_fields( def test_list_data_stores_rest_unset_required_fields(): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_data_stores._get_unset_required_fields({}) @@ -3009,7 +3433,7 @@ def test_list_data_stores_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_data_stores_rest_interceptors(null_interceptor): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DataStoreServiceRestInterceptor(), @@ -3067,7 +3491,7 @@ def test_list_data_stores_rest_bad_request( transport: str = "rest", request_type=data_store_service.ListDataStoresRequest ): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3089,7 +3513,7 @@ def test_list_data_stores_rest_bad_request( def test_list_data_stores_rest_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3131,7 +3555,7 @@ def test_list_data_stores_rest_flattened(): def test_list_data_stores_rest_flattened_error(transport: str = "rest"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3146,7 +3570,7 @@ def test_list_data_stores_rest_flattened_error(transport: str = "rest"): def test_list_data_stores_rest_pager(transport: str = "rest"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3216,7 +3640,7 @@ def test_list_data_stores_rest_pager(transport: str = "rest"): ) def test_delete_data_store_rest(request_type): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3262,7 +3686,7 @@ def test_delete_data_store_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_data_store._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3271,7 +3695,7 @@ def test_delete_data_store_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_data_store._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3280,7 +3704,7 @@ def test_delete_data_store_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3319,7 +3743,7 @@ def test_delete_data_store_rest_required_fields( def test_delete_data_store_rest_unset_required_fields(): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_data_store._get_unset_required_fields({}) @@ -3329,7 +3753,7 @@ def test_delete_data_store_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_data_store_rest_interceptors(null_interceptor): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DataStoreServiceRestInterceptor(), @@ -3389,7 +3813,7 @@ def test_delete_data_store_rest_bad_request( transport: str = "rest", request_type=data_store_service.DeleteDataStoreRequest ): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3411,7 +3835,7 @@ def test_delete_data_store_rest_bad_request( def test_delete_data_store_rest_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3453,7 +3877,7 @@ def test_delete_data_store_rest_flattened(): def test_delete_data_store_rest_flattened_error(transport: str = "rest"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3468,7 +3892,7 @@ def test_delete_data_store_rest_flattened_error(transport: str = "rest"): def test_delete_data_store_rest_error(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3481,7 +3905,7 @@ def test_delete_data_store_rest_error(): ) def test_update_data_store_rest(request_type): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3619,14 +4043,14 @@ def test_update_data_store_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_data_store._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_data_store._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3635,7 +4059,7 @@ def test_update_data_store_rest_required_fields( # verify required fields with non-default values are left alone client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3678,7 +4102,7 @@ def test_update_data_store_rest_required_fields( def test_update_data_store_rest_unset_required_fields(): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_data_store._get_unset_required_fields({}) @@ -3688,7 +4112,7 @@ def test_update_data_store_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_data_store_rest_interceptors(null_interceptor): transport = transports.DataStoreServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DataStoreServiceRestInterceptor(), @@ -3746,7 +4170,7 @@ def test_update_data_store_rest_bad_request( transport: str = "rest", request_type=data_store_service.UpdateDataStoreRequest ): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3770,7 +4194,7 @@ def test_update_data_store_rest_bad_request( def test_update_data_store_rest_flattened(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3817,7 +4241,7 @@ def test_update_data_store_rest_flattened(): def test_update_data_store_rest_flattened_error(transport: str = "rest"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3833,24 +4257,24 @@ def test_update_data_store_rest_flattened_error(transport: str = "rest"): def test_update_data_store_rest_error(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DataStoreServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DataStoreServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DataStoreServiceClient( @@ -3860,7 +4284,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DataStoreServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3871,16 +4295,17 @@ 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 = DataStoreServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DataStoreServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DataStoreServiceClient( @@ -3892,7 +4317,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DataStoreServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DataStoreServiceClient(transport=transport) assert client.transport is transport @@ -3901,13 +4326,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DataStoreServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DataStoreServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3924,7 +4349,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3938,7 +4363,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DataStoreServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3946,7 +4371,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3958,7 +4383,7 @@ def test_data_store_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DataStoreServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3970,7 +4395,7 @@ def test_data_store_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DataStoreServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4013,7 +4438,7 @@ def test_data_store_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DataStoreServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4032,7 +4457,7 @@ def test_data_store_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.data_store_service.transports.DataStoreServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DataStoreServiceTransport() adc.assert_called_once() @@ -4040,7 +4465,7 @@ def test_data_store_service_base_transport_with_adc(): def test_data_store_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DataStoreServiceClient() adc.assert_called_once_with( scopes=None, @@ -4060,7 +4485,7 @@ def test_data_store_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4107,7 +4532,7 @@ def test_data_store_service_transport_create_channel(transport_class, grpc_helpe ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4135,7 +4560,7 @@ def test_data_store_service_transport_create_channel(transport_class, grpc_helpe ], ) def test_data_store_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4173,7 +4598,7 @@ def test_data_store_service_grpc_transport_client_cert_source_for_mtls(transport def test_data_store_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4185,7 +4610,7 @@ def test_data_store_service_http_transport_client_cert_source_for_mtls(): def test_data_store_service_rest_lro_client(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -4210,7 +4635,7 @@ def test_data_store_service_rest_lro_client(): ) def test_data_store_service_host_no_port(transport_name): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -4233,7 +4658,7 @@ def test_data_store_service_host_no_port(transport_name): ) def test_data_store_service_host_with_port(transport_name): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4253,8 +4678,8 @@ def test_data_store_service_host_with_port(transport_name): ], ) def test_data_store_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DataStoreServiceClient( credentials=creds1, transport=transport_name, @@ -4330,7 +4755,7 @@ def test_data_store_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4408,7 +4833,7 @@ def test_data_store_service_transport_channel_mtls_with_adc(transport_class): def test_data_store_service_grpc_lro_client(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -4425,7 +4850,7 @@ def test_data_store_service_grpc_lro_client(): def test_data_store_service_grpc_lro_async_client(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -4604,7 +5029,7 @@ def test_client_with_default_client_info(): transports.DataStoreServiceTransport, "_prep_wrapped_messages" ) as prep: client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4614,7 +5039,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DataStoreServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4623,7 +5048,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4638,7 +5063,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4671,7 +5096,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -4701,7 +5126,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4734,7 +5159,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -4762,7 +5187,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4787,7 +5212,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4813,7 +5238,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4842,7 +5267,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4871,7 +5296,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4889,7 +5314,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4907,7 +5332,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4932,7 +5357,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4958,7 +5383,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4987,7 +5412,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5016,7 +5441,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5034,7 +5459,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DataStoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5058,7 +5483,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5075,7 +5500,7 @@ def test_client_ctx(): ] for transport in transports: client = DataStoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5106,7 +5531,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_document_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_document_service.py index c048d3b23306..7e6aff7feefb 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_document_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_document_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -85,6 +85,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -114,6 +137,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert DocumentServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DocumentServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DocumentServiceClient._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 DocumentServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentServiceClient._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 DocumentServiceClient._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 DocumentServiceClient._get_client_cert_source(None, False) is None + assert ( + DocumentServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + DocumentServiceClient._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 ( + DocumentServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DocumentServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DocumentServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), +) +@mock.patch.object( + DocumentServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DocumentServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DocumentServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DocumentServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "always") + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentServiceClient._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 ( + DocumentServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DocumentServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DocumentServiceClient._get_universe_domain(None, None) + == DocumentServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DocumentServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DocumentServiceClient, transports.DocumentServiceGrpcTransport, "grpc"), + (DocumentServiceClient, transports.DocumentServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -125,7 +409,7 @@ def test__get_default_mtls_endpoint(): def test_document_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -179,7 +463,7 @@ def test_document_service_client_service_account_always_use_jwt( def test_document_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -229,20 +513,22 @@ def test_document_service_client_get_transport_class(): ) @mock.patch.object( DocumentServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), ) @mock.patch.object( DocumentServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), ) def test_document_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(DocumentServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -277,7 +563,9 @@ def test_document_service_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, @@ -307,15 +595,23 @@ def test_document_service_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") @@ -325,7 +621,9 @@ def test_document_service_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", @@ -343,7 +641,9 @@ def test_document_service_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, @@ -396,13 +696,13 @@ def test_document_service_client_client_options( ) @mock.patch.object( DocumentServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), ) @mock.patch.object( DocumentServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_document_service_client_mtls_env_auto( @@ -425,7 +725,9 @@ def test_document_service_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 @@ -457,7 +759,9 @@ def test_document_service_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 @@ -491,7 +795,9 @@ def test_document_service_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, @@ -581,6 +887,118 @@ def test_document_service_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", [DocumentServiceClient, DocumentServiceAsyncClient] +) +@mock.patch.object( + DocumentServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), +) +@mock.patch.object( + DocumentServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), +) +def test_document_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DocumentServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -607,7 +1025,9 @@ def test_document_service_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, @@ -647,7 +1067,9 @@ def test_document_service_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, @@ -707,7 +1129,9 @@ def test_document_service_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, @@ -724,8 +1148,8 @@ def test_document_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -754,7 +1178,7 @@ def test_document_service_client_create_channel_credentials_file( ) def test_get_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -791,7 +1215,7 @@ def test_get_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -808,7 +1232,7 @@ async def test_get_document_async( transport: str = "grpc_asyncio", request_type=document_service.GetDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -849,7 +1273,7 @@ async def test_get_document_async_from_dict(): def test_get_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -879,7 +1303,7 @@ def test_get_document_field_headers(): @pytest.mark.asyncio async def test_get_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -908,7 +1332,7 @@ async def test_get_document_field_headers_async(): def test_get_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -932,7 +1356,7 @@ def test_get_document_flattened(): def test_get_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -947,7 +1371,7 @@ def test_get_document_flattened_error(): @pytest.mark.asyncio async def test_get_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -974,7 +1398,7 @@ async def test_get_document_flattened_async(): @pytest.mark.asyncio async def test_get_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -995,7 +1419,7 @@ async def test_get_document_flattened_error_async(): ) def test_list_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1025,7 +1449,7 @@ def test_list_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1042,7 +1466,7 @@ async def test_list_documents_async( transport: str = "grpc_asyncio", request_type=document_service.ListDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1077,7 +1501,7 @@ async def test_list_documents_async_from_dict(): def test_list_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1107,7 +1531,7 @@ def test_list_documents_field_headers(): @pytest.mark.asyncio async def test_list_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1138,7 +1562,7 @@ async def test_list_documents_field_headers_async(): def test_list_documents_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1162,7 +1586,7 @@ def test_list_documents_flattened(): def test_list_documents_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1177,7 +1601,7 @@ def test_list_documents_flattened_error(): @pytest.mark.asyncio async def test_list_documents_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1206,7 +1630,7 @@ async def test_list_documents_flattened_async(): @pytest.mark.asyncio async def test_list_documents_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1220,7 +1644,7 @@ async def test_list_documents_flattened_error_async(): def test_list_documents_pager(transport_name: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1270,7 +1694,7 @@ def test_list_documents_pager(transport_name: str = "grpc"): def test_list_documents_pages(transport_name: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1312,7 +1736,7 @@ def test_list_documents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_documents_async_pager(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1362,7 +1786,7 @@ async def test_list_documents_async_pager(): @pytest.mark.asyncio async def test_list_documents_async_pages(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1417,7 +1841,7 @@ async def test_list_documents_async_pages(): ) def test_create_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1454,7 +1878,7 @@ def test_create_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1471,7 +1895,7 @@ async def test_create_document_async( transport: str = "grpc_asyncio", request_type=document_service.CreateDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1512,7 +1936,7 @@ async def test_create_document_async_from_dict(): def test_create_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1542,7 +1966,7 @@ def test_create_document_field_headers(): @pytest.mark.asyncio async def test_create_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1573,7 +1997,7 @@ async def test_create_document_field_headers_async(): def test_create_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1621,7 +2045,7 @@ def test_create_document_flattened(): def test_create_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1646,7 +2070,7 @@ def test_create_document_flattened_error(): @pytest.mark.asyncio async def test_create_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1699,7 +2123,7 @@ async def test_create_document_flattened_async(): @pytest.mark.asyncio async def test_create_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1730,7 +2154,7 @@ async def test_create_document_flattened_error_async(): ) def test_update_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1767,7 +2191,7 @@ def test_update_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1784,7 +2208,7 @@ async def test_update_document_async( transport: str = "grpc_asyncio", request_type=document_service.UpdateDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1825,7 +2249,7 @@ async def test_update_document_async_from_dict(): def test_update_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1855,7 +2279,7 @@ def test_update_document_field_headers(): @pytest.mark.asyncio async def test_update_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1891,7 +2315,7 @@ async def test_update_document_field_headers_async(): ) def test_delete_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1918,7 +2342,7 @@ def test_delete_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1935,7 +2359,7 @@ async def test_delete_document_async( transport: str = "grpc_asyncio", request_type=document_service.DeleteDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1965,7 +2389,7 @@ async def test_delete_document_async_from_dict(): def test_delete_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1995,7 +2419,7 @@ def test_delete_document_field_headers(): @pytest.mark.asyncio async def test_delete_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2024,7 +2448,7 @@ async def test_delete_document_field_headers_async(): def test_delete_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2048,7 +2472,7 @@ def test_delete_document_flattened(): def test_delete_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2063,7 +2487,7 @@ def test_delete_document_flattened_error(): @pytest.mark.asyncio async def test_delete_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2090,7 +2514,7 @@ async def test_delete_document_flattened_async(): @pytest.mark.asyncio async def test_delete_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2111,7 +2535,7 @@ async def test_delete_document_flattened_error_async(): ) def test_import_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2138,7 +2562,7 @@ def test_import_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2155,7 +2579,7 @@ async def test_import_documents_async( transport: str = "grpc_asyncio", request_type=import_config.ImportDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2187,7 +2611,7 @@ async def test_import_documents_async_from_dict(): def test_import_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2217,7 +2641,7 @@ def test_import_documents_field_headers(): @pytest.mark.asyncio async def test_import_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2255,7 +2679,7 @@ async def test_import_documents_field_headers_async(): ) def test_purge_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2282,7 +2706,7 @@ def test_purge_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2299,7 +2723,7 @@ async def test_purge_documents_async( transport: str = "grpc_asyncio", request_type=purge_config.PurgeDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2331,7 +2755,7 @@ async def test_purge_documents_async_from_dict(): def test_purge_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2361,7 +2785,7 @@ def test_purge_documents_field_headers(): @pytest.mark.asyncio async def test_purge_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2399,7 +2823,7 @@ async def test_purge_documents_field_headers_async(): ) def test_get_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2459,7 +2883,7 @@ def test_get_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2468,7 +2892,7 @@ def test_get_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2477,7 +2901,7 @@ def test_get_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2519,7 +2943,7 @@ def test_get_document_rest_required_fields( def test_get_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_document._get_unset_required_fields({}) @@ -2529,7 +2953,7 @@ def test_get_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -2585,7 +3009,7 @@ def test_get_document_rest_bad_request( transport: str = "rest", request_type=document_service.GetDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2609,7 +3033,7 @@ def test_get_document_rest_bad_request( def test_get_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2653,7 +3077,7 @@ def test_get_document_rest_flattened(): def test_get_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2668,7 +3092,7 @@ def test_get_document_rest_flattened_error(transport: str = "rest"): def test_get_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2681,7 +3105,7 @@ def test_get_document_rest_error(): ) def test_list_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2734,7 +3158,7 @@ def test_list_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2743,7 +3167,7 @@ def test_list_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2759,7 +3183,7 @@ def test_list_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2801,7 +3225,7 @@ def test_list_documents_rest_required_fields( def test_list_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_documents._get_unset_required_fields({}) @@ -2819,7 +3243,7 @@ def test_list_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -2877,7 +3301,7 @@ def test_list_documents_rest_bad_request( transport: str = "rest", request_type=document_service.ListDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2901,7 +3325,7 @@ def test_list_documents_rest_bad_request( def test_list_documents_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2945,7 +3369,7 @@ def test_list_documents_rest_flattened(): def test_list_documents_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2960,7 +3384,7 @@ def test_list_documents_rest_flattened_error(transport: str = "rest"): def test_list_documents_rest_pager(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3032,7 +3456,7 @@ def test_list_documents_rest_pager(transport: str = "rest"): ) def test_create_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3175,7 +3599,7 @@ def test_create_document_rest_required_fields( assert "documentId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3187,7 +3611,7 @@ def test_create_document_rest_required_fields( jsonified_request["documentId"] = "document_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("document_id",)) @@ -3200,7 +3624,7 @@ def test_create_document_rest_required_fields( assert jsonified_request["documentId"] == "document_id_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3249,7 +3673,7 @@ def test_create_document_rest_required_fields( def test_create_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_document._get_unset_required_fields({}) @@ -3268,7 +3692,7 @@ def test_create_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3326,7 +3750,7 @@ def test_create_document_rest_bad_request( transport: str = "rest", request_type=document_service.CreateDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3350,7 +3774,7 @@ def test_create_document_rest_bad_request( def test_create_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3404,7 +3828,7 @@ def test_create_document_rest_flattened(): def test_create_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3429,7 +3853,7 @@ def test_create_document_rest_flattened_error(transport: str = "rest"): def test_create_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3442,7 +3866,7 @@ def test_create_document_rest_error(): ) def test_update_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3584,14 +4008,14 @@ def test_update_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("allow_missing",)) @@ -3600,7 +4024,7 @@ def test_update_document_rest_required_fields( # verify required fields with non-default values are left alone client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3643,7 +4067,7 @@ def test_update_document_rest_required_fields( def test_update_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_document._get_unset_required_fields({}) @@ -3653,7 +4077,7 @@ def test_update_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3709,7 +4133,7 @@ def test_update_document_rest_bad_request( transport: str = "rest", request_type=document_service.UpdateDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3735,7 +4159,7 @@ def test_update_document_rest_bad_request( def test_update_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3748,7 +4172,7 @@ def test_update_document_rest_error(): ) def test_delete_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3796,7 +4220,7 @@ def test_delete_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3805,7 +4229,7 @@ def test_delete_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3814,7 +4238,7 @@ def test_delete_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3853,7 +4277,7 @@ def test_delete_document_rest_required_fields( def test_delete_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_document._get_unset_required_fields({}) @@ -3863,7 +4287,7 @@ def test_delete_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3913,7 +4337,7 @@ def test_delete_document_rest_bad_request( transport: str = "rest", request_type=document_service.DeleteDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3937,7 +4361,7 @@ def test_delete_document_rest_bad_request( def test_delete_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3979,7 +4403,7 @@ def test_delete_document_rest_flattened(): def test_delete_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3994,7 +4418,7 @@ def test_delete_document_rest_flattened_error(transport: str = "rest"): def test_delete_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4007,7 +4431,7 @@ def test_delete_document_rest_error(): ) def test_import_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4055,7 +4479,7 @@ def test_import_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4064,7 +4488,7 @@ def test_import_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4073,7 +4497,7 @@ def test_import_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4113,7 +4537,7 @@ def test_import_documents_rest_required_fields( def test_import_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_documents._get_unset_required_fields({}) @@ -4123,7 +4547,7 @@ def test_import_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -4183,7 +4607,7 @@ def test_import_documents_rest_bad_request( transport: str = "rest", request_type=import_config.ImportDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4207,7 +4631,7 @@ def test_import_documents_rest_bad_request( def test_import_documents_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4220,7 +4644,7 @@ def test_import_documents_rest_error(): ) def test_purge_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4269,7 +4693,7 @@ def test_purge_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).purge_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4279,7 +4703,7 @@ def test_purge_documents_rest_required_fields( jsonified_request["filter"] = "filter_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).purge_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4290,7 +4714,7 @@ def test_purge_documents_rest_required_fields( assert jsonified_request["filter"] == "filter_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4330,7 +4754,7 @@ def test_purge_documents_rest_required_fields( def test_purge_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.purge_documents._get_unset_required_fields({}) @@ -4348,7 +4772,7 @@ def test_purge_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_purge_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -4408,7 +4832,7 @@ def test_purge_documents_rest_bad_request( transport: str = "rest", request_type=purge_config.PurgeDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4432,24 +4856,24 @@ def test_purge_documents_rest_bad_request( def test_purge_documents_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( @@ -4459,7 +4883,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4470,16 +4894,17 @@ 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 = DocumentServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( @@ -4491,7 +4916,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DocumentServiceClient(transport=transport) assert client.transport is transport @@ -4500,13 +4925,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DocumentServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4523,7 +4948,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4537,7 +4962,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DocumentServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4545,7 +4970,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4557,7 +4982,7 @@ def test_document_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DocumentServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4569,7 +4994,7 @@ def test_document_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DocumentServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4614,7 +5039,7 @@ def test_document_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4633,7 +5058,7 @@ def test_document_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentServiceTransport() adc.assert_called_once() @@ -4641,7 +5066,7 @@ def test_document_service_base_transport_with_adc(): def test_document_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DocumentServiceClient() adc.assert_called_once_with( scopes=None, @@ -4661,7 +5086,7 @@ def test_document_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4708,7 +5133,7 @@ def test_document_service_transport_create_channel(transport_class, grpc_helpers ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4736,7 +5161,7 @@ def test_document_service_transport_create_channel(transport_class, grpc_helpers ], ) def test_document_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4774,7 +5199,7 @@ def test_document_service_grpc_transport_client_cert_source_for_mtls(transport_c def test_document_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4786,7 +5211,7 @@ def test_document_service_http_transport_client_cert_source_for_mtls(): def test_document_service_rest_lro_client(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -4811,7 +5236,7 @@ def test_document_service_rest_lro_client(): ) def test_document_service_host_no_port(transport_name): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -4834,7 +5259,7 @@ def test_document_service_host_no_port(transport_name): ) def test_document_service_host_with_port(transport_name): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4854,8 +5279,8 @@ def test_document_service_host_with_port(transport_name): ], ) def test_document_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DocumentServiceClient( credentials=creds1, transport=transport_name, @@ -4937,7 +5362,7 @@ def test_document_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5015,7 +5440,7 @@ def test_document_service_transport_channel_mtls_with_adc(transport_class): def test_document_service_grpc_lro_client(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5032,7 +5457,7 @@ def test_document_service_grpc_lro_client(): def test_document_service_grpc_lro_async_client(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -5220,7 +5645,7 @@ def test_client_with_default_client_info(): transports.DocumentServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5230,7 +5655,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5239,7 +5664,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5254,7 +5679,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5287,7 +5712,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -5317,7 +5742,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5350,7 +5775,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -5378,7 +5803,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5403,7 +5828,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5429,7 +5854,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5458,7 +5883,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5487,7 +5912,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5505,7 +5930,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5523,7 +5948,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5548,7 +5973,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5574,7 +5999,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5603,7 +6028,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5632,7 +6057,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5650,7 +6075,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5674,7 +6099,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5691,7 +6116,7 @@ def test_client_ctx(): ] for transport in transports: client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5722,7 +6147,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_engine_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_engine_service.py index 63a2b2ed9760..8dc1f1b0b23e 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_engine_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_engine_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -83,6 +83,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -112,6 +135,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert EngineServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EngineServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EngineServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EngineServiceClient._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 EngineServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EngineServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EngineServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EngineServiceClient._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 EngineServiceClient._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 EngineServiceClient._get_client_cert_source(None, False) is None + assert ( + EngineServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + EngineServiceClient._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 ( + EngineServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + EngineServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EngineServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EngineServiceClient), +) +@mock.patch.object( + EngineServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EngineServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EngineServiceClient._DEFAULT_UNIVERSE + default_endpoint = EngineServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EngineServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + EngineServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EngineServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EngineServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EngineServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + EngineServiceClient._get_api_endpoint(None, None, default_universe, "always") + == EngineServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EngineServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EngineServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EngineServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + EngineServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EngineServiceClient._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 ( + EngineServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + EngineServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + EngineServiceClient._get_universe_domain(None, None) + == EngineServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EngineServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (EngineServiceClient, transports.EngineServiceGrpcTransport, "grpc"), + (EngineServiceClient, transports.EngineServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -121,7 +401,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_engine_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -173,7 +453,7 @@ def test_engine_service_client_service_account_always_use_jwt( ], ) def test_engine_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -223,20 +503,22 @@ def test_engine_service_client_get_transport_class(): ) @mock.patch.object( EngineServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EngineServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EngineServiceClient), ) @mock.patch.object( EngineServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EngineServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EngineServiceAsyncClient), ) def test_engine_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(EngineServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -271,7 +553,9 @@ def test_engine_service_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, @@ -301,15 +585,23 @@ def test_engine_service_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") @@ -319,7 +611,9 @@ def test_engine_service_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", @@ -337,7 +631,9 @@ def test_engine_service_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, @@ -370,13 +666,13 @@ def test_engine_service_client_client_options( ) @mock.patch.object( EngineServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EngineServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EngineServiceClient), ) @mock.patch.object( EngineServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EngineServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EngineServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_engine_service_client_mtls_env_auto( @@ -399,7 +695,9 @@ def test_engine_service_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 @@ -431,7 +729,9 @@ def test_engine_service_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 @@ -465,7 +765,9 @@ def test_engine_service_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, @@ -555,6 +857,118 @@ def test_engine_service_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", [EngineServiceClient, EngineServiceAsyncClient] +) +@mock.patch.object( + EngineServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EngineServiceClient), +) +@mock.patch.object( + EngineServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EngineServiceAsyncClient), +) +def test_engine_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EngineServiceClient._DEFAULT_UNIVERSE + default_endpoint = EngineServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EngineServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -581,7 +995,9 @@ def test_engine_service_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, @@ -621,7 +1037,9 @@ def test_engine_service_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, @@ -681,7 +1099,9 @@ def test_engine_service_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, @@ -698,8 +1118,8 @@ def test_engine_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -728,7 +1148,7 @@ def test_engine_service_client_create_channel_credentials_file( ) def test_create_engine(request_type, transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -755,7 +1175,7 @@ def test_create_engine_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -772,7 +1192,7 @@ async def test_create_engine_async( transport: str = "grpc_asyncio", request_type=engine_service.CreateEngineRequest ): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -804,7 +1224,7 @@ async def test_create_engine_async_from_dict(): def test_create_engine_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -834,7 +1254,7 @@ def test_create_engine_field_headers(): @pytest.mark.asyncio async def test_create_engine_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -865,7 +1285,7 @@ async def test_create_engine_field_headers_async(): def test_create_engine_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -897,7 +1317,7 @@ def test_create_engine_flattened(): def test_create_engine_flattened_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -914,7 +1334,7 @@ def test_create_engine_flattened_error(): @pytest.mark.asyncio async def test_create_engine_flattened_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -951,7 +1371,7 @@ async def test_create_engine_flattened_async(): @pytest.mark.asyncio async def test_create_engine_flattened_error_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -974,7 +1394,7 @@ async def test_create_engine_flattened_error_async(): ) def test_delete_engine(request_type, transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1001,7 +1421,7 @@ def test_delete_engine_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1018,7 +1438,7 @@ async def test_delete_engine_async( transport: str = "grpc_asyncio", request_type=engine_service.DeleteEngineRequest ): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1050,7 +1470,7 @@ async def test_delete_engine_async_from_dict(): def test_delete_engine_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1080,7 +1500,7 @@ def test_delete_engine_field_headers(): @pytest.mark.asyncio async def test_delete_engine_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1111,7 +1531,7 @@ async def test_delete_engine_field_headers_async(): def test_delete_engine_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1135,7 +1555,7 @@ def test_delete_engine_flattened(): def test_delete_engine_flattened_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1150,7 +1570,7 @@ def test_delete_engine_flattened_error(): @pytest.mark.asyncio async def test_delete_engine_flattened_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1179,7 +1599,7 @@ async def test_delete_engine_flattened_async(): @pytest.mark.asyncio async def test_delete_engine_flattened_error_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1200,7 +1620,7 @@ async def test_delete_engine_flattened_error_async(): ) def test_update_engine(request_type, transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1238,7 +1658,7 @@ def test_update_engine_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1255,7 +1675,7 @@ async def test_update_engine_async( transport: str = "grpc_asyncio", request_type=engine_service.UpdateEngineRequest ): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1298,7 +1718,7 @@ async def test_update_engine_async_from_dict(): def test_update_engine_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1328,7 +1748,7 @@ def test_update_engine_field_headers(): @pytest.mark.asyncio async def test_update_engine_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1357,7 +1777,7 @@ async def test_update_engine_field_headers_async(): def test_update_engine_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1385,7 +1805,7 @@ def test_update_engine_flattened(): def test_update_engine_flattened_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1401,7 +1821,7 @@ def test_update_engine_flattened_error(): @pytest.mark.asyncio async def test_update_engine_flattened_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1432,7 +1852,7 @@ async def test_update_engine_flattened_async(): @pytest.mark.asyncio async def test_update_engine_flattened_error_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1454,7 +1874,7 @@ async def test_update_engine_flattened_error_async(): ) def test_get_engine(request_type, transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1492,7 +1912,7 @@ def test_get_engine_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1509,7 +1929,7 @@ async def test_get_engine_async( transport: str = "grpc_asyncio", request_type=engine_service.GetEngineRequest ): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1552,7 +1972,7 @@ async def test_get_engine_async_from_dict(): def test_get_engine_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1582,7 +2002,7 @@ def test_get_engine_field_headers(): @pytest.mark.asyncio async def test_get_engine_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1611,7 +2031,7 @@ async def test_get_engine_field_headers_async(): def test_get_engine_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1635,7 +2055,7 @@ def test_get_engine_flattened(): def test_get_engine_flattened_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1650,7 +2070,7 @@ def test_get_engine_flattened_error(): @pytest.mark.asyncio async def test_get_engine_flattened_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1677,7 +2097,7 @@ async def test_get_engine_flattened_async(): @pytest.mark.asyncio async def test_get_engine_flattened_error_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1698,7 +2118,7 @@ async def test_get_engine_flattened_error_async(): ) def test_list_engines(request_type, transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1728,7 +2148,7 @@ def test_list_engines_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1745,7 +2165,7 @@ async def test_list_engines_async( transport: str = "grpc_asyncio", request_type=engine_service.ListEnginesRequest ): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1780,7 +2200,7 @@ async def test_list_engines_async_from_dict(): def test_list_engines_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1810,7 +2230,7 @@ def test_list_engines_field_headers(): @pytest.mark.asyncio async def test_list_engines_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1841,7 +2261,7 @@ async def test_list_engines_field_headers_async(): def test_list_engines_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1865,7 +2285,7 @@ def test_list_engines_flattened(): def test_list_engines_flattened_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1880,7 +2300,7 @@ def test_list_engines_flattened_error(): @pytest.mark.asyncio async def test_list_engines_flattened_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1909,7 +2329,7 @@ async def test_list_engines_flattened_async(): @pytest.mark.asyncio async def test_list_engines_flattened_error_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1923,7 +2343,7 @@ async def test_list_engines_flattened_error_async(): def test_list_engines_pager(transport_name: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1973,7 +2393,7 @@ def test_list_engines_pager(transport_name: str = "grpc"): def test_list_engines_pages(transport_name: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2015,7 +2435,7 @@ def test_list_engines_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_engines_async_pager(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2065,7 +2485,7 @@ async def test_list_engines_async_pager(): @pytest.mark.asyncio async def test_list_engines_async_pages(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2120,7 +2540,7 @@ async def test_list_engines_async_pages(): ) def test_pause_engine(request_type, transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2158,7 +2578,7 @@ def test_pause_engine_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2175,7 +2595,7 @@ async def test_pause_engine_async( transport: str = "grpc_asyncio", request_type=engine_service.PauseEngineRequest ): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2218,7 +2638,7 @@ async def test_pause_engine_async_from_dict(): def test_pause_engine_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2248,7 +2668,7 @@ def test_pause_engine_field_headers(): @pytest.mark.asyncio async def test_pause_engine_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2277,7 +2697,7 @@ async def test_pause_engine_field_headers_async(): def test_pause_engine_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2301,7 +2721,7 @@ def test_pause_engine_flattened(): def test_pause_engine_flattened_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2316,7 +2736,7 @@ def test_pause_engine_flattened_error(): @pytest.mark.asyncio async def test_pause_engine_flattened_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2343,7 +2763,7 @@ async def test_pause_engine_flattened_async(): @pytest.mark.asyncio async def test_pause_engine_flattened_error_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2364,7 +2784,7 @@ async def test_pause_engine_flattened_error_async(): ) def test_resume_engine(request_type, transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2402,7 +2822,7 @@ def test_resume_engine_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2419,7 +2839,7 @@ async def test_resume_engine_async( transport: str = "grpc_asyncio", request_type=engine_service.ResumeEngineRequest ): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2462,7 +2882,7 @@ async def test_resume_engine_async_from_dict(): def test_resume_engine_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2492,7 +2912,7 @@ def test_resume_engine_field_headers(): @pytest.mark.asyncio async def test_resume_engine_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2521,7 +2941,7 @@ async def test_resume_engine_field_headers_async(): def test_resume_engine_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2545,7 +2965,7 @@ def test_resume_engine_flattened(): def test_resume_engine_flattened_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2560,7 +2980,7 @@ def test_resume_engine_flattened_error(): @pytest.mark.asyncio async def test_resume_engine_flattened_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2587,7 +3007,7 @@ async def test_resume_engine_flattened_async(): @pytest.mark.asyncio async def test_resume_engine_flattened_error_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2608,7 +3028,7 @@ async def test_resume_engine_flattened_error_async(): ) def test_tune_engine(request_type, transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2635,7 +3055,7 @@ def test_tune_engine_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2652,7 +3072,7 @@ async def test_tune_engine_async( transport: str = "grpc_asyncio", request_type=engine_service.TuneEngineRequest ): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2684,7 +3104,7 @@ async def test_tune_engine_async_from_dict(): def test_tune_engine_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2714,7 +3134,7 @@ def test_tune_engine_field_headers(): @pytest.mark.asyncio async def test_tune_engine_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2745,7 +3165,7 @@ async def test_tune_engine_field_headers_async(): def test_tune_engine_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2769,7 +3189,7 @@ def test_tune_engine_flattened(): def test_tune_engine_flattened_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2784,7 +3204,7 @@ def test_tune_engine_flattened_error(): @pytest.mark.asyncio async def test_tune_engine_flattened_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2813,7 +3233,7 @@ async def test_tune_engine_flattened_async(): @pytest.mark.asyncio async def test_tune_engine_flattened_error_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2834,7 +3254,7 @@ async def test_tune_engine_flattened_error_async(): ) def test_create_engine_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2985,7 +3405,7 @@ def test_create_engine_rest_required_fields( assert "engineId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2997,7 +3417,7 @@ def test_create_engine_rest_required_fields( jsonified_request["engineId"] = "engine_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_engine._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("engine_id",)) @@ -3010,7 +3430,7 @@ def test_create_engine_rest_required_fields( assert jsonified_request["engineId"] == "engine_id_value" client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3056,7 +3476,7 @@ def test_create_engine_rest_required_fields( def test_create_engine_rest_unset_required_fields(): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_engine._get_unset_required_fields({}) @@ -3075,7 +3495,7 @@ def test_create_engine_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_engine_rest_interceptors(null_interceptor): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EngineServiceRestInterceptor(), @@ -3135,7 +3555,7 @@ def test_create_engine_rest_bad_request( transport: str = "rest", request_type=engine_service.CreateEngineRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3157,7 +3577,7 @@ def test_create_engine_rest_bad_request( def test_create_engine_rest_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3201,7 +3621,7 @@ def test_create_engine_rest_flattened(): def test_create_engine_rest_flattened_error(transport: str = "rest"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3218,7 +3638,7 @@ def test_create_engine_rest_flattened_error(transport: str = "rest"): def test_create_engine_rest_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3231,7 +3651,7 @@ def test_create_engine_rest_error(): ) def test_delete_engine_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3279,7 +3699,7 @@ def test_delete_engine_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3288,7 +3708,7 @@ def test_delete_engine_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3297,7 +3717,7 @@ def test_delete_engine_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3336,7 +3756,7 @@ def test_delete_engine_rest_required_fields( def test_delete_engine_rest_unset_required_fields(): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_engine._get_unset_required_fields({}) @@ -3346,7 +3766,7 @@ def test_delete_engine_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_engine_rest_interceptors(null_interceptor): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EngineServiceRestInterceptor(), @@ -3406,7 +3826,7 @@ def test_delete_engine_rest_bad_request( transport: str = "rest", request_type=engine_service.DeleteEngineRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3430,7 +3850,7 @@ def test_delete_engine_rest_bad_request( def test_delete_engine_rest_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3472,7 +3892,7 @@ def test_delete_engine_rest_flattened(): def test_delete_engine_rest_flattened_error(transport: str = "rest"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3487,7 +3907,7 @@ def test_delete_engine_rest_flattened_error(transport: str = "rest"): def test_delete_engine_rest_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3500,7 +3920,7 @@ def test_delete_engine_rest_error(): ) def test_update_engine_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3665,14 +4085,14 @@ def test_update_engine_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_engine._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3681,7 +4101,7 @@ def test_update_engine_rest_required_fields( # verify required fields with non-default values are left alone client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3724,7 +4144,7 @@ def test_update_engine_rest_required_fields( def test_update_engine_rest_unset_required_fields(): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_engine._get_unset_required_fields({}) @@ -3734,7 +4154,7 @@ def test_update_engine_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_engine_rest_interceptors(null_interceptor): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EngineServiceRestInterceptor(), @@ -3790,7 +4210,7 @@ def test_update_engine_rest_bad_request( transport: str = "rest", request_type=engine_service.UpdateEngineRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3816,7 +4236,7 @@ def test_update_engine_rest_bad_request( def test_update_engine_rest_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3863,7 +4283,7 @@ def test_update_engine_rest_flattened(): def test_update_engine_rest_flattened_error(transport: str = "rest"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3879,7 +4299,7 @@ def test_update_engine_rest_flattened_error(transport: str = "rest"): def test_update_engine_rest_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3892,7 +4312,7 @@ def test_update_engine_rest_error(): ) def test_get_engine_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3951,7 +4371,7 @@ def test_get_engine_rest_required_fields(request_type=engine_service.GetEngineRe # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3960,7 +4380,7 @@ def test_get_engine_rest_required_fields(request_type=engine_service.GetEngineRe jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3969,7 +4389,7 @@ def test_get_engine_rest_required_fields(request_type=engine_service.GetEngineRe assert jsonified_request["name"] == "name_value" client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4011,7 +4431,7 @@ def test_get_engine_rest_required_fields(request_type=engine_service.GetEngineRe def test_get_engine_rest_unset_required_fields(): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_engine._get_unset_required_fields({}) @@ -4021,7 +4441,7 @@ def test_get_engine_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_engine_rest_interceptors(null_interceptor): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EngineServiceRestInterceptor(), @@ -4077,7 +4497,7 @@ def test_get_engine_rest_bad_request( transport: str = "rest", request_type=engine_service.GetEngineRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4101,7 +4521,7 @@ def test_get_engine_rest_bad_request( def test_get_engine_rest_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4145,7 +4565,7 @@ def test_get_engine_rest_flattened(): def test_get_engine_rest_flattened_error(transport: str = "rest"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4160,7 +4580,7 @@ def test_get_engine_rest_flattened_error(transport: str = "rest"): def test_get_engine_rest_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4173,7 +4593,7 @@ def test_get_engine_rest_error(): ) def test_list_engines_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4224,7 +4644,7 @@ def test_list_engines_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_engines._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4233,7 +4653,7 @@ def test_list_engines_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_engines._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4250,7 +4670,7 @@ def test_list_engines_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4292,7 +4712,7 @@ def test_list_engines_rest_required_fields( def test_list_engines_rest_unset_required_fields(): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_engines._get_unset_required_fields({}) @@ -4311,7 +4731,7 @@ def test_list_engines_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_engines_rest_interceptors(null_interceptor): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EngineServiceRestInterceptor(), @@ -4369,7 +4789,7 @@ def test_list_engines_rest_bad_request( transport: str = "rest", request_type=engine_service.ListEnginesRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4391,7 +4811,7 @@ def test_list_engines_rest_bad_request( def test_list_engines_rest_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4435,7 +4855,7 @@ def test_list_engines_rest_flattened(): def test_list_engines_rest_flattened_error(transport: str = "rest"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4450,7 +4870,7 @@ def test_list_engines_rest_flattened_error(transport: str = "rest"): def test_list_engines_rest_pager(transport: str = "rest"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4522,7 +4942,7 @@ def test_list_engines_rest_pager(transport: str = "rest"): ) def test_pause_engine_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4583,7 +5003,7 @@ def test_pause_engine_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).pause_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4592,7 +5012,7 @@ def test_pause_engine_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).pause_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4601,7 +5021,7 @@ def test_pause_engine_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4644,7 +5064,7 @@ def test_pause_engine_rest_required_fields( def test_pause_engine_rest_unset_required_fields(): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.pause_engine._get_unset_required_fields({}) @@ -4654,7 +5074,7 @@ def test_pause_engine_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_pause_engine_rest_interceptors(null_interceptor): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EngineServiceRestInterceptor(), @@ -4710,7 +5130,7 @@ def test_pause_engine_rest_bad_request( transport: str = "rest", request_type=engine_service.PauseEngineRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4734,7 +5154,7 @@ def test_pause_engine_rest_bad_request( def test_pause_engine_rest_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4778,7 +5198,7 @@ def test_pause_engine_rest_flattened(): def test_pause_engine_rest_flattened_error(transport: str = "rest"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4793,7 +5213,7 @@ def test_pause_engine_rest_flattened_error(transport: str = "rest"): def test_pause_engine_rest_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4806,7 +5226,7 @@ def test_pause_engine_rest_error(): ) def test_resume_engine_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4867,7 +5287,7 @@ def test_resume_engine_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).resume_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4876,7 +5296,7 @@ def test_resume_engine_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).resume_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4885,7 +5305,7 @@ def test_resume_engine_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4928,7 +5348,7 @@ def test_resume_engine_rest_required_fields( def test_resume_engine_rest_unset_required_fields(): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.resume_engine._get_unset_required_fields({}) @@ -4938,7 +5358,7 @@ def test_resume_engine_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_resume_engine_rest_interceptors(null_interceptor): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EngineServiceRestInterceptor(), @@ -4994,7 +5414,7 @@ def test_resume_engine_rest_bad_request( transport: str = "rest", request_type=engine_service.ResumeEngineRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5018,7 +5438,7 @@ def test_resume_engine_rest_bad_request( def test_resume_engine_rest_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5062,7 +5482,7 @@ def test_resume_engine_rest_flattened(): def test_resume_engine_rest_flattened_error(transport: str = "rest"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5077,7 +5497,7 @@ def test_resume_engine_rest_flattened_error(transport: str = "rest"): def test_resume_engine_rest_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5090,7 +5510,7 @@ def test_resume_engine_rest_error(): ) def test_tune_engine_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5138,7 +5558,7 @@ def test_tune_engine_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).tune_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5147,7 +5567,7 @@ def test_tune_engine_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).tune_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5156,7 +5576,7 @@ def test_tune_engine_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5196,7 +5616,7 @@ def test_tune_engine_rest_required_fields( def test_tune_engine_rest_unset_required_fields(): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.tune_engine._get_unset_required_fields({}) @@ -5206,7 +5626,7 @@ def test_tune_engine_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_tune_engine_rest_interceptors(null_interceptor): transport = transports.EngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EngineServiceRestInterceptor(), @@ -5266,7 +5686,7 @@ def test_tune_engine_rest_bad_request( transport: str = "rest", request_type=engine_service.TuneEngineRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5290,7 +5710,7 @@ def test_tune_engine_rest_bad_request( def test_tune_engine_rest_flattened(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5332,7 +5752,7 @@ def test_tune_engine_rest_flattened(): def test_tune_engine_rest_flattened_error(transport: str = "rest"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5347,24 +5767,24 @@ def test_tune_engine_rest_flattened_error(transport: str = "rest"): def test_tune_engine_rest_error(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EngineServiceClient( @@ -5374,7 +5794,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5385,16 +5805,17 @@ 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 = EngineServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EngineServiceClient( @@ -5406,7 +5827,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EngineServiceClient(transport=transport) assert client.transport is transport @@ -5415,13 +5836,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EngineServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5438,7 +5859,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5452,7 +5873,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = EngineServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5460,7 +5881,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5472,7 +5893,7 @@ def test_engine_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EngineServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5484,7 +5905,7 @@ def test_engine_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EngineServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5530,7 +5951,7 @@ def test_engine_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EngineServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5549,7 +5970,7 @@ def test_engine_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.engine_service.transports.EngineServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EngineServiceTransport() adc.assert_called_once() @@ -5557,7 +5978,7 @@ def test_engine_service_base_transport_with_adc(): def test_engine_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EngineServiceClient() adc.assert_called_once_with( scopes=None, @@ -5577,7 +5998,7 @@ def test_engine_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5624,7 +6045,7 @@ def test_engine_service_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5652,7 +6073,7 @@ def test_engine_service_transport_create_channel(transport_class, grpc_helpers): ], ) def test_engine_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5690,7 +6111,7 @@ def test_engine_service_grpc_transport_client_cert_source_for_mtls(transport_cla def test_engine_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5702,7 +6123,7 @@ def test_engine_service_http_transport_client_cert_source_for_mtls(): def test_engine_service_rest_lro_client(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5727,7 +6148,7 @@ def test_engine_service_rest_lro_client(): ) def test_engine_service_host_no_port(transport_name): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -5750,7 +6171,7 @@ def test_engine_service_host_no_port(transport_name): ) def test_engine_service_host_with_port(transport_name): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -5770,8 +6191,8 @@ def test_engine_service_host_with_port(transport_name): ], ) def test_engine_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EngineServiceClient( credentials=creds1, transport=transport_name, @@ -5854,7 +6275,7 @@ def test_engine_service_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5932,7 +6353,7 @@ def test_engine_service_transport_channel_mtls_with_adc(transport_class): def test_engine_service_grpc_lro_client(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5949,7 +6370,7 @@ def test_engine_service_grpc_lro_client(): def test_engine_service_grpc_lro_async_client(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -6131,7 +6552,7 @@ def test_client_with_default_client_info(): transports.EngineServiceTransport, "_prep_wrapped_messages" ) as prep: client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6141,7 +6562,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EngineServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6150,7 +6571,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6165,7 +6586,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6198,7 +6619,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -6228,7 +6649,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6261,7 +6682,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -6289,7 +6710,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6314,7 +6735,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6340,7 +6761,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6369,7 +6790,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6398,7 +6819,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6416,7 +6837,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6434,7 +6855,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6459,7 +6880,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6485,7 +6906,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6514,7 +6935,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6543,7 +6964,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6561,7 +6982,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = EngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6585,7 +7006,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -6602,7 +7023,7 @@ def test_client_ctx(): ] for transport in transports: client = EngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -6633,7 +7054,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_recommendation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_recommendation_service.py index 87a4cd661ebb..fd7a12f7586a 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_recommendation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_recommendation_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -74,6 +74,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -104,6 +127,291 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert RecommendationServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert RecommendationServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert RecommendationServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + RecommendationServiceClient._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 RecommendationServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert RecommendationServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert RecommendationServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + RecommendationServiceClient._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 RecommendationServiceClient._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 RecommendationServiceClient._get_client_cert_source(None, False) is None + assert ( + RecommendationServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + RecommendationServiceClient._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 ( + RecommendationServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + RecommendationServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + RecommendationServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceClient), +) +@mock.patch.object( + RecommendationServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = RecommendationServiceClient._DEFAULT_UNIVERSE + default_endpoint = RecommendationServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = RecommendationServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + RecommendationServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + RecommendationServiceClient._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 ( + RecommendationServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + RecommendationServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + RecommendationServiceClient._get_universe_domain(None, None) + == RecommendationServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + RecommendationServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + RecommendationServiceClient, + transports.RecommendationServiceGrpcTransport, + "grpc", + ), + ( + RecommendationServiceClient, + transports.RecommendationServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -115,7 +423,7 @@ def test__get_default_mtls_endpoint(): def test_recommendation_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -169,7 +477,7 @@ def test_recommendation_service_client_service_account_always_use_jwt( def test_recommendation_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -227,20 +535,22 @@ def test_recommendation_service_client_get_transport_class(): ) @mock.patch.object( RecommendationServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(RecommendationServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceClient), ) @mock.patch.object( RecommendationServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(RecommendationServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceAsyncClient), ) def test_recommendation_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(RecommendationServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -275,7 +585,9 @@ def test_recommendation_service_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, @@ -305,15 +617,23 @@ def test_recommendation_service_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") @@ -323,7 +643,9 @@ def test_recommendation_service_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", @@ -341,7 +663,9 @@ def test_recommendation_service_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, @@ -394,13 +718,13 @@ def test_recommendation_service_client_client_options( ) @mock.patch.object( RecommendationServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(RecommendationServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceClient), ) @mock.patch.object( RecommendationServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(RecommendationServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_recommendation_service_client_mtls_env_auto( @@ -423,7 +747,9 @@ def test_recommendation_service_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 @@ -455,7 +781,9 @@ def test_recommendation_service_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 @@ -489,7 +817,9 @@ def test_recommendation_service_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, @@ -579,6 +909,118 @@ def test_recommendation_service_client_get_mtls_endpoint_and_cert_source(client_ 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", [RecommendationServiceClient, RecommendationServiceAsyncClient] +) +@mock.patch.object( + RecommendationServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceClient), +) +@mock.patch.object( + RecommendationServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceAsyncClient), +) +def test_recommendation_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = RecommendationServiceClient._DEFAULT_UNIVERSE + default_endpoint = RecommendationServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = RecommendationServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -613,7 +1055,9 @@ def test_recommendation_service_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, @@ -658,7 +1102,9 @@ def test_recommendation_service_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, @@ -718,7 +1164,9 @@ def test_recommendation_service_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, @@ -735,8 +1183,8 @@ def test_recommendation_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -765,7 +1213,7 @@ def test_recommendation_service_client_create_channel_credentials_file( ) def test_recommend(request_type, transport: str = "grpc"): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -799,7 +1247,7 @@ def test_recommend_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -817,7 +1265,7 @@ async def test_recommend_async( request_type=recommendation_service.RecommendRequest, ): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -856,7 +1304,7 @@ async def test_recommend_async_from_dict(): def test_recommend_field_headers(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -886,7 +1334,7 @@ def test_recommend_field_headers(): @pytest.mark.asyncio async def test_recommend_field_headers_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -924,7 +1372,7 @@ async def test_recommend_field_headers_async(): ) def test_recommend_rest(request_type): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -981,7 +1429,7 @@ def test_recommend_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).recommend._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -990,7 +1438,7 @@ def test_recommend_rest_required_fields( jsonified_request["servingConfig"] = "serving_config_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).recommend._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -999,7 +1447,7 @@ def test_recommend_rest_required_fields( assert jsonified_request["servingConfig"] == "serving_config_value" client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1042,7 +1490,7 @@ def test_recommend_rest_required_fields( def test_recommend_rest_unset_required_fields(): transport = transports.RecommendationServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.recommend._get_unset_required_fields({}) @@ -1060,7 +1508,7 @@ def test_recommend_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_recommend_rest_interceptors(null_interceptor): transport = transports.RecommendationServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.RecommendationServiceRestInterceptor(), @@ -1118,7 +1566,7 @@ def test_recommend_rest_bad_request( transport: str = "rest", request_type=recommendation_service.RecommendRequest ): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1142,24 +1590,24 @@ def test_recommend_rest_bad_request( def test_recommend_rest_error(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = RecommendationServiceClient( @@ -1169,7 +1617,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1180,16 +1628,17 @@ 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 = RecommendationServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = RecommendationServiceClient( @@ -1201,7 +1650,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = RecommendationServiceClient(transport=transport) assert client.transport is transport @@ -1210,13 +1659,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.RecommendationServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1233,7 +1682,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1247,7 +1696,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = RecommendationServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1255,7 +1704,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1267,7 +1716,7 @@ def test_recommendation_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.RecommendationServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1279,7 +1728,7 @@ def test_recommendation_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.RecommendationServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1313,7 +1762,7 @@ def test_recommendation_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.RecommendationServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1332,7 +1781,7 @@ def test_recommendation_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.RecommendationServiceTransport() adc.assert_called_once() @@ -1340,7 +1789,7 @@ def test_recommendation_service_base_transport_with_adc(): def test_recommendation_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) RecommendationServiceClient() adc.assert_called_once_with( scopes=None, @@ -1360,7 +1809,7 @@ def test_recommendation_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1407,7 +1856,7 @@ def test_recommendation_service_transport_create_channel(transport_class, grpc_h ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1437,7 +1886,7 @@ def test_recommendation_service_transport_create_channel(transport_class, grpc_h def test_recommendation_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1475,7 +1924,7 @@ def test_recommendation_service_grpc_transport_client_cert_source_for_mtls( def test_recommendation_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1495,7 +1944,7 @@ def test_recommendation_service_http_transport_client_cert_source_for_mtls(): ) def test_recommendation_service_host_no_port(transport_name): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -1518,7 +1967,7 @@ def test_recommendation_service_host_no_port(transport_name): ) def test_recommendation_service_host_with_port(transport_name): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -1538,8 +1987,8 @@ def test_recommendation_service_host_with_port(transport_name): ], ) def test_recommendation_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = RecommendationServiceClient( credentials=creds1, transport=transport_name, @@ -1603,7 +2052,7 @@ def test_recommendation_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -1854,7 +2303,7 @@ def test_client_with_default_client_info(): transports.RecommendationServiceTransport, "_prep_wrapped_messages" ) as prep: client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1864,7 +2313,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = RecommendationServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1873,7 +2322,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -1888,7 +2337,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1921,7 +2370,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -1951,7 +2400,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1984,7 +2433,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -2012,7 +2461,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2037,7 +2486,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2063,7 +2512,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2092,7 +2541,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2121,7 +2570,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2139,7 +2588,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2157,7 +2606,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2182,7 +2631,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2208,7 +2657,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2237,7 +2686,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2266,7 +2715,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2284,7 +2733,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2308,7 +2757,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2325,7 +2774,7 @@ def test_client_ctx(): ] for transport in transports: client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2359,7 +2808,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_schema_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_schema_service.py index 6c0c212df2c8..d7f8640ac24d 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_schema_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_schema_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -81,6 +81,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -110,6 +133,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SchemaServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SchemaServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SchemaServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SchemaServiceClient._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 SchemaServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SchemaServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SchemaServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SchemaServiceClient._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 SchemaServiceClient._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 SchemaServiceClient._get_client_cert_source(None, False) is None + assert ( + SchemaServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + SchemaServiceClient._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 ( + SchemaServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SchemaServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SchemaServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), +) +@mock.patch.object( + SchemaServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SchemaServiceClient._DEFAULT_UNIVERSE + default_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SchemaServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SchemaServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, default_universe, "always") + == SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SchemaServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SchemaServiceClient._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 ( + SchemaServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SchemaServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SchemaServiceClient._get_universe_domain(None, None) + == SchemaServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SchemaServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SchemaServiceClient, transports.SchemaServiceGrpcTransport, "grpc"), + (SchemaServiceClient, transports.SchemaServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -119,7 +399,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_schema_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -171,7 +451,7 @@ def test_schema_service_client_service_account_always_use_jwt( ], ) def test_schema_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -221,20 +501,22 @@ def test_schema_service_client_get_transport_class(): ) @mock.patch.object( SchemaServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), ) @mock.patch.object( SchemaServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), ) def test_schema_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SchemaServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -269,7 +551,9 @@ def test_schema_service_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, @@ -299,15 +583,23 @@ def test_schema_service_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") @@ -317,7 +609,9 @@ def test_schema_service_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", @@ -335,7 +629,9 @@ def test_schema_service_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, @@ -368,13 +664,13 @@ def test_schema_service_client_client_options( ) @mock.patch.object( SchemaServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), ) @mock.patch.object( SchemaServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_schema_service_client_mtls_env_auto( @@ -397,7 +693,9 @@ def test_schema_service_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 @@ -429,7 +727,9 @@ def test_schema_service_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 @@ -463,7 +763,9 @@ def test_schema_service_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, @@ -553,6 +855,118 @@ def test_schema_service_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", [SchemaServiceClient, SchemaServiceAsyncClient] +) +@mock.patch.object( + SchemaServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), +) +@mock.patch.object( + SchemaServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), +) +def test_schema_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SchemaServiceClient._DEFAULT_UNIVERSE + default_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SchemaServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -579,7 +993,9 @@ def test_schema_service_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, @@ -619,7 +1035,9 @@ def test_schema_service_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, @@ -679,7 +1097,9 @@ def test_schema_service_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, @@ -696,8 +1116,8 @@ def test_schema_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -726,7 +1146,7 @@ def test_schema_service_client_create_channel_credentials_file( ) def test_get_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -757,7 +1177,7 @@ def test_get_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -774,7 +1194,7 @@ async def test_get_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.GetSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -809,7 +1229,7 @@ async def test_get_schema_async_from_dict(): def test_get_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -839,7 +1259,7 @@ def test_get_schema_field_headers(): @pytest.mark.asyncio async def test_get_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -868,7 +1288,7 @@ async def test_get_schema_field_headers_async(): def test_get_schema_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -892,7 +1312,7 @@ def test_get_schema_flattened(): def test_get_schema_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -907,7 +1327,7 @@ def test_get_schema_flattened_error(): @pytest.mark.asyncio async def test_get_schema_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -934,7 +1354,7 @@ async def test_get_schema_flattened_async(): @pytest.mark.asyncio async def test_get_schema_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -955,7 +1375,7 @@ async def test_get_schema_flattened_error_async(): ) def test_list_schemas(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -985,7 +1405,7 @@ def test_list_schemas_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1002,7 +1422,7 @@ async def test_list_schemas_async( transport: str = "grpc_asyncio", request_type=schema_service.ListSchemasRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1037,7 +1457,7 @@ async def test_list_schemas_async_from_dict(): def test_list_schemas_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1067,7 +1487,7 @@ def test_list_schemas_field_headers(): @pytest.mark.asyncio async def test_list_schemas_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1098,7 +1518,7 @@ async def test_list_schemas_field_headers_async(): def test_list_schemas_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1122,7 +1542,7 @@ def test_list_schemas_flattened(): def test_list_schemas_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1137,7 +1557,7 @@ def test_list_schemas_flattened_error(): @pytest.mark.asyncio async def test_list_schemas_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1166,7 +1586,7 @@ async def test_list_schemas_flattened_async(): @pytest.mark.asyncio async def test_list_schemas_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1180,7 +1600,7 @@ async def test_list_schemas_flattened_error_async(): def test_list_schemas_pager(transport_name: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1230,7 +1650,7 @@ def test_list_schemas_pager(transport_name: str = "grpc"): def test_list_schemas_pages(transport_name: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1272,7 +1692,7 @@ def test_list_schemas_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_schemas_async_pager(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1322,7 +1742,7 @@ async def test_list_schemas_async_pager(): @pytest.mark.asyncio async def test_list_schemas_async_pages(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1377,7 +1797,7 @@ async def test_list_schemas_async_pages(): ) def test_create_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1404,7 +1824,7 @@ def test_create_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1421,7 +1841,7 @@ async def test_create_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.CreateSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1453,7 +1873,7 @@ async def test_create_schema_async_from_dict(): def test_create_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1483,7 +1903,7 @@ def test_create_schema_field_headers(): @pytest.mark.asyncio async def test_create_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1514,7 +1934,7 @@ async def test_create_schema_field_headers_async(): def test_create_schema_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1562,7 +1982,7 @@ def test_create_schema_flattened(): def test_create_schema_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1587,7 +2007,7 @@ def test_create_schema_flattened_error(): @pytest.mark.asyncio async def test_create_schema_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1640,7 +2060,7 @@ async def test_create_schema_flattened_async(): @pytest.mark.asyncio async def test_create_schema_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1671,7 +2091,7 @@ async def test_create_schema_flattened_error_async(): ) def test_update_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1698,7 +2118,7 @@ def test_update_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1715,7 +2135,7 @@ async def test_update_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.UpdateSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1747,7 +2167,7 @@ async def test_update_schema_async_from_dict(): def test_update_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1777,7 +2197,7 @@ def test_update_schema_field_headers(): @pytest.mark.asyncio async def test_update_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1815,7 +2235,7 @@ async def test_update_schema_field_headers_async(): ) def test_delete_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1842,7 +2262,7 @@ def test_delete_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1859,7 +2279,7 @@ async def test_delete_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.DeleteSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1891,7 +2311,7 @@ async def test_delete_schema_async_from_dict(): def test_delete_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1921,7 +2341,7 @@ def test_delete_schema_field_headers(): @pytest.mark.asyncio async def test_delete_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1952,7 +2372,7 @@ async def test_delete_schema_field_headers_async(): def test_delete_schema_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1976,7 +2396,7 @@ def test_delete_schema_flattened(): def test_delete_schema_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1991,7 +2411,7 @@ def test_delete_schema_flattened_error(): @pytest.mark.asyncio async def test_delete_schema_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2020,7 +2440,7 @@ async def test_delete_schema_flattened_async(): @pytest.mark.asyncio async def test_delete_schema_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2041,7 +2461,7 @@ async def test_delete_schema_flattened_error_async(): ) def test_get_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2093,7 +2513,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2102,7 +2522,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2111,7 +2531,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe assert jsonified_request["name"] == "name_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2153,7 +2573,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe def test_get_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_schema._get_unset_required_fields({}) @@ -2163,7 +2583,7 @@ def test_get_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -2219,7 +2639,7 @@ def test_get_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.GetSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2243,7 +2663,7 @@ def test_get_schema_rest_bad_request( def test_get_schema_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2287,7 +2707,7 @@ def test_get_schema_rest_flattened(): def test_get_schema_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2302,7 +2722,7 @@ def test_get_schema_rest_flattened_error(transport: str = "rest"): def test_get_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2315,7 +2735,7 @@ def test_get_schema_rest_error(): ) def test_list_schemas_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2366,7 +2786,7 @@ def test_list_schemas_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_schemas._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2375,7 +2795,7 @@ def test_list_schemas_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_schemas._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2391,7 +2811,7 @@ def test_list_schemas_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2433,7 +2853,7 @@ def test_list_schemas_rest_required_fields( def test_list_schemas_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_schemas._get_unset_required_fields({}) @@ -2451,7 +2871,7 @@ def test_list_schemas_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_schemas_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -2509,7 +2929,7 @@ def test_list_schemas_rest_bad_request( transport: str = "rest", request_type=schema_service.ListSchemasRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2531,7 +2951,7 @@ def test_list_schemas_rest_bad_request( def test_list_schemas_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2575,7 +2995,7 @@ def test_list_schemas_rest_flattened(): def test_list_schemas_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2590,7 +3010,7 @@ def test_list_schemas_rest_flattened_error(transport: str = "rest"): def test_list_schemas_rest_pager(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2662,7 +3082,7 @@ def test_list_schemas_rest_pager(transport: str = "rest"): ) def test_create_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2795,7 +3215,7 @@ def test_create_schema_rest_required_fields( assert "schemaId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2807,7 +3227,7 @@ def test_create_schema_rest_required_fields( jsonified_request["schemaId"] = "schema_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_schema._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("schema_id",)) @@ -2820,7 +3240,7 @@ def test_create_schema_rest_required_fields( assert jsonified_request["schemaId"] == "schema_id_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2866,7 +3286,7 @@ def test_create_schema_rest_required_fields( def test_create_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_schema._get_unset_required_fields({}) @@ -2885,7 +3305,7 @@ def test_create_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -2945,7 +3365,7 @@ def test_create_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.CreateSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2967,7 +3387,7 @@ def test_create_schema_rest_bad_request( def test_create_schema_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3019,7 +3439,7 @@ def test_create_schema_rest_flattened(): def test_create_schema_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3044,7 +3464,7 @@ def test_create_schema_rest_flattened_error(transport: str = "rest"): def test_create_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3057,7 +3477,7 @@ def test_create_schema_rest_error(): ) def test_update_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3191,14 +3611,14 @@ def test_update_schema_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_schema._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("allow_missing",)) @@ -3207,7 +3627,7 @@ def test_update_schema_rest_required_fields( # verify required fields with non-default values are left alone client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3247,7 +3667,7 @@ def test_update_schema_rest_required_fields( def test_update_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_schema._get_unset_required_fields({}) @@ -3257,7 +3677,7 @@ def test_update_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -3317,7 +3737,7 @@ def test_update_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.UpdateSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3343,7 +3763,7 @@ def test_update_schema_rest_bad_request( def test_update_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3356,7 +3776,7 @@ def test_update_schema_rest_error(): ) def test_delete_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3404,7 +3824,7 @@ def test_delete_schema_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3413,7 +3833,7 @@ def test_delete_schema_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3422,7 +3842,7 @@ def test_delete_schema_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3461,7 +3881,7 @@ def test_delete_schema_rest_required_fields( def test_delete_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_schema._get_unset_required_fields({}) @@ -3471,7 +3891,7 @@ def test_delete_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -3531,7 +3951,7 @@ def test_delete_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.DeleteSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3555,7 +3975,7 @@ def test_delete_schema_rest_bad_request( def test_delete_schema_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3597,7 +4017,7 @@ def test_delete_schema_rest_flattened(): def test_delete_schema_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3612,24 +4032,24 @@ def test_delete_schema_rest_flattened_error(transport: str = "rest"): def test_delete_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SchemaServiceClient( @@ -3639,7 +4059,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3650,16 +4070,17 @@ 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 = SchemaServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SchemaServiceClient( @@ -3671,7 +4092,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SchemaServiceClient(transport=transport) assert client.transport is transport @@ -3680,13 +4101,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SchemaServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3703,7 +4124,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3717,7 +4138,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SchemaServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3725,7 +4146,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3737,7 +4158,7 @@ def test_schema_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SchemaServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3749,7 +4170,7 @@ def test_schema_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SchemaServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3792,7 +4213,7 @@ def test_schema_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SchemaServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3811,7 +4232,7 @@ def test_schema_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SchemaServiceTransport() adc.assert_called_once() @@ -3819,7 +4240,7 @@ def test_schema_service_base_transport_with_adc(): def test_schema_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SchemaServiceClient() adc.assert_called_once_with( scopes=None, @@ -3839,7 +4260,7 @@ def test_schema_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -3886,7 +4307,7 @@ def test_schema_service_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3914,7 +4335,7 @@ def test_schema_service_transport_create_channel(transport_class, grpc_helpers): ], ) def test_schema_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3952,7 +4373,7 @@ def test_schema_service_grpc_transport_client_cert_source_for_mtls(transport_cla def test_schema_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -3964,7 +4385,7 @@ def test_schema_service_http_transport_client_cert_source_for_mtls(): def test_schema_service_rest_lro_client(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -3989,7 +4410,7 @@ def test_schema_service_rest_lro_client(): ) def test_schema_service_host_no_port(transport_name): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -4012,7 +4433,7 @@ def test_schema_service_host_no_port(transport_name): ) def test_schema_service_host_with_port(transport_name): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4032,8 +4453,8 @@ def test_schema_service_host_with_port(transport_name): ], ) def test_schema_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SchemaServiceClient( credentials=creds1, transport=transport_name, @@ -4107,7 +4528,7 @@ def test_schema_service_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4185,7 +4606,7 @@ def test_schema_service_transport_channel_mtls_with_adc(transport_class): def test_schema_service_grpc_lro_client(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -4202,7 +4623,7 @@ def test_schema_service_grpc_lro_client(): def test_schema_service_grpc_lro_async_client(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -4382,7 +4803,7 @@ def test_client_with_default_client_info(): transports.SchemaServiceTransport, "_prep_wrapped_messages" ) as prep: client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4392,7 +4813,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SchemaServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4401,7 +4822,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4416,7 +4837,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4449,7 +4870,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -4479,7 +4900,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4512,7 +4933,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -4540,7 +4961,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4565,7 +4986,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4591,7 +5012,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4620,7 +5041,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4649,7 +5070,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4667,7 +5088,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4685,7 +5106,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4710,7 +5131,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4736,7 +5157,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4765,7 +5186,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4794,7 +5215,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -4812,7 +5233,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -4836,7 +5257,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -4853,7 +5274,7 @@ def test_client_ctx(): ] for transport in transports: client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -4884,7 +5305,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_service.py index ed2dbd5e13f5..20f20f68f628 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -69,6 +69,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -98,6 +121,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SearchServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SearchServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SearchServiceClient._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 SearchServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SearchServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SearchServiceClient._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 SearchServiceClient._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 SearchServiceClient._get_client_cert_source(None, False) is None + assert ( + SearchServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + SearchServiceClient._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 ( + SearchServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SearchServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), +) +@mock.patch.object( + SearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SearchServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, default_universe, "always") + == SearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SearchServiceClient._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 ( + SearchServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SearchServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SearchServiceClient._get_universe_domain(None, None) + == SearchServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SearchServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SearchServiceClient, transports.SearchServiceGrpcTransport, "grpc"), + (SearchServiceClient, transports.SearchServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -107,7 +387,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_search_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -159,7 +439,7 @@ def test_search_service_client_service_account_always_use_jwt( ], ) def test_search_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -209,20 +489,22 @@ def test_search_service_client_get_transport_class(): ) @mock.patch.object( SearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), ) @mock.patch.object( SearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), ) def test_search_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SearchServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -257,7 +539,9 @@ def test_search_service_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, @@ -287,15 +571,23 @@ def test_search_service_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") @@ -305,7 +597,9 @@ def test_search_service_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", @@ -323,7 +617,9 @@ def test_search_service_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, @@ -356,13 +652,13 @@ def test_search_service_client_client_options( ) @mock.patch.object( SearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), ) @mock.patch.object( SearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_search_service_client_mtls_env_auto( @@ -385,7 +681,9 @@ def test_search_service_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 @@ -417,7 +715,9 @@ def test_search_service_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 @@ -451,7 +751,9 @@ def test_search_service_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, @@ -541,6 +843,118 @@ def test_search_service_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", [SearchServiceClient, SearchServiceAsyncClient] +) +@mock.patch.object( + SearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), +) +@mock.patch.object( + SearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), +) +def test_search_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SearchServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -567,7 +981,9 @@ def test_search_service_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, @@ -607,7 +1023,9 @@ def test_search_service_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, @@ -667,7 +1085,9 @@ def test_search_service_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, @@ -684,8 +1104,8 @@ def test_search_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -714,7 +1134,7 @@ def test_search_service_client_create_channel_credentials_file( ) def test_search(request_type, transport: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -754,7 +1174,7 @@ def test_search_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -771,7 +1191,7 @@ async def test_search_async( transport: str = "grpc_asyncio", request_type=search_service.SearchRequest ): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -816,7 +1236,7 @@ async def test_search_async_from_dict(): def test_search_field_headers(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -846,7 +1266,7 @@ def test_search_field_headers(): @pytest.mark.asyncio async def test_search_field_headers_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -877,7 +1297,7 @@ async def test_search_field_headers_async(): def test_search_pager(transport_name: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -929,7 +1349,7 @@ def test_search_pager(transport_name: str = "grpc"): def test_search_pages(transport_name: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -971,7 +1391,7 @@ def test_search_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_search_async_pager(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1023,7 +1443,7 @@ async def test_search_async_pager(): @pytest.mark.asyncio async def test_search_async_pages(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1076,7 +1496,7 @@ async def test_search_async_pages(): ) def test_search_rest(request_type): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1137,7 +1557,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1146,7 +1566,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): jsonified_request["servingConfig"] = "serving_config_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1155,7 +1575,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): assert jsonified_request["servingConfig"] == "serving_config_value" client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1198,7 +1618,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): def test_search_rest_unset_required_fields(): transport = transports.SearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search._get_unset_required_fields({}) @@ -1208,7 +1628,7 @@ def test_search_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_rest_interceptors(null_interceptor): transport = transports.SearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SearchServiceRestInterceptor(), @@ -1264,7 +1684,7 @@ def test_search_rest_bad_request( transport: str = "rest", request_type=search_service.SearchRequest ): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1288,7 +1708,7 @@ def test_search_rest_bad_request( def test_search_rest_pager(transport: str = "rest"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1354,17 +1774,17 @@ def test_search_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchServiceClient( @@ -1374,7 +1794,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1385,16 +1805,17 @@ 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 = SearchServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchServiceClient( @@ -1406,7 +1827,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SearchServiceClient(transport=transport) assert client.transport is transport @@ -1415,13 +1836,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SearchServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1438,7 +1859,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1452,7 +1873,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SearchServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1460,7 +1881,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1472,7 +1893,7 @@ def test_search_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1484,7 +1905,7 @@ def test_search_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1518,7 +1939,7 @@ def test_search_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SearchServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1537,7 +1958,7 @@ def test_search_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SearchServiceTransport() adc.assert_called_once() @@ -1545,7 +1966,7 @@ def test_search_service_base_transport_with_adc(): def test_search_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SearchServiceClient() adc.assert_called_once_with( scopes=None, @@ -1565,7 +1986,7 @@ def test_search_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1612,7 +2033,7 @@ def test_search_service_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1640,7 +2061,7 @@ def test_search_service_transport_create_channel(transport_class, grpc_helpers): ], ) def test_search_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1678,7 +2099,7 @@ def test_search_service_grpc_transport_client_cert_source_for_mtls(transport_cla def test_search_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1698,7 +2119,7 @@ def test_search_service_http_transport_client_cert_source_for_mtls(): ) def test_search_service_host_no_port(transport_name): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -1721,7 +2142,7 @@ def test_search_service_host_no_port(transport_name): ) def test_search_service_host_with_port(transport_name): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -1741,8 +2162,8 @@ def test_search_service_host_with_port(transport_name): ], ) def test_search_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SearchServiceClient( credentials=creds1, transport=transport_name, @@ -1804,7 +2225,7 @@ def test_search_service_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2084,7 +2505,7 @@ def test_client_with_default_client_info(): transports.SearchServiceTransport, "_prep_wrapped_messages" ) as prep: client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2094,7 +2515,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SearchServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2103,7 +2524,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2118,7 +2539,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2151,7 +2572,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -2181,7 +2602,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2214,7 +2635,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -2242,7 +2663,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2267,7 +2688,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2293,7 +2714,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2322,7 +2743,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2351,7 +2772,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2369,7 +2790,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2387,7 +2808,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2412,7 +2833,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2438,7 +2859,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2467,7 +2888,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2496,7 +2917,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2514,7 +2935,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2538,7 +2959,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2555,7 +2976,7 @@ def test_client_ctx(): ] for transport in transports: client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2586,7 +3007,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_tuning_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_tuning_service.py index 4892c2467183..baea9e9bfdbe 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_tuning_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_search_tuning_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -79,6 +79,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -109,6 +132,289 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SearchTuningServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SearchTuningServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SearchTuningServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SearchTuningServiceClient._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 SearchTuningServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SearchTuningServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SearchTuningServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SearchTuningServiceClient._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 SearchTuningServiceClient._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 SearchTuningServiceClient._get_client_cert_source(None, False) is None + assert ( + SearchTuningServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + SearchTuningServiceClient._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 ( + SearchTuningServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SearchTuningServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SearchTuningServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchTuningServiceClient), +) +@mock.patch.object( + SearchTuningServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchTuningServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SearchTuningServiceClient._DEFAULT_UNIVERSE + default_endpoint = SearchTuningServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SearchTuningServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SearchTuningServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SearchTuningServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SearchTuningServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchTuningServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + SearchTuningServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == SearchTuningServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchTuningServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SearchTuningServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchTuningServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SearchTuningServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SearchTuningServiceClient._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 ( + SearchTuningServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SearchTuningServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SearchTuningServiceClient._get_universe_domain(None, None) + == SearchTuningServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SearchTuningServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + SearchTuningServiceClient, + transports.SearchTuningServiceGrpcTransport, + "grpc", + ), + ( + SearchTuningServiceClient, + transports.SearchTuningServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -120,7 +426,7 @@ def test__get_default_mtls_endpoint(): def test_search_tuning_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -174,7 +480,7 @@ def test_search_tuning_service_client_service_account_always_use_jwt( def test_search_tuning_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -232,20 +538,22 @@ def test_search_tuning_service_client_get_transport_class(): ) @mock.patch.object( SearchTuningServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchTuningServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchTuningServiceClient), ) @mock.patch.object( SearchTuningServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchTuningServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchTuningServiceAsyncClient), ) def test_search_tuning_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SearchTuningServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -280,7 +588,9 @@ def test_search_tuning_service_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, @@ -310,15 +620,23 @@ def test_search_tuning_service_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") @@ -328,7 +646,9 @@ def test_search_tuning_service_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", @@ -346,7 +666,9 @@ def test_search_tuning_service_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, @@ -399,13 +721,13 @@ def test_search_tuning_service_client_client_options( ) @mock.patch.object( SearchTuningServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchTuningServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchTuningServiceClient), ) @mock.patch.object( SearchTuningServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchTuningServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchTuningServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_search_tuning_service_client_mtls_env_auto( @@ -428,7 +750,9 @@ def test_search_tuning_service_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 @@ -460,7 +784,9 @@ def test_search_tuning_service_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 @@ -494,7 +820,9 @@ def test_search_tuning_service_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, @@ -584,6 +912,118 @@ def test_search_tuning_service_client_get_mtls_endpoint_and_cert_source(client_c 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", [SearchTuningServiceClient, SearchTuningServiceAsyncClient] +) +@mock.patch.object( + SearchTuningServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchTuningServiceClient), +) +@mock.patch.object( + SearchTuningServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchTuningServiceAsyncClient), +) +def test_search_tuning_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SearchTuningServiceClient._DEFAULT_UNIVERSE + default_endpoint = SearchTuningServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SearchTuningServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -618,7 +1058,9 @@ def test_search_tuning_service_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, @@ -663,7 +1105,9 @@ def test_search_tuning_service_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, @@ -723,7 +1167,9 @@ def test_search_tuning_service_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, @@ -740,8 +1186,8 @@ def test_search_tuning_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -770,7 +1216,7 @@ def test_search_tuning_service_client_create_channel_credentials_file( ) def test_train_custom_model(request_type, transport: str = "grpc"): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -799,7 +1245,7 @@ def test_train_custom_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -819,7 +1265,7 @@ async def test_train_custom_model_async( request_type=search_tuning_service.TrainCustomModelRequest, ): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -853,7 +1299,7 @@ async def test_train_custom_model_async_from_dict(): def test_train_custom_model_field_headers(): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -885,7 +1331,7 @@ def test_train_custom_model_field_headers(): @pytest.mark.asyncio async def test_train_custom_model_field_headers_async(): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -925,7 +1371,7 @@ async def test_train_custom_model_field_headers_async(): ) def test_train_custom_model_rest(request_type): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -973,7 +1419,7 @@ def test_train_custom_model_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_custom_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -982,7 +1428,7 @@ def test_train_custom_model_rest_required_fields( jsonified_request["dataStore"] = "data_store_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_custom_model._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -991,7 +1437,7 @@ def test_train_custom_model_rest_required_fields( assert jsonified_request["dataStore"] == "data_store_value" client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1031,7 +1477,7 @@ def test_train_custom_model_rest_required_fields( def test_train_custom_model_rest_unset_required_fields(): transport = transports.SearchTuningServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.train_custom_model._get_unset_required_fields({}) @@ -1041,7 +1487,7 @@ def test_train_custom_model_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_train_custom_model_rest_interceptors(null_interceptor): transport = transports.SearchTuningServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SearchTuningServiceRestInterceptor(), @@ -1101,7 +1547,7 @@ def test_train_custom_model_rest_bad_request( transport: str = "rest", request_type=search_tuning_service.TrainCustomModelRequest ): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1125,24 +1571,24 @@ def test_train_custom_model_rest_bad_request( def test_train_custom_model_rest_error(): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SearchTuningServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SearchTuningServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchTuningServiceClient( @@ -1152,7 +1598,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SearchTuningServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1163,16 +1609,17 @@ 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 = SearchTuningServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SearchTuningServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchTuningServiceClient( @@ -1184,7 +1631,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SearchTuningServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SearchTuningServiceClient(transport=transport) assert client.transport is transport @@ -1193,13 +1640,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SearchTuningServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SearchTuningServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1216,7 +1663,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1230,7 +1677,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SearchTuningServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1238,7 +1685,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1250,7 +1697,7 @@ def test_search_tuning_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SearchTuningServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1262,7 +1709,7 @@ def test_search_tuning_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SearchTuningServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1301,7 +1748,7 @@ def test_search_tuning_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SearchTuningServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1320,7 +1767,7 @@ def test_search_tuning_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.search_tuning_service.transports.SearchTuningServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SearchTuningServiceTransport() adc.assert_called_once() @@ -1328,7 +1775,7 @@ def test_search_tuning_service_base_transport_with_adc(): def test_search_tuning_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SearchTuningServiceClient() adc.assert_called_once_with( scopes=None, @@ -1348,7 +1795,7 @@ def test_search_tuning_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1395,7 +1842,7 @@ def test_search_tuning_service_transport_create_channel(transport_class, grpc_he ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1425,7 +1872,7 @@ def test_search_tuning_service_transport_create_channel(transport_class, grpc_he def test_search_tuning_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1463,7 +1910,7 @@ def test_search_tuning_service_grpc_transport_client_cert_source_for_mtls( def test_search_tuning_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1475,7 +1922,7 @@ def test_search_tuning_service_http_transport_client_cert_source_for_mtls(): def test_search_tuning_service_rest_lro_client(): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -1500,7 +1947,7 @@ def test_search_tuning_service_rest_lro_client(): ) def test_search_tuning_service_host_no_port(transport_name): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -1523,7 +1970,7 @@ def test_search_tuning_service_host_no_port(transport_name): ) def test_search_tuning_service_host_with_port(transport_name): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -1543,8 +1990,8 @@ def test_search_tuning_service_host_with_port(transport_name): ], ) def test_search_tuning_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SearchTuningServiceClient( credentials=creds1, transport=transport_name, @@ -1608,7 +2055,7 @@ def test_search_tuning_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -1686,7 +2133,7 @@ def test_search_tuning_service_transport_channel_mtls_with_adc(transport_class): def test_search_tuning_service_grpc_lro_client(): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -1703,7 +2150,7 @@ def test_search_tuning_service_grpc_lro_client(): def test_search_tuning_service_grpc_lro_async_client(): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -1854,7 +2301,7 @@ def test_client_with_default_client_info(): transports.SearchTuningServiceTransport, "_prep_wrapped_messages" ) as prep: client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1864,7 +2311,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SearchTuningServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1873,7 +2320,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -1888,7 +2335,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1921,7 +2368,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -1951,7 +2398,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1984,7 +2431,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -2012,7 +2459,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2037,7 +2484,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2063,7 +2510,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2092,7 +2539,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2121,7 +2568,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2139,7 +2586,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2157,7 +2604,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2182,7 +2629,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2208,7 +2655,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2237,7 +2684,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2266,7 +2713,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2284,7 +2731,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SearchTuningServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2308,7 +2755,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2325,7 +2772,7 @@ def test_client_ctx(): ] for transport in transports: client = SearchTuningServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2359,7 +2806,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_site_search_engine_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_site_search_engine_service.py index ba20e4c7ac1a..996501b994ec 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_site_search_engine_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_site_search_engine_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -82,6 +82,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -112,6 +135,291 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SiteSearchEngineServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SiteSearchEngineServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SiteSearchEngineServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SiteSearchEngineServiceClient._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 SiteSearchEngineServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SiteSearchEngineServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SiteSearchEngineServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SiteSearchEngineServiceClient._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 SiteSearchEngineServiceClient._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 SiteSearchEngineServiceClient._get_client_cert_source(None, False) is None + assert ( + SiteSearchEngineServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + SiteSearchEngineServiceClient._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 ( + SiteSearchEngineServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SiteSearchEngineServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SiteSearchEngineServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SiteSearchEngineServiceClient), +) +@mock.patch.object( + SiteSearchEngineServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SiteSearchEngineServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SiteSearchEngineServiceClient._DEFAULT_UNIVERSE + default_endpoint = SiteSearchEngineServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SiteSearchEngineServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SiteSearchEngineServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SiteSearchEngineServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SiteSearchEngineServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SiteSearchEngineServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + SiteSearchEngineServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == SiteSearchEngineServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SiteSearchEngineServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SiteSearchEngineServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SiteSearchEngineServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + SiteSearchEngineServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SiteSearchEngineServiceClient._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 ( + SiteSearchEngineServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SiteSearchEngineServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SiteSearchEngineServiceClient._get_universe_domain(None, None) + == SiteSearchEngineServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SiteSearchEngineServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + SiteSearchEngineServiceClient, + transports.SiteSearchEngineServiceGrpcTransport, + "grpc", + ), + ( + SiteSearchEngineServiceClient, + transports.SiteSearchEngineServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -123,7 +431,7 @@ def test__get_default_mtls_endpoint(): def test_site_search_engine_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -177,7 +485,7 @@ def test_site_search_engine_service_client_service_account_always_use_jwt( def test_site_search_engine_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -235,20 +543,22 @@ def test_site_search_engine_service_client_get_transport_class(): ) @mock.patch.object( SiteSearchEngineServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SiteSearchEngineServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SiteSearchEngineServiceClient), ) @mock.patch.object( SiteSearchEngineServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SiteSearchEngineServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SiteSearchEngineServiceAsyncClient), ) def test_site_search_engine_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SiteSearchEngineServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -283,7 +593,9 @@ def test_site_search_engine_service_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, @@ -313,15 +625,23 @@ def test_site_search_engine_service_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") @@ -331,7 +651,9 @@ def test_site_search_engine_service_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", @@ -349,7 +671,9 @@ def test_site_search_engine_service_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, @@ -402,13 +726,13 @@ def test_site_search_engine_service_client_client_options( ) @mock.patch.object( SiteSearchEngineServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SiteSearchEngineServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SiteSearchEngineServiceClient), ) @mock.patch.object( SiteSearchEngineServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SiteSearchEngineServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SiteSearchEngineServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_site_search_engine_service_client_mtls_env_auto( @@ -431,7 +755,9 @@ def test_site_search_engine_service_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 @@ -463,7 +789,9 @@ def test_site_search_engine_service_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 @@ -497,7 +825,9 @@ def test_site_search_engine_service_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, @@ -589,6 +919,118 @@ def test_site_search_engine_service_client_get_mtls_endpoint_and_cert_source( 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", [SiteSearchEngineServiceClient, SiteSearchEngineServiceAsyncClient] +) +@mock.patch.object( + SiteSearchEngineServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SiteSearchEngineServiceClient), +) +@mock.patch.object( + SiteSearchEngineServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SiteSearchEngineServiceAsyncClient), +) +def test_site_search_engine_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SiteSearchEngineServiceClient._DEFAULT_UNIVERSE + default_endpoint = SiteSearchEngineServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SiteSearchEngineServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -623,7 +1065,9 @@ def test_site_search_engine_service_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, @@ -668,7 +1112,9 @@ def test_site_search_engine_service_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, @@ -728,7 +1174,9 @@ def test_site_search_engine_service_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, @@ -745,8 +1193,8 @@ def test_site_search_engine_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -775,7 +1223,7 @@ def test_site_search_engine_service_client_create_channel_credentials_file( ) def test_get_site_search_engine(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -807,7 +1255,7 @@ def test_get_site_search_engine_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -827,7 +1275,7 @@ async def test_get_site_search_engine_async( request_type=site_search_engine_service.GetSiteSearchEngineRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -864,7 +1312,7 @@ async def test_get_site_search_engine_async_from_dict(): def test_get_site_search_engine_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -896,7 +1344,7 @@ def test_get_site_search_engine_field_headers(): @pytest.mark.asyncio async def test_get_site_search_engine_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -929,7 +1377,7 @@ async def test_get_site_search_engine_field_headers_async(): def test_get_site_search_engine_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -955,7 +1403,7 @@ def test_get_site_search_engine_flattened(): def test_get_site_search_engine_flattened_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -970,7 +1418,7 @@ def test_get_site_search_engine_flattened_error(): @pytest.mark.asyncio async def test_get_site_search_engine_flattened_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1001,7 +1449,7 @@ async def test_get_site_search_engine_flattened_async(): @pytest.mark.asyncio async def test_get_site_search_engine_flattened_error_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1022,7 +1470,7 @@ async def test_get_site_search_engine_flattened_error_async(): ) def test_create_target_site(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1051,7 +1499,7 @@ def test_create_target_site_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1071,7 +1519,7 @@ async def test_create_target_site_async( request_type=site_search_engine_service.CreateTargetSiteRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1105,7 +1553,7 @@ async def test_create_target_site_async_from_dict(): def test_create_target_site_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1137,7 +1585,7 @@ def test_create_target_site_field_headers(): @pytest.mark.asyncio async def test_create_target_site_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1170,7 +1618,7 @@ async def test_create_target_site_field_headers_async(): def test_create_target_site_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1200,7 +1648,7 @@ def test_create_target_site_flattened(): def test_create_target_site_flattened_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1216,7 +1664,7 @@ def test_create_target_site_flattened_error(): @pytest.mark.asyncio async def test_create_target_site_flattened_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1251,7 +1699,7 @@ async def test_create_target_site_flattened_async(): @pytest.mark.asyncio async def test_create_target_site_flattened_error_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1273,7 +1721,7 @@ async def test_create_target_site_flattened_error_async(): ) def test_batch_create_target_sites(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1302,7 +1750,7 @@ def test_batch_create_target_sites_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1322,7 +1770,7 @@ async def test_batch_create_target_sites_async( request_type=site_search_engine_service.BatchCreateTargetSitesRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1356,7 +1804,7 @@ async def test_batch_create_target_sites_async_from_dict(): def test_batch_create_target_sites_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1388,7 +1836,7 @@ def test_batch_create_target_sites_field_headers(): @pytest.mark.asyncio async def test_batch_create_target_sites_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1428,7 +1876,7 @@ async def test_batch_create_target_sites_field_headers_async(): ) def test_get_target_site(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1470,7 +1918,7 @@ def test_get_target_site_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1488,7 +1936,7 @@ async def test_get_target_site_async( request_type=site_search_engine_service.GetTargetSiteRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1535,7 +1983,7 @@ async def test_get_target_site_async_from_dict(): def test_get_target_site_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1565,7 +2013,7 @@ def test_get_target_site_field_headers(): @pytest.mark.asyncio async def test_get_target_site_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1596,7 +2044,7 @@ async def test_get_target_site_field_headers_async(): def test_get_target_site_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1620,7 +2068,7 @@ def test_get_target_site_flattened(): def test_get_target_site_flattened_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1635,7 +2083,7 @@ def test_get_target_site_flattened_error(): @pytest.mark.asyncio async def test_get_target_site_flattened_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1664,7 +2112,7 @@ async def test_get_target_site_flattened_async(): @pytest.mark.asyncio async def test_get_target_site_flattened_error_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1685,7 +2133,7 @@ async def test_get_target_site_flattened_error_async(): ) def test_update_target_site(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1714,7 +2162,7 @@ def test_update_target_site_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1734,7 +2182,7 @@ async def test_update_target_site_async( request_type=site_search_engine_service.UpdateTargetSiteRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1768,7 +2216,7 @@ async def test_update_target_site_async_from_dict(): def test_update_target_site_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1800,7 +2248,7 @@ def test_update_target_site_field_headers(): @pytest.mark.asyncio async def test_update_target_site_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1833,7 +2281,7 @@ async def test_update_target_site_field_headers_async(): def test_update_target_site_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1859,7 +2307,7 @@ def test_update_target_site_flattened(): def test_update_target_site_flattened_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1874,7 +2322,7 @@ def test_update_target_site_flattened_error(): @pytest.mark.asyncio async def test_update_target_site_flattened_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1905,7 +2353,7 @@ async def test_update_target_site_flattened_async(): @pytest.mark.asyncio async def test_update_target_site_flattened_error_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1926,7 +2374,7 @@ async def test_update_target_site_flattened_error_async(): ) def test_delete_target_site(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1955,7 +2403,7 @@ def test_delete_target_site_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1975,7 +2423,7 @@ async def test_delete_target_site_async( request_type=site_search_engine_service.DeleteTargetSiteRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2009,7 +2457,7 @@ async def test_delete_target_site_async_from_dict(): def test_delete_target_site_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2041,7 +2489,7 @@ def test_delete_target_site_field_headers(): @pytest.mark.asyncio async def test_delete_target_site_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2074,7 +2522,7 @@ async def test_delete_target_site_field_headers_async(): def test_delete_target_site_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2100,7 +2548,7 @@ def test_delete_target_site_flattened(): def test_delete_target_site_flattened_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2115,7 +2563,7 @@ def test_delete_target_site_flattened_error(): @pytest.mark.asyncio async def test_delete_target_site_flattened_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2146,7 +2594,7 @@ async def test_delete_target_site_flattened_async(): @pytest.mark.asyncio async def test_delete_target_site_flattened_error_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2167,7 +2615,7 @@ async def test_delete_target_site_flattened_error_async(): ) def test_list_target_sites(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2201,7 +2649,7 @@ def test_list_target_sites_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2221,7 +2669,7 @@ async def test_list_target_sites_async( request_type=site_search_engine_service.ListTargetSitesRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2260,7 +2708,7 @@ async def test_list_target_sites_async_from_dict(): def test_list_target_sites_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2292,7 +2740,7 @@ def test_list_target_sites_field_headers(): @pytest.mark.asyncio async def test_list_target_sites_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2325,7 +2773,7 @@ async def test_list_target_sites_field_headers_async(): def test_list_target_sites_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2351,7 +2799,7 @@ def test_list_target_sites_flattened(): def test_list_target_sites_flattened_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2366,7 +2814,7 @@ def test_list_target_sites_flattened_error(): @pytest.mark.asyncio async def test_list_target_sites_flattened_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2397,7 +2845,7 @@ async def test_list_target_sites_flattened_async(): @pytest.mark.asyncio async def test_list_target_sites_flattened_error_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2411,7 +2859,7 @@ async def test_list_target_sites_flattened_error_async(): def test_list_target_sites_pager(transport_name: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2463,7 +2911,7 @@ def test_list_target_sites_pager(transport_name: str = "grpc"): def test_list_target_sites_pages(transport_name: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2507,7 +2955,7 @@ def test_list_target_sites_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_target_sites_async_pager(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2559,7 +3007,7 @@ async def test_list_target_sites_async_pager(): @pytest.mark.asyncio async def test_list_target_sites_async_pages(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2616,7 +3064,7 @@ async def test_list_target_sites_async_pages(): ) def test_enable_advanced_site_search(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2645,7 +3093,7 @@ def test_enable_advanced_site_search_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2665,7 +3113,7 @@ async def test_enable_advanced_site_search_async( request_type=site_search_engine_service.EnableAdvancedSiteSearchRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2699,7 +3147,7 @@ async def test_enable_advanced_site_search_async_from_dict(): def test_enable_advanced_site_search_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2731,7 +3179,7 @@ def test_enable_advanced_site_search_field_headers(): @pytest.mark.asyncio async def test_enable_advanced_site_search_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2771,7 +3219,7 @@ async def test_enable_advanced_site_search_field_headers_async(): ) def test_disable_advanced_site_search(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2800,7 +3248,7 @@ def test_disable_advanced_site_search_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2820,7 +3268,7 @@ async def test_disable_advanced_site_search_async( request_type=site_search_engine_service.DisableAdvancedSiteSearchRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2854,7 +3302,7 @@ async def test_disable_advanced_site_search_async_from_dict(): def test_disable_advanced_site_search_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2886,7 +3334,7 @@ def test_disable_advanced_site_search_field_headers(): @pytest.mark.asyncio async def test_disable_advanced_site_search_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2926,7 +3374,7 @@ async def test_disable_advanced_site_search_field_headers_async(): ) def test_recrawl_uris(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2953,7 +3401,7 @@ def test_recrawl_uris_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2971,7 +3419,7 @@ async def test_recrawl_uris_async( request_type=site_search_engine_service.RecrawlUrisRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3003,7 +3451,7 @@ async def test_recrawl_uris_async_from_dict(): def test_recrawl_uris_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3033,7 +3481,7 @@ def test_recrawl_uris_field_headers(): @pytest.mark.asyncio async def test_recrawl_uris_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3071,7 +3519,7 @@ async def test_recrawl_uris_field_headers_async(): ) def test_batch_verify_target_sites(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3100,7 +3548,7 @@ def test_batch_verify_target_sites_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3120,7 +3568,7 @@ async def test_batch_verify_target_sites_async( request_type=site_search_engine_service.BatchVerifyTargetSitesRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3154,7 +3602,7 @@ async def test_batch_verify_target_sites_async_from_dict(): def test_batch_verify_target_sites_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3186,7 +3634,7 @@ def test_batch_verify_target_sites_field_headers(): @pytest.mark.asyncio async def test_batch_verify_target_sites_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3226,7 +3674,7 @@ async def test_batch_verify_target_sites_field_headers_async(): ) def test_fetch_domain_verification_status(request_type, transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3264,7 +3712,7 @@ def test_fetch_domain_verification_status_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3286,7 +3734,7 @@ async def test_fetch_domain_verification_status_async( request_type=site_search_engine_service.FetchDomainVerificationStatusRequest, ): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3327,7 +3775,7 @@ async def test_fetch_domain_verification_status_async_from_dict(): def test_fetch_domain_verification_status_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3361,7 +3809,7 @@ def test_fetch_domain_verification_status_field_headers(): @pytest.mark.asyncio async def test_fetch_domain_verification_status_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3394,7 +3842,7 @@ async def test_fetch_domain_verification_status_field_headers_async(): def test_fetch_domain_verification_status_pager(transport_name: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3446,7 +3894,7 @@ def test_fetch_domain_verification_status_pager(transport_name: str = "grpc"): def test_fetch_domain_verification_status_pages(transport_name: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3490,7 +3938,7 @@ def test_fetch_domain_verification_status_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_fetch_domain_verification_status_async_pager(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3542,7 +3990,7 @@ async def test_fetch_domain_verification_status_async_pager(): @pytest.mark.asyncio async def test_fetch_domain_verification_status_async_pages(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3599,7 +4047,7 @@ async def test_fetch_domain_verification_status_async_pages(): ) def test_get_site_search_engine_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3652,7 +4100,7 @@ def test_get_site_search_engine_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_site_search_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3661,7 +4109,7 @@ def test_get_site_search_engine_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_site_search_engine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3670,7 +4118,7 @@ def test_get_site_search_engine_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3712,7 +4160,7 @@ def test_get_site_search_engine_rest_required_fields( def test_get_site_search_engine_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_site_search_engine._get_unset_required_fields({}) @@ -3722,7 +4170,7 @@ def test_get_site_search_engine_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_site_search_engine_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -3781,7 +4229,7 @@ def test_get_site_search_engine_rest_bad_request( request_type=site_search_engine_service.GetSiteSearchEngineRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3805,7 +4253,7 @@ def test_get_site_search_engine_rest_bad_request( def test_get_site_search_engine_rest_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3849,7 +4297,7 @@ def test_get_site_search_engine_rest_flattened(): def test_get_site_search_engine_rest_flattened_error(transport: str = "rest"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3864,7 +4312,7 @@ def test_get_site_search_engine_rest_flattened_error(transport: str = "rest"): def test_get_site_search_engine_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3877,7 +4325,7 @@ def test_get_site_search_engine_rest_error(): ) def test_create_target_site_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4008,7 +4456,7 @@ def test_create_target_site_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_target_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4017,7 +4465,7 @@ def test_create_target_site_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_target_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4026,7 +4474,7 @@ def test_create_target_site_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4066,7 +4514,7 @@ def test_create_target_site_rest_required_fields( def test_create_target_site_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_target_site._get_unset_required_fields({}) @@ -4084,7 +4532,7 @@ def test_create_target_site_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_target_site_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -4145,7 +4593,7 @@ def test_create_target_site_rest_bad_request( request_type=site_search_engine_service.CreateTargetSiteRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4169,7 +4617,7 @@ def test_create_target_site_rest_bad_request( def test_create_target_site_rest_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4212,7 +4660,7 @@ def test_create_target_site_rest_flattened(): def test_create_target_site_rest_flattened_error(transport: str = "rest"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4228,7 +4676,7 @@ def test_create_target_site_rest_flattened_error(transport: str = "rest"): def test_create_target_site_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4241,7 +4689,7 @@ def test_create_target_site_rest_error(): ) def test_batch_create_target_sites_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4289,7 +4737,7 @@ def test_batch_create_target_sites_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_create_target_sites._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4298,7 +4746,7 @@ def test_batch_create_target_sites_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_create_target_sites._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4307,7 +4755,7 @@ def test_batch_create_target_sites_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4347,7 +4795,7 @@ def test_batch_create_target_sites_rest_required_fields( def test_batch_create_target_sites_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_create_target_sites._get_unset_required_fields({}) @@ -4365,7 +4813,7 @@ def test_batch_create_target_sites_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_create_target_sites_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -4428,7 +4876,7 @@ def test_batch_create_target_sites_rest_bad_request( request_type=site_search_engine_service.BatchCreateTargetSitesRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4452,7 +4900,7 @@ def test_batch_create_target_sites_rest_bad_request( def test_batch_create_target_sites_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4465,7 +4913,7 @@ def test_batch_create_target_sites_rest_error(): ) def test_get_target_site_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4530,7 +4978,7 @@ def test_get_target_site_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_target_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4539,7 +4987,7 @@ def test_get_target_site_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_target_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4548,7 +4996,7 @@ def test_get_target_site_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4590,7 +5038,7 @@ def test_get_target_site_rest_required_fields( def test_get_target_site_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_target_site._get_unset_required_fields({}) @@ -4600,7 +5048,7 @@ def test_get_target_site_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_target_site_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -4659,7 +5107,7 @@ def test_get_target_site_rest_bad_request( request_type=site_search_engine_service.GetTargetSiteRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4683,7 +5131,7 @@ def test_get_target_site_rest_bad_request( def test_get_target_site_rest_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4727,7 +5175,7 @@ def test_get_target_site_rest_flattened(): def test_get_target_site_rest_flattened_error(transport: str = "rest"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4742,7 +5190,7 @@ def test_get_target_site_rest_flattened_error(transport: str = "rest"): def test_get_target_site_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4755,7 +5203,7 @@ def test_get_target_site_rest_error(): ) def test_update_target_site_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4887,21 +5335,21 @@ def test_update_target_site_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_target_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_target_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4941,7 +5389,7 @@ def test_update_target_site_rest_required_fields( def test_update_target_site_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_target_site._get_unset_required_fields({}) @@ -4951,7 +5399,7 @@ def test_update_target_site_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_target_site_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -5012,7 +5460,7 @@ def test_update_target_site_rest_bad_request( request_type=site_search_engine_service.UpdateTargetSiteRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5038,7 +5486,7 @@ def test_update_target_site_rest_bad_request( def test_update_target_site_rest_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5082,7 +5530,7 @@ def test_update_target_site_rest_flattened(): def test_update_target_site_rest_flattened_error(transport: str = "rest"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5097,7 +5545,7 @@ def test_update_target_site_rest_flattened_error(transport: str = "rest"): def test_update_target_site_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5110,7 +5558,7 @@ def test_update_target_site_rest_error(): ) def test_delete_target_site_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5158,7 +5606,7 @@ def test_delete_target_site_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_target_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5167,7 +5615,7 @@ def test_delete_target_site_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_target_site._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5176,7 +5624,7 @@ def test_delete_target_site_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5215,7 +5663,7 @@ def test_delete_target_site_rest_required_fields( def test_delete_target_site_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_target_site._get_unset_required_fields({}) @@ -5225,7 +5673,7 @@ def test_delete_target_site_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_target_site_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -5286,7 +5734,7 @@ def test_delete_target_site_rest_bad_request( request_type=site_search_engine_service.DeleteTargetSiteRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5310,7 +5758,7 @@ def test_delete_target_site_rest_bad_request( def test_delete_target_site_rest_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5352,7 +5800,7 @@ def test_delete_target_site_rest_flattened(): def test_delete_target_site_rest_flattened_error(transport: str = "rest"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5367,7 +5815,7 @@ def test_delete_target_site_rest_flattened_error(transport: str = "rest"): def test_delete_target_site_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5380,7 +5828,7 @@ def test_delete_target_site_rest_error(): ) def test_list_target_sites_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5437,7 +5885,7 @@ def test_list_target_sites_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_target_sites._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5446,7 +5894,7 @@ def test_list_target_sites_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_target_sites._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5462,7 +5910,7 @@ def test_list_target_sites_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5506,7 +5954,7 @@ def test_list_target_sites_rest_required_fields( def test_list_target_sites_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_target_sites._get_unset_required_fields({}) @@ -5524,7 +5972,7 @@ def test_list_target_sites_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_target_sites_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -5585,7 +6033,7 @@ def test_list_target_sites_rest_bad_request( request_type=site_search_engine_service.ListTargetSitesRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5609,7 +6057,7 @@ def test_list_target_sites_rest_bad_request( def test_list_target_sites_rest_flattened(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5655,7 +6103,7 @@ def test_list_target_sites_rest_flattened(): def test_list_target_sites_rest_flattened_error(transport: str = "rest"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5670,7 +6118,7 @@ def test_list_target_sites_rest_flattened_error(transport: str = "rest"): def test_list_target_sites_rest_pager(transport: str = "rest"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5743,7 +6191,7 @@ def test_list_target_sites_rest_pager(transport: str = "rest"): ) def test_enable_advanced_site_search_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5791,7 +6239,7 @@ def test_enable_advanced_site_search_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).enable_advanced_site_search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5800,7 +6248,7 @@ def test_enable_advanced_site_search_rest_required_fields( jsonified_request["siteSearchEngine"] = "site_search_engine_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).enable_advanced_site_search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5809,7 +6257,7 @@ def test_enable_advanced_site_search_rest_required_fields( assert jsonified_request["siteSearchEngine"] == "site_search_engine_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5849,7 +6297,7 @@ def test_enable_advanced_site_search_rest_required_fields( def test_enable_advanced_site_search_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.enable_advanced_site_search._get_unset_required_fields({}) @@ -5859,7 +6307,7 @@ def test_enable_advanced_site_search_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_enable_advanced_site_search_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -5922,7 +6370,7 @@ def test_enable_advanced_site_search_rest_bad_request( request_type=site_search_engine_service.EnableAdvancedSiteSearchRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5946,7 +6394,7 @@ def test_enable_advanced_site_search_rest_bad_request( def test_enable_advanced_site_search_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5959,7 +6407,7 @@ def test_enable_advanced_site_search_rest_error(): ) def test_disable_advanced_site_search_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6007,7 +6455,7 @@ def test_disable_advanced_site_search_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).disable_advanced_site_search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6016,7 +6464,7 @@ def test_disable_advanced_site_search_rest_required_fields( jsonified_request["siteSearchEngine"] = "site_search_engine_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).disable_advanced_site_search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6025,7 +6473,7 @@ def test_disable_advanced_site_search_rest_required_fields( assert jsonified_request["siteSearchEngine"] == "site_search_engine_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6065,7 +6513,7 @@ def test_disable_advanced_site_search_rest_required_fields( def test_disable_advanced_site_search_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.disable_advanced_site_search._get_unset_required_fields({}) @@ -6075,7 +6523,7 @@ def test_disable_advanced_site_search_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_disable_advanced_site_search_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -6138,7 +6586,7 @@ def test_disable_advanced_site_search_rest_bad_request( request_type=site_search_engine_service.DisableAdvancedSiteSearchRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6162,7 +6610,7 @@ def test_disable_advanced_site_search_rest_bad_request( def test_disable_advanced_site_search_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6175,7 +6623,7 @@ def test_disable_advanced_site_search_rest_error(): ) def test_recrawl_uris_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6224,7 +6672,7 @@ def test_recrawl_uris_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).recrawl_uris._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6234,7 +6682,7 @@ def test_recrawl_uris_rest_required_fields( jsonified_request["uris"] = "uris_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).recrawl_uris._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6245,7 +6693,7 @@ def test_recrawl_uris_rest_required_fields( assert jsonified_request["uris"] == "uris_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6285,7 +6733,7 @@ def test_recrawl_uris_rest_required_fields( def test_recrawl_uris_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.recrawl_uris._get_unset_required_fields({}) @@ -6303,7 +6751,7 @@ def test_recrawl_uris_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_recrawl_uris_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -6363,7 +6811,7 @@ def test_recrawl_uris_rest_bad_request( transport: str = "rest", request_type=site_search_engine_service.RecrawlUrisRequest ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6387,7 +6835,7 @@ def test_recrawl_uris_rest_bad_request( def test_recrawl_uris_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6400,7 +6848,7 @@ def test_recrawl_uris_rest_error(): ) def test_batch_verify_target_sites_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6448,7 +6896,7 @@ def test_batch_verify_target_sites_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_verify_target_sites._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6457,7 +6905,7 @@ def test_batch_verify_target_sites_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_verify_target_sites._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6466,7 +6914,7 @@ def test_batch_verify_target_sites_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6506,7 +6954,7 @@ def test_batch_verify_target_sites_rest_required_fields( def test_batch_verify_target_sites_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_verify_target_sites._get_unset_required_fields({}) @@ -6516,7 +6964,7 @@ def test_batch_verify_target_sites_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_verify_target_sites_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -6579,7 +7027,7 @@ def test_batch_verify_target_sites_rest_bad_request( request_type=site_search_engine_service.BatchVerifyTargetSitesRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6603,7 +7051,7 @@ def test_batch_verify_target_sites_rest_bad_request( def test_batch_verify_target_sites_rest_error(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6616,7 +7064,7 @@ def test_batch_verify_target_sites_rest_error(): ) def test_fetch_domain_verification_status_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6675,7 +7123,7 @@ def test_fetch_domain_verification_status_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).fetch_domain_verification_status._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6684,7 +7132,7 @@ def test_fetch_domain_verification_status_rest_required_fields( jsonified_request["siteSearchEngine"] = "site_search_engine_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).fetch_domain_verification_status._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6700,7 +7148,7 @@ def test_fetch_domain_verification_status_rest_required_fields( assert jsonified_request["siteSearchEngine"] == "site_search_engine_value" client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6746,7 +7194,7 @@ def test_fetch_domain_verification_status_rest_required_fields( def test_fetch_domain_verification_status_rest_unset_required_fields(): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -6766,7 +7214,7 @@ def test_fetch_domain_verification_status_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_fetch_domain_verification_status_rest_interceptors(null_interceptor): transport = transports.SiteSearchEngineServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SiteSearchEngineServiceRestInterceptor(), @@ -6831,7 +7279,7 @@ def test_fetch_domain_verification_status_rest_bad_request( request_type=site_search_engine_service.FetchDomainVerificationStatusRequest, ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6855,7 +7303,7 @@ def test_fetch_domain_verification_status_rest_bad_request( def test_fetch_domain_verification_status_rest_pager(transport: str = "rest"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6924,17 +7372,17 @@ def test_fetch_domain_verification_status_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SiteSearchEngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SiteSearchEngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SiteSearchEngineServiceClient( @@ -6944,7 +7392,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SiteSearchEngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -6955,16 +7403,17 @@ 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 = SiteSearchEngineServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SiteSearchEngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SiteSearchEngineServiceClient( @@ -6976,7 +7425,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SiteSearchEngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SiteSearchEngineServiceClient(transport=transport) assert client.transport is transport @@ -6985,13 +7434,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SiteSearchEngineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SiteSearchEngineServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -7008,7 +7457,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -7022,7 +7471,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SiteSearchEngineServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -7030,7 +7479,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -7042,7 +7491,7 @@ def test_site_search_engine_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SiteSearchEngineServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -7054,7 +7503,7 @@ def test_site_search_engine_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SiteSearchEngineServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -7104,7 +7553,7 @@ def test_site_search_engine_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SiteSearchEngineServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -7123,7 +7572,7 @@ def test_site_search_engine_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.site_search_engine_service.transports.SiteSearchEngineServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SiteSearchEngineServiceTransport() adc.assert_called_once() @@ -7131,7 +7580,7 @@ def test_site_search_engine_service_base_transport_with_adc(): def test_site_search_engine_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SiteSearchEngineServiceClient() adc.assert_called_once_with( scopes=None, @@ -7151,7 +7600,7 @@ def test_site_search_engine_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -7200,7 +7649,7 @@ def test_site_search_engine_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7230,7 +7679,7 @@ def test_site_search_engine_service_transport_create_channel( def test_site_search_engine_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -7268,7 +7717,7 @@ def test_site_search_engine_service_grpc_transport_client_cert_source_for_mtls( def test_site_search_engine_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -7280,7 +7729,7 @@ def test_site_search_engine_service_http_transport_client_cert_source_for_mtls() def test_site_search_engine_service_rest_lro_client(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -7305,7 +7754,7 @@ def test_site_search_engine_service_rest_lro_client(): ) def test_site_search_engine_service_host_no_port(transport_name): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -7328,7 +7777,7 @@ def test_site_search_engine_service_host_no_port(transport_name): ) def test_site_search_engine_service_host_with_port(transport_name): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -7348,8 +7797,8 @@ def test_site_search_engine_service_host_with_port(transport_name): ], ) def test_site_search_engine_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SiteSearchEngineServiceClient( credentials=creds1, transport=transport_name, @@ -7446,7 +7895,7 @@ def test_site_search_engine_service_transport_channel_mtls_with_client_cert_sour mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -7524,7 +7973,7 @@ def test_site_search_engine_service_transport_channel_mtls_with_adc(transport_cl def test_site_search_engine_service_grpc_lro_client(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -7541,7 +7990,7 @@ def test_site_search_engine_service_grpc_lro_client(): def test_site_search_engine_service_grpc_lro_async_client(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -7725,7 +8174,7 @@ def test_client_with_default_client_info(): transports.SiteSearchEngineServiceTransport, "_prep_wrapped_messages" ) as prep: client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7735,7 +8184,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SiteSearchEngineServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7744,7 +8193,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -7759,7 +8208,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7792,7 +8241,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -7822,7 +8271,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7855,7 +8304,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -7883,7 +8332,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7908,7 +8357,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7934,7 +8383,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7963,7 +8412,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7992,7 +8441,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -8010,7 +8459,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -8028,7 +8477,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8053,7 +8502,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8079,7 +8528,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8108,7 +8557,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8137,7 +8586,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -8155,7 +8604,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SiteSearchEngineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -8179,7 +8628,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -8196,7 +8645,7 @@ def test_client_ctx(): ] for transport in transports: client = SiteSearchEngineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -8233,7 +8682,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_user_event_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_user_event_service.py index 6f39a4a65030..f9d38085551d 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_user_event_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1alpha/test_user_event_service.py @@ -36,7 +36,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -87,6 +87,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -117,6 +140,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert UserEventServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert UserEventServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert UserEventServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + UserEventServiceClient._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 UserEventServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert UserEventServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert UserEventServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + UserEventServiceClient._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 UserEventServiceClient._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 UserEventServiceClient._get_client_cert_source(None, False) is None + assert ( + UserEventServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + UserEventServiceClient._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 ( + UserEventServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + UserEventServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + UserEventServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), +) +@mock.patch.object( + UserEventServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = UserEventServiceClient._DEFAULT_UNIVERSE + default_endpoint = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + UserEventServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + UserEventServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, default_universe, "always") + == UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + UserEventServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + UserEventServiceClient._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 ( + UserEventServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + UserEventServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + UserEventServiceClient._get_universe_domain(None, None) + == UserEventServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + UserEventServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (UserEventServiceClient, transports.UserEventServiceGrpcTransport, "grpc"), + (UserEventServiceClient, transports.UserEventServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -128,7 +412,7 @@ def test__get_default_mtls_endpoint(): def test_user_event_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -182,7 +466,7 @@ def test_user_event_service_client_service_account_always_use_jwt( def test_user_event_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -232,20 +516,22 @@ def test_user_event_service_client_get_transport_class(): ) @mock.patch.object( UserEventServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), ) @mock.patch.object( UserEventServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), ) def test_user_event_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(UserEventServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -280,7 +566,9 @@ def test_user_event_service_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, @@ -310,15 +598,23 @@ def test_user_event_service_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") @@ -328,7 +624,9 @@ def test_user_event_service_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", @@ -346,7 +644,9 @@ def test_user_event_service_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, @@ -399,13 +699,13 @@ def test_user_event_service_client_client_options( ) @mock.patch.object( UserEventServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), ) @mock.patch.object( UserEventServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_user_event_service_client_mtls_env_auto( @@ -428,7 +728,9 @@ def test_user_event_service_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 @@ -460,7 +762,9 @@ def test_user_event_service_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 @@ -494,7 +798,9 @@ def test_user_event_service_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, @@ -584,6 +890,118 @@ def test_user_event_service_client_get_mtls_endpoint_and_cert_source(client_clas 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", [UserEventServiceClient, UserEventServiceAsyncClient] +) +@mock.patch.object( + UserEventServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), +) +@mock.patch.object( + UserEventServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), +) +def test_user_event_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = UserEventServiceClient._DEFAULT_UNIVERSE + default_endpoint = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = UserEventServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -610,7 +1028,9 @@ def test_user_event_service_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, @@ -655,7 +1075,9 @@ def test_user_event_service_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, @@ -715,7 +1137,9 @@ def test_user_event_service_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, @@ -732,8 +1156,8 @@ def test_user_event_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -762,7 +1186,7 @@ def test_user_event_service_client_create_channel_credentials_file( ) def test_write_user_event(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -806,7 +1230,7 @@ def test_write_user_event_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -824,7 +1248,7 @@ async def test_write_user_event_async( request_type=user_event_service.WriteUserEventRequest, ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -873,7 +1297,7 @@ async def test_write_user_event_async_from_dict(): def test_write_user_event_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -903,7 +1327,7 @@ def test_write_user_event_field_headers(): @pytest.mark.asyncio async def test_write_user_event_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -941,7 +1365,7 @@ async def test_write_user_event_field_headers_async(): ) def test_collect_user_event(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -975,7 +1399,7 @@ def test_collect_user_event_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -995,7 +1419,7 @@ async def test_collect_user_event_async( request_type=user_event_service.CollectUserEventRequest, ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1034,7 +1458,7 @@ async def test_collect_user_event_async_from_dict(): def test_collect_user_event_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1066,7 +1490,7 @@ def test_collect_user_event_field_headers(): @pytest.mark.asyncio async def test_collect_user_event_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1106,7 +1530,7 @@ async def test_collect_user_event_field_headers_async(): ) def test_purge_user_events(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1135,7 +1559,7 @@ def test_purge_user_events_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1154,7 +1578,7 @@ async def test_purge_user_events_async( transport: str = "grpc_asyncio", request_type=purge_config.PurgeUserEventsRequest ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1188,7 +1612,7 @@ async def test_purge_user_events_async_from_dict(): def test_purge_user_events_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1220,7 +1644,7 @@ def test_purge_user_events_field_headers(): @pytest.mark.asyncio async def test_purge_user_events_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1260,7 +1684,7 @@ async def test_purge_user_events_field_headers_async(): ) def test_import_user_events(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1289,7 +1713,7 @@ def test_import_user_events_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1308,7 +1732,7 @@ async def test_import_user_events_async( transport: str = "grpc_asyncio", request_type=import_config.ImportUserEventsRequest ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1342,7 +1766,7 @@ async def test_import_user_events_async_from_dict(): def test_import_user_events_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1374,7 +1798,7 @@ def test_import_user_events_field_headers(): @pytest.mark.asyncio async def test_import_user_events_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1414,7 +1838,7 @@ async def test_import_user_events_field_headers_async(): ) def test_write_user_event_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1601,7 +2025,7 @@ def test_write_user_event_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).write_user_event._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1610,7 +2034,7 @@ def test_write_user_event_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).write_user_event._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1619,7 +2043,7 @@ def test_write_user_event_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1662,7 +2086,7 @@ def test_write_user_event_rest_required_fields( def test_write_user_event_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.write_user_event._get_unset_required_fields({}) @@ -1680,7 +2104,7 @@ def test_write_user_event_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_write_user_event_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -1736,7 +2160,7 @@ def test_write_user_event_rest_bad_request( transport: str = "rest", request_type=user_event_service.WriteUserEventRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1758,7 +2182,7 @@ def test_write_user_event_rest_bad_request( def test_write_user_event_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -1771,7 +2195,7 @@ def test_write_user_event_rest_error(): ) def test_collect_user_event_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1824,7 +2248,7 @@ def test_collect_user_event_rest_required_fields( assert "userEvent" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).collect_user_event._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1836,7 +2260,7 @@ def test_collect_user_event_rest_required_fields( jsonified_request["userEvent"] = "user_event_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).collect_user_event._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -1855,7 +2279,7 @@ def test_collect_user_event_rest_required_fields( assert jsonified_request["userEvent"] == "user_event_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1901,7 +2325,7 @@ def test_collect_user_event_rest_required_fields( def test_collect_user_event_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.collect_user_event._get_unset_required_fields({}) @@ -1925,7 +2349,7 @@ def test_collect_user_event_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_collect_user_event_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -1981,7 +2405,7 @@ def test_collect_user_event_rest_bad_request( transport: str = "rest", request_type=user_event_service.CollectUserEventRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2003,7 +2427,7 @@ def test_collect_user_event_rest_bad_request( def test_collect_user_event_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2016,7 +2440,7 @@ def test_collect_user_event_rest_error(): ) def test_purge_user_events_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2063,7 +2487,7 @@ def test_purge_user_events_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).purge_user_events._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2073,7 +2497,7 @@ def test_purge_user_events_rest_required_fields( jsonified_request["filter"] = "filter_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).purge_user_events._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2084,7 +2508,7 @@ def test_purge_user_events_rest_required_fields( assert jsonified_request["filter"] == "filter_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2124,7 +2548,7 @@ def test_purge_user_events_rest_required_fields( def test_purge_user_events_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.purge_user_events._get_unset_required_fields({}) @@ -2142,7 +2566,7 @@ def test_purge_user_events_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_purge_user_events_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -2202,7 +2626,7 @@ def test_purge_user_events_rest_bad_request( transport: str = "rest", request_type=purge_config.PurgeUserEventsRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2224,7 +2648,7 @@ def test_purge_user_events_rest_bad_request( def test_purge_user_events_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2237,7 +2661,7 @@ def test_purge_user_events_rest_error(): ) def test_import_user_events_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2283,7 +2707,7 @@ def test_import_user_events_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_user_events._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2292,7 +2716,7 @@ def test_import_user_events_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_user_events._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2301,7 +2725,7 @@ def test_import_user_events_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2341,7 +2765,7 @@ def test_import_user_events_rest_required_fields( def test_import_user_events_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_user_events._get_unset_required_fields({}) @@ -2351,7 +2775,7 @@ def test_import_user_events_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_user_events_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -2411,7 +2835,7 @@ def test_import_user_events_rest_bad_request( transport: str = "rest", request_type=import_config.ImportUserEventsRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2433,24 +2857,24 @@ def test_import_user_events_rest_bad_request( def test_import_user_events_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = UserEventServiceClient( @@ -2460,7 +2884,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -2471,16 +2895,17 @@ 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 = UserEventServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = UserEventServiceClient( @@ -2492,7 +2917,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = UserEventServiceClient(transport=transport) assert client.transport is transport @@ -2501,13 +2926,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.UserEventServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -2524,7 +2949,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -2538,7 +2963,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = UserEventServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -2546,7 +2971,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -2558,7 +2983,7 @@ def test_user_event_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.UserEventServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -2570,7 +2995,7 @@ def test_user_event_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.UserEventServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -2612,7 +3037,7 @@ def test_user_event_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1alpha.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.UserEventServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2631,7 +3056,7 @@ def test_user_event_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1alpha.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.UserEventServiceTransport() adc.assert_called_once() @@ -2639,7 +3064,7 @@ def test_user_event_service_base_transport_with_adc(): def test_user_event_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) UserEventServiceClient() adc.assert_called_once_with( scopes=None, @@ -2659,7 +3084,7 @@ def test_user_event_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2706,7 +3131,7 @@ def test_user_event_service_transport_create_channel(transport_class, grpc_helpe ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2734,7 +3159,7 @@ def test_user_event_service_transport_create_channel(transport_class, grpc_helpe ], ) def test_user_event_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2772,7 +3197,7 @@ def test_user_event_service_grpc_transport_client_cert_source_for_mtls(transport def test_user_event_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -2784,7 +3209,7 @@ def test_user_event_service_http_transport_client_cert_source_for_mtls(): def test_user_event_service_rest_lro_client(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -2809,7 +3234,7 @@ def test_user_event_service_rest_lro_client(): ) def test_user_event_service_host_no_port(transport_name): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -2832,7 +3257,7 @@ def test_user_event_service_host_no_port(transport_name): ) def test_user_event_service_host_with_port(transport_name): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -2852,8 +3277,8 @@ def test_user_event_service_host_with_port(transport_name): ], ) def test_user_event_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = UserEventServiceClient( credentials=creds1, transport=transport_name, @@ -2926,7 +3351,7 @@ def test_user_event_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -3004,7 +3429,7 @@ def test_user_event_service_transport_channel_mtls_with_adc(transport_class): def test_user_event_service_grpc_lro_client(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -3021,7 +3446,7 @@ def test_user_event_service_grpc_lro_client(): def test_user_event_service_grpc_lro_async_client(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -3206,7 +3631,7 @@ def test_client_with_default_client_info(): transports.UserEventServiceTransport, "_prep_wrapped_messages" ) as prep: client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3216,7 +3641,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = UserEventServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3225,7 +3650,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -3240,7 +3665,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3273,7 +3698,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -3303,7 +3728,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3336,7 +3761,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -3364,7 +3789,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3389,7 +3814,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3415,7 +3840,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3444,7 +3869,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3473,7 +3898,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3491,7 +3916,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3509,7 +3934,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3534,7 +3959,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3560,7 +3985,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3589,7 +4014,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3618,7 +4043,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3636,7 +4061,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3660,7 +4085,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3677,7 +4102,7 @@ def test_client_ctx(): ] for transport in transports: client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3708,7 +4133,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_completion_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_completion_service.py index 730359445681..3f9718d7fdb1 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_completion_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_completion_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -67,6 +67,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -97,6 +120,275 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert CompletionServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + CompletionServiceClient._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 CompletionServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert CompletionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + CompletionServiceClient._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 CompletionServiceClient._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 CompletionServiceClient._get_client_cert_source(None, False) is None + assert ( + CompletionServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + CompletionServiceClient._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 ( + CompletionServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + CompletionServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + CompletionServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), +) +@mock.patch.object( + CompletionServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = CompletionServiceClient._DEFAULT_UNIVERSE + default_endpoint = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + CompletionServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + CompletionServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CompletionServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + CompletionServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CompletionServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == CompletionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CompletionServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + CompletionServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + CompletionServiceClient._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 ( + CompletionServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + CompletionServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + CompletionServiceClient._get_universe_domain(None, None) + == CompletionServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + CompletionServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (CompletionServiceClient, transports.CompletionServiceGrpcTransport, "grpc"), + (CompletionServiceClient, transports.CompletionServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -108,7 +400,7 @@ def test__get_default_mtls_endpoint(): def test_completion_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -162,7 +454,7 @@ def test_completion_service_client_service_account_always_use_jwt( def test_completion_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -212,20 +504,22 @@ def test_completion_service_client_get_transport_class(): ) @mock.patch.object( CompletionServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), ) @mock.patch.object( CompletionServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), ) def test_completion_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CompletionServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -260,7 +554,9 @@ def test_completion_service_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, @@ -290,15 +586,23 @@ def test_completion_service_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") @@ -308,7 +612,9 @@ def test_completion_service_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", @@ -326,7 +632,9 @@ def test_completion_service_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, @@ -379,13 +687,13 @@ def test_completion_service_client_client_options( ) @mock.patch.object( CompletionServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), ) @mock.patch.object( CompletionServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CompletionServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_completion_service_client_mtls_env_auto( @@ -408,7 +716,9 @@ def test_completion_service_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 @@ -440,7 +750,9 @@ def test_completion_service_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 @@ -474,7 +786,9 @@ def test_completion_service_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, @@ -564,6 +878,118 @@ def test_completion_service_client_get_mtls_endpoint_and_cert_source(client_clas 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", [CompletionServiceClient, CompletionServiceAsyncClient] +) +@mock.patch.object( + CompletionServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceClient), +) +@mock.patch.object( + CompletionServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CompletionServiceAsyncClient), +) +def test_completion_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = CompletionServiceClient._DEFAULT_UNIVERSE + default_endpoint = CompletionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CompletionServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -590,7 +1016,9 @@ def test_completion_service_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, @@ -635,7 +1063,9 @@ def test_completion_service_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, @@ -695,7 +1125,9 @@ def test_completion_service_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, @@ -712,8 +1144,8 @@ def test_completion_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -742,7 +1174,7 @@ def test_completion_service_client_create_channel_credentials_file( ) def test_complete_query(request_type, transport: str = "grpc"): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -772,7 +1204,7 @@ def test_complete_query_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -790,7 +1222,7 @@ async def test_complete_query_async( request_type=completion_service.CompleteQueryRequest, ): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -825,7 +1257,7 @@ async def test_complete_query_async_from_dict(): def test_complete_query_field_headers(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -855,7 +1287,7 @@ def test_complete_query_field_headers(): @pytest.mark.asyncio async def test_complete_query_field_headers_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -893,7 +1325,7 @@ async def test_complete_query_field_headers_async(): ) def test_complete_query_rest(request_type): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -948,7 +1380,7 @@ def test_complete_query_rest_required_fields( assert "query" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_query._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -960,7 +1392,7 @@ def test_complete_query_rest_required_fields( jsonified_request["query"] = "query_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).complete_query._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -980,7 +1412,7 @@ def test_complete_query_rest_required_fields( assert jsonified_request["query"] == "query_value" client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1028,7 +1460,7 @@ def test_complete_query_rest_required_fields( def test_complete_query_rest_unset_required_fields(): transport = transports.CompletionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.complete_query._get_unset_required_fields({}) @@ -1053,7 +1485,7 @@ def test_complete_query_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_complete_query_rest_interceptors(null_interceptor): transport = transports.CompletionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CompletionServiceRestInterceptor(), @@ -1111,7 +1543,7 @@ def test_complete_query_rest_bad_request( transport: str = "rest", request_type=completion_service.CompleteQueryRequest ): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1135,24 +1567,24 @@ def test_complete_query_rest_bad_request( def test_complete_query_rest_error(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CompletionServiceClient( @@ -1162,7 +1594,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1173,16 +1605,17 @@ 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 = CompletionServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CompletionServiceClient( @@ -1194,7 +1627,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = CompletionServiceClient(transport=transport) assert client.transport is transport @@ -1203,13 +1636,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CompletionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.CompletionServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1226,7 +1659,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1240,7 +1673,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = CompletionServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1248,7 +1681,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1260,7 +1693,7 @@ def test_completion_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.CompletionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1272,7 +1705,7 @@ def test_completion_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CompletionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1306,7 +1739,7 @@ def test_completion_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1beta.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CompletionServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1325,7 +1758,7 @@ def test_completion_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1beta.services.completion_service.transports.CompletionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CompletionServiceTransport() adc.assert_called_once() @@ -1333,7 +1766,7 @@ def test_completion_service_base_transport_with_adc(): def test_completion_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) CompletionServiceClient() adc.assert_called_once_with( scopes=None, @@ -1353,7 +1786,7 @@ def test_completion_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1400,7 +1833,7 @@ def test_completion_service_transport_create_channel(transport_class, grpc_helpe ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1428,7 +1861,7 @@ def test_completion_service_transport_create_channel(transport_class, grpc_helpe ], ) def test_completion_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1466,7 +1899,7 @@ def test_completion_service_grpc_transport_client_cert_source_for_mtls(transport def test_completion_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1486,7 +1919,7 @@ def test_completion_service_http_transport_client_cert_source_for_mtls(): ) def test_completion_service_host_no_port(transport_name): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -1509,7 +1942,7 @@ def test_completion_service_host_no_port(transport_name): ) def test_completion_service_host_with_port(transport_name): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -1529,8 +1962,8 @@ def test_completion_service_host_with_port(transport_name): ], ) def test_completion_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = CompletionServiceClient( credentials=creds1, transport=transport_name, @@ -1594,7 +2027,7 @@ def test_completion_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -1806,7 +2239,7 @@ def test_client_with_default_client_info(): transports.CompletionServiceTransport, "_prep_wrapped_messages" ) as prep: client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1816,7 +2249,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = CompletionServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1825,7 +2258,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -1840,7 +2273,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1873,7 +2306,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -1903,7 +2336,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1936,7 +2369,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -1964,7 +2397,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1989,7 +2422,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2015,7 +2448,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2044,7 +2477,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2073,7 +2506,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2091,7 +2524,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2109,7 +2542,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2134,7 +2567,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2160,7 +2593,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2189,7 +2622,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2218,7 +2651,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2236,7 +2669,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = CompletionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2260,7 +2693,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2277,7 +2710,7 @@ def test_client_ctx(): ] for transport in transports: client = CompletionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2311,7 +2744,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_conversational_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_conversational_search_service.py index 16f95c6ccc8c..b548cbf8ab40 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_conversational_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_conversational_search_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -75,6 +75,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -107,6 +130,297 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + ConversationalSearchServiceClient._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 ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert ConversationalSearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationalSearchServiceClient._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 ConversationalSearchServiceClient._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 ( + ConversationalSearchServiceClient._get_client_cert_source(None, False) is None + ) + assert ( + ConversationalSearchServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + ConversationalSearchServiceClient._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 ( + ConversationalSearchServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + ConversationalSearchServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + ConversationalSearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), +) +@mock.patch.object( + ConversationalSearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = ConversationalSearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == ConversationalSearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + ConversationalSearchServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + ConversationalSearchServiceClient._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 ( + ConversationalSearchServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + ConversationalSearchServiceClient._get_universe_domain( + None, universe_domain_env + ) + == universe_domain_env + ) + assert ( + ConversationalSearchServiceClient._get_universe_domain(None, None) + == ConversationalSearchServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + ConversationalSearchServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + ConversationalSearchServiceClient, + transports.ConversationalSearchServiceGrpcTransport, + "grpc", + ), + ( + ConversationalSearchServiceClient, + transports.ConversationalSearchServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -118,7 +432,7 @@ def test__get_default_mtls_endpoint(): def test_conversational_search_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -172,7 +486,7 @@ def test_conversational_search_service_client_service_account_always_use_jwt( def test_conversational_search_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -230,13 +544,13 @@ def test_conversational_search_service_client_get_transport_class(): ) @mock.patch.object( ConversationalSearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), ) @mock.patch.object( ConversationalSearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), ) def test_conversational_search_service_client_client_options( client_class, transport_class, transport_name @@ -245,7 +559,9 @@ def test_conversational_search_service_client_client_options( with mock.patch.object( ConversationalSearchServiceClient, "get_transport_class" ) as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -282,7 +598,9 @@ def test_conversational_search_service_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, @@ -312,15 +630,23 @@ def test_conversational_search_service_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") @@ -330,7 +656,9 @@ def test_conversational_search_service_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", @@ -348,7 +676,9 @@ def test_conversational_search_service_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, @@ -401,13 +731,13 @@ def test_conversational_search_service_client_client_options( ) @mock.patch.object( ConversationalSearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), ) @mock.patch.object( ConversationalSearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(ConversationalSearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_conversational_search_service_client_mtls_env_auto( @@ -430,7 +760,9 @@ def test_conversational_search_service_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 @@ -462,7 +794,9 @@ def test_conversational_search_service_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 @@ -496,7 +830,9 @@ def test_conversational_search_service_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, @@ -589,6 +925,121 @@ def test_conversational_search_service_client_get_mtls_endpoint_and_cert_source( 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", + [ConversationalSearchServiceClient, ConversationalSearchServiceAsyncClient], +) +@mock.patch.object( + ConversationalSearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceClient), +) +@mock.patch.object( + ConversationalSearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(ConversationalSearchServiceAsyncClient), +) +def test_conversational_search_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = ConversationalSearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + ConversationalSearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ConversationalSearchServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -623,7 +1074,9 @@ def test_conversational_search_service_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, @@ -668,7 +1121,9 @@ def test_conversational_search_service_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, @@ -728,7 +1183,9 @@ def test_conversational_search_service_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, @@ -745,8 +1202,8 @@ def test_conversational_search_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -775,7 +1232,7 @@ def test_conversational_search_service_client_create_channel_credentials_file( ) def test_converse_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -809,7 +1266,7 @@ def test_converse_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -829,7 +1286,7 @@ async def test_converse_conversation_async( request_type=conversational_search_service.ConverseConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -868,7 +1325,7 @@ async def test_converse_conversation_async_from_dict(): def test_converse_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -900,7 +1357,7 @@ def test_converse_conversation_field_headers(): @pytest.mark.asyncio async def test_converse_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -933,7 +1390,7 @@ async def test_converse_conversation_field_headers_async(): def test_converse_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -963,7 +1420,7 @@ def test_converse_conversation_flattened(): def test_converse_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -979,7 +1436,7 @@ def test_converse_conversation_flattened_error(): @pytest.mark.asyncio async def test_converse_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1014,7 +1471,7 @@ async def test_converse_conversation_flattened_async(): @pytest.mark.asyncio async def test_converse_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1036,7 +1493,7 @@ async def test_converse_conversation_flattened_error_async(): ) def test_create_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1072,7 +1529,7 @@ def test_create_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1092,7 +1549,7 @@ async def test_create_conversation_async( request_type=conversational_search_service.CreateConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1133,7 +1590,7 @@ async def test_create_conversation_async_from_dict(): def test_create_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1165,7 +1622,7 @@ def test_create_conversation_field_headers(): @pytest.mark.asyncio async def test_create_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1198,7 +1655,7 @@ async def test_create_conversation_field_headers_async(): def test_create_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1228,7 +1685,7 @@ def test_create_conversation_flattened(): def test_create_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1244,7 +1701,7 @@ def test_create_conversation_flattened_error(): @pytest.mark.asyncio async def test_create_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1279,7 +1736,7 @@ async def test_create_conversation_flattened_async(): @pytest.mark.asyncio async def test_create_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1301,7 +1758,7 @@ async def test_create_conversation_flattened_error_async(): ) def test_delete_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1330,7 +1787,7 @@ def test_delete_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1350,7 +1807,7 @@ async def test_delete_conversation_async( request_type=conversational_search_service.DeleteConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1382,7 +1839,7 @@ async def test_delete_conversation_async_from_dict(): def test_delete_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1414,7 +1871,7 @@ def test_delete_conversation_field_headers(): @pytest.mark.asyncio async def test_delete_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1445,7 +1902,7 @@ async def test_delete_conversation_field_headers_async(): def test_delete_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1471,7 +1928,7 @@ def test_delete_conversation_flattened(): def test_delete_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1486,7 +1943,7 @@ def test_delete_conversation_flattened_error(): @pytest.mark.asyncio async def test_delete_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1515,7 +1972,7 @@ async def test_delete_conversation_flattened_async(): @pytest.mark.asyncio async def test_delete_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1536,7 +1993,7 @@ async def test_delete_conversation_flattened_error_async(): ) def test_update_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1572,7 +2029,7 @@ def test_update_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1592,7 +2049,7 @@ async def test_update_conversation_async( request_type=conversational_search_service.UpdateConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1633,7 +2090,7 @@ async def test_update_conversation_async_from_dict(): def test_update_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1665,7 +2122,7 @@ def test_update_conversation_field_headers(): @pytest.mark.asyncio async def test_update_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1698,7 +2155,7 @@ async def test_update_conversation_field_headers_async(): def test_update_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1728,7 +2185,7 @@ def test_update_conversation_flattened(): def test_update_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1744,7 +2201,7 @@ def test_update_conversation_flattened_error(): @pytest.mark.asyncio async def test_update_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1779,7 +2236,7 @@ async def test_update_conversation_flattened_async(): @pytest.mark.asyncio async def test_update_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1801,7 +2258,7 @@ async def test_update_conversation_flattened_error_async(): ) def test_get_conversation(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1835,7 +2292,7 @@ def test_get_conversation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1853,7 +2310,7 @@ async def test_get_conversation_async( request_type=conversational_search_service.GetConversationRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1892,7 +2349,7 @@ async def test_get_conversation_async_from_dict(): def test_get_conversation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1922,7 +2379,7 @@ def test_get_conversation_field_headers(): @pytest.mark.asyncio async def test_get_conversation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1953,7 +2410,7 @@ async def test_get_conversation_field_headers_async(): def test_get_conversation_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1977,7 +2434,7 @@ def test_get_conversation_flattened(): def test_get_conversation_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1992,7 +2449,7 @@ def test_get_conversation_flattened_error(): @pytest.mark.asyncio async def test_get_conversation_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2021,7 +2478,7 @@ async def test_get_conversation_flattened_async(): @pytest.mark.asyncio async def test_get_conversation_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2042,7 +2499,7 @@ async def test_get_conversation_flattened_error_async(): ) def test_list_conversations(request_type, transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2074,7 +2531,7 @@ def test_list_conversations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2094,7 +2551,7 @@ async def test_list_conversations_async( request_type=conversational_search_service.ListConversationsRequest, ): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2131,7 +2588,7 @@ async def test_list_conversations_async_from_dict(): def test_list_conversations_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2163,7 +2620,7 @@ def test_list_conversations_field_headers(): @pytest.mark.asyncio async def test_list_conversations_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2196,7 +2653,7 @@ async def test_list_conversations_field_headers_async(): def test_list_conversations_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2222,7 +2679,7 @@ def test_list_conversations_flattened(): def test_list_conversations_flattened_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2237,7 +2694,7 @@ def test_list_conversations_flattened_error(): @pytest.mark.asyncio async def test_list_conversations_flattened_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2268,7 +2725,7 @@ async def test_list_conversations_flattened_async(): @pytest.mark.asyncio async def test_list_conversations_flattened_error_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2282,7 +2739,7 @@ async def test_list_conversations_flattened_error_async(): def test_list_conversations_pager(transport_name: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2334,7 +2791,7 @@ def test_list_conversations_pager(transport_name: str = "grpc"): def test_list_conversations_pages(transport_name: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2378,7 +2835,7 @@ def test_list_conversations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversations_async_pager(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2430,7 +2887,7 @@ async def test_list_conversations_async_pager(): @pytest.mark.asyncio async def test_list_conversations_async_pages(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2487,7 +2944,7 @@ async def test_list_conversations_async_pages(): ) def test_converse_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2544,7 +3001,7 @@ def test_converse_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).converse_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2553,7 +3010,7 @@ def test_converse_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).converse_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2562,7 +3019,7 @@ def test_converse_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2609,7 +3066,7 @@ def test_converse_conversation_rest_required_fields( def test_converse_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.converse_conversation._get_unset_required_fields({}) @@ -2627,7 +3084,7 @@ def test_converse_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_converse_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -2690,7 +3147,7 @@ def test_converse_conversation_rest_bad_request( request_type=conversational_search_service.ConverseConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2714,7 +3171,7 @@ def test_converse_conversation_rest_bad_request( def test_converse_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2761,7 +3218,7 @@ def test_converse_conversation_rest_flattened(): def test_converse_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2777,7 +3234,7 @@ def test_converse_conversation_rest_flattened_error(transport: str = "rest"): def test_converse_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2790,7 +3247,7 @@ def test_converse_conversation_rest_error(): ) def test_create_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2955,7 +3412,7 @@ def test_create_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2964,7 +3421,7 @@ def test_create_conversation_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2973,7 +3430,7 @@ def test_create_conversation_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3016,7 +3473,7 @@ def test_create_conversation_rest_required_fields( def test_create_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_conversation._get_unset_required_fields({}) @@ -3034,7 +3491,7 @@ def test_create_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -3094,7 +3551,7 @@ def test_create_conversation_rest_bad_request( request_type=conversational_search_service.CreateConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3116,7 +3573,7 @@ def test_create_conversation_rest_bad_request( def test_create_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3161,7 +3618,7 @@ def test_create_conversation_rest_flattened(): def test_create_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3177,7 +3634,7 @@ def test_create_conversation_rest_flattened_error(transport: str = "rest"): def test_create_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3190,7 +3647,7 @@ def test_create_conversation_rest_error(): ) def test_delete_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3238,7 +3695,7 @@ def test_delete_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3247,7 +3704,7 @@ def test_delete_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3256,7 +3713,7 @@ def test_delete_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3295,7 +3752,7 @@ def test_delete_conversation_rest_required_fields( def test_delete_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_conversation._get_unset_required_fields({}) @@ -3305,7 +3762,7 @@ def test_delete_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -3356,7 +3813,7 @@ def test_delete_conversation_rest_bad_request( request_type=conversational_search_service.DeleteConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3380,7 +3837,7 @@ def test_delete_conversation_rest_bad_request( def test_delete_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3422,7 +3879,7 @@ def test_delete_conversation_rest_flattened(): def test_delete_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3437,7 +3894,7 @@ def test_delete_conversation_rest_flattened_error(transport: str = "rest"): def test_delete_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3450,7 +3907,7 @@ def test_delete_conversation_rest_error(): ) def test_update_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3618,14 +4075,14 @@ def test_update_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_conversation._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3634,7 +4091,7 @@ def test_update_conversation_rest_required_fields( # verify required fields with non-default values are left alone client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3677,7 +4134,7 @@ def test_update_conversation_rest_required_fields( def test_update_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_conversation._get_unset_required_fields({}) @@ -3687,7 +4144,7 @@ def test_update_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -3747,7 +4204,7 @@ def test_update_conversation_rest_bad_request( request_type=conversational_search_service.UpdateConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3773,7 +4230,7 @@ def test_update_conversation_rest_bad_request( def test_update_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3820,7 +4277,7 @@ def test_update_conversation_rest_flattened(): def test_update_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3836,7 +4293,7 @@ def test_update_conversation_rest_flattened_error(transport: str = "rest"): def test_update_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3849,7 +4306,7 @@ def test_update_conversation_rest_error(): ) def test_get_conversation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3906,7 +4363,7 @@ def test_get_conversation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3915,7 +4372,7 @@ def test_get_conversation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_conversation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3924,7 +4381,7 @@ def test_get_conversation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3966,7 +4423,7 @@ def test_get_conversation_rest_required_fields( def test_get_conversation_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_conversation._get_unset_required_fields({}) @@ -3976,7 +4433,7 @@ def test_get_conversation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_conversation_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -4035,7 +4492,7 @@ def test_get_conversation_rest_bad_request( request_type=conversational_search_service.GetConversationRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4059,7 +4516,7 @@ def test_get_conversation_rest_bad_request( def test_get_conversation_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4103,7 +4560,7 @@ def test_get_conversation_rest_flattened(): def test_get_conversation_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4118,7 +4575,7 @@ def test_get_conversation_rest_flattened_error(transport: str = "rest"): def test_get_conversation_rest_error(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4131,7 +4588,7 @@ def test_get_conversation_rest_error(): ) def test_list_conversations_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4184,7 +4641,7 @@ def test_list_conversations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4193,7 +4650,7 @@ def test_list_conversations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_conversations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4211,7 +4668,7 @@ def test_list_conversations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4255,7 +4712,7 @@ def test_list_conversations_rest_required_fields( def test_list_conversations_rest_unset_required_fields(): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_conversations._get_unset_required_fields({}) @@ -4275,7 +4732,7 @@ def test_list_conversations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_conversations_rest_interceptors(null_interceptor): transport = transports.ConversationalSearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.ConversationalSearchServiceRestInterceptor(), @@ -4336,7 +4793,7 @@ def test_list_conversations_rest_bad_request( request_type=conversational_search_service.ListConversationsRequest, ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4358,7 +4815,7 @@ def test_list_conversations_rest_bad_request( def test_list_conversations_rest_flattened(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4404,7 +4861,7 @@ def test_list_conversations_rest_flattened(): def test_list_conversations_rest_flattened_error(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4419,7 +4876,7 @@ def test_list_conversations_rest_flattened_error(transport: str = "rest"): def test_list_conversations_rest_pager(transport: str = "rest"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4486,17 +4943,17 @@ def test_list_conversations_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationalSearchServiceClient( @@ -4506,7 +4963,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4517,16 +4974,17 @@ 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 = ConversationalSearchServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = ConversationalSearchServiceClient( @@ -4538,7 +4996,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = ConversationalSearchServiceClient(transport=transport) assert client.transport is transport @@ -4547,13 +5005,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.ConversationalSearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.ConversationalSearchServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4570,7 +5028,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4584,7 +5042,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = ConversationalSearchServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4592,7 +5050,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4604,7 +5062,7 @@ def test_conversational_search_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.ConversationalSearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4616,7 +5074,7 @@ def test_conversational_search_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.ConversationalSearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4655,7 +5113,7 @@ def test_conversational_search_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1beta.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationalSearchServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4674,7 +5132,7 @@ def test_conversational_search_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1beta.services.conversational_search_service.transports.ConversationalSearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.ConversationalSearchServiceTransport() adc.assert_called_once() @@ -4682,7 +5140,7 @@ def test_conversational_search_service_base_transport_with_adc(): def test_conversational_search_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) ConversationalSearchServiceClient() adc.assert_called_once_with( scopes=None, @@ -4702,7 +5160,7 @@ def test_conversational_search_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4754,7 +5212,7 @@ def test_conversational_search_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4784,7 +5242,7 @@ def test_conversational_search_service_transport_create_channel( def test_conversational_search_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4822,7 +5280,7 @@ def test_conversational_search_service_grpc_transport_client_cert_source_for_mtl def test_conversational_search_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4842,7 +5300,7 @@ def test_conversational_search_service_http_transport_client_cert_source_for_mtl ) def test_conversational_search_service_host_no_port(transport_name): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -4865,7 +5323,7 @@ def test_conversational_search_service_host_no_port(transport_name): ) def test_conversational_search_service_host_with_port(transport_name): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4887,8 +5345,8 @@ def test_conversational_search_service_host_with_port(transport_name): def test_conversational_search_service_client_transport_session_collision( transport_name, ): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = ConversationalSearchServiceClient( credentials=creds1, transport=transport_name, @@ -4967,7 +5425,7 @@ def test_conversational_search_service_transport_channel_mtls_with_client_cert_s mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5279,7 +5737,7 @@ def test_client_with_default_client_info(): transports.ConversationalSearchServiceTransport, "_prep_wrapped_messages" ) as prep: client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5289,7 +5747,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = ConversationalSearchServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5298,7 +5756,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5313,7 +5771,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5346,7 +5804,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -5376,7 +5834,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5409,7 +5867,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -5437,7 +5895,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5462,7 +5920,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5488,7 +5946,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5517,7 +5975,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5546,7 +6004,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5564,7 +6022,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5582,7 +6040,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5607,7 +6065,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5633,7 +6091,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5662,7 +6120,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5691,7 +6149,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5709,7 +6167,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = ConversationalSearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5733,7 +6191,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5750,7 +6208,7 @@ def test_client_ctx(): ] for transport in transports: client = ConversationalSearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5787,7 +6245,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_document_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_document_service.py index 954a617a8c5c..a7b8f02d5bae 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_document_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_document_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -85,6 +85,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -114,6 +137,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert DocumentServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DocumentServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DocumentServiceClient._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 DocumentServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentServiceClient._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 DocumentServiceClient._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 DocumentServiceClient._get_client_cert_source(None, False) is None + assert ( + DocumentServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + DocumentServiceClient._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 ( + DocumentServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DocumentServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DocumentServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), +) +@mock.patch.object( + DocumentServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DocumentServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DocumentServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DocumentServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "always") + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentServiceClient._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 ( + DocumentServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DocumentServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DocumentServiceClient._get_universe_domain(None, None) + == DocumentServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DocumentServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DocumentServiceClient, transports.DocumentServiceGrpcTransport, "grpc"), + (DocumentServiceClient, transports.DocumentServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -125,7 +409,7 @@ def test__get_default_mtls_endpoint(): def test_document_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -179,7 +463,7 @@ def test_document_service_client_service_account_always_use_jwt( def test_document_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -229,20 +513,22 @@ def test_document_service_client_get_transport_class(): ) @mock.patch.object( DocumentServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), ) @mock.patch.object( DocumentServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), ) def test_document_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(DocumentServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -277,7 +563,9 @@ def test_document_service_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, @@ -307,15 +595,23 @@ def test_document_service_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") @@ -325,7 +621,9 @@ def test_document_service_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", @@ -343,7 +641,9 @@ def test_document_service_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, @@ -396,13 +696,13 @@ def test_document_service_client_client_options( ) @mock.patch.object( DocumentServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), ) @mock.patch.object( DocumentServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_document_service_client_mtls_env_auto( @@ -425,7 +725,9 @@ def test_document_service_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 @@ -457,7 +759,9 @@ def test_document_service_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 @@ -491,7 +795,9 @@ def test_document_service_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, @@ -581,6 +887,118 @@ def test_document_service_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", [DocumentServiceClient, DocumentServiceAsyncClient] +) +@mock.patch.object( + DocumentServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), +) +@mock.patch.object( + DocumentServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), +) +def test_document_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DocumentServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -607,7 +1025,9 @@ def test_document_service_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, @@ -647,7 +1067,9 @@ def test_document_service_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, @@ -707,7 +1129,9 @@ def test_document_service_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, @@ -724,8 +1148,8 @@ def test_document_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -754,7 +1178,7 @@ def test_document_service_client_create_channel_credentials_file( ) def test_get_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -791,7 +1215,7 @@ def test_get_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -808,7 +1232,7 @@ async def test_get_document_async( transport: str = "grpc_asyncio", request_type=document_service.GetDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -849,7 +1273,7 @@ async def test_get_document_async_from_dict(): def test_get_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -879,7 +1303,7 @@ def test_get_document_field_headers(): @pytest.mark.asyncio async def test_get_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -908,7 +1332,7 @@ async def test_get_document_field_headers_async(): def test_get_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -932,7 +1356,7 @@ def test_get_document_flattened(): def test_get_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -947,7 +1371,7 @@ def test_get_document_flattened_error(): @pytest.mark.asyncio async def test_get_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -974,7 +1398,7 @@ async def test_get_document_flattened_async(): @pytest.mark.asyncio async def test_get_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -995,7 +1419,7 @@ async def test_get_document_flattened_error_async(): ) def test_list_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1025,7 +1449,7 @@ def test_list_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1042,7 +1466,7 @@ async def test_list_documents_async( transport: str = "grpc_asyncio", request_type=document_service.ListDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1077,7 +1501,7 @@ async def test_list_documents_async_from_dict(): def test_list_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1107,7 +1531,7 @@ def test_list_documents_field_headers(): @pytest.mark.asyncio async def test_list_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1138,7 +1562,7 @@ async def test_list_documents_field_headers_async(): def test_list_documents_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1162,7 +1586,7 @@ def test_list_documents_flattened(): def test_list_documents_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1177,7 +1601,7 @@ def test_list_documents_flattened_error(): @pytest.mark.asyncio async def test_list_documents_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1206,7 +1630,7 @@ async def test_list_documents_flattened_async(): @pytest.mark.asyncio async def test_list_documents_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1220,7 +1644,7 @@ async def test_list_documents_flattened_error_async(): def test_list_documents_pager(transport_name: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1270,7 +1694,7 @@ def test_list_documents_pager(transport_name: str = "grpc"): def test_list_documents_pages(transport_name: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1312,7 +1736,7 @@ def test_list_documents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_documents_async_pager(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1362,7 +1786,7 @@ async def test_list_documents_async_pager(): @pytest.mark.asyncio async def test_list_documents_async_pages(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1417,7 +1841,7 @@ async def test_list_documents_async_pages(): ) def test_create_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1454,7 +1878,7 @@ def test_create_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1471,7 +1895,7 @@ async def test_create_document_async( transport: str = "grpc_asyncio", request_type=document_service.CreateDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1512,7 +1936,7 @@ async def test_create_document_async_from_dict(): def test_create_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1542,7 +1966,7 @@ def test_create_document_field_headers(): @pytest.mark.asyncio async def test_create_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1573,7 +1997,7 @@ async def test_create_document_field_headers_async(): def test_create_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1621,7 +2045,7 @@ def test_create_document_flattened(): def test_create_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1646,7 +2070,7 @@ def test_create_document_flattened_error(): @pytest.mark.asyncio async def test_create_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1699,7 +2123,7 @@ async def test_create_document_flattened_async(): @pytest.mark.asyncio async def test_create_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1730,7 +2154,7 @@ async def test_create_document_flattened_error_async(): ) def test_update_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1767,7 +2191,7 @@ def test_update_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1784,7 +2208,7 @@ async def test_update_document_async( transport: str = "grpc_asyncio", request_type=document_service.UpdateDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1825,7 +2249,7 @@ async def test_update_document_async_from_dict(): def test_update_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1855,7 +2279,7 @@ def test_update_document_field_headers(): @pytest.mark.asyncio async def test_update_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1891,7 +2315,7 @@ async def test_update_document_field_headers_async(): ) def test_delete_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1918,7 +2342,7 @@ def test_delete_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1935,7 +2359,7 @@ async def test_delete_document_async( transport: str = "grpc_asyncio", request_type=document_service.DeleteDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1965,7 +2389,7 @@ async def test_delete_document_async_from_dict(): def test_delete_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1995,7 +2419,7 @@ def test_delete_document_field_headers(): @pytest.mark.asyncio async def test_delete_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2024,7 +2448,7 @@ async def test_delete_document_field_headers_async(): def test_delete_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2048,7 +2472,7 @@ def test_delete_document_flattened(): def test_delete_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2063,7 +2487,7 @@ def test_delete_document_flattened_error(): @pytest.mark.asyncio async def test_delete_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2090,7 +2514,7 @@ async def test_delete_document_flattened_async(): @pytest.mark.asyncio async def test_delete_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2111,7 +2535,7 @@ async def test_delete_document_flattened_error_async(): ) def test_import_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2138,7 +2562,7 @@ def test_import_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2155,7 +2579,7 @@ async def test_import_documents_async( transport: str = "grpc_asyncio", request_type=import_config.ImportDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2187,7 +2611,7 @@ async def test_import_documents_async_from_dict(): def test_import_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2217,7 +2641,7 @@ def test_import_documents_field_headers(): @pytest.mark.asyncio async def test_import_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2255,7 +2679,7 @@ async def test_import_documents_field_headers_async(): ) def test_purge_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2282,7 +2706,7 @@ def test_purge_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2299,7 +2723,7 @@ async def test_purge_documents_async( transport: str = "grpc_asyncio", request_type=purge_config.PurgeDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2331,7 +2755,7 @@ async def test_purge_documents_async_from_dict(): def test_purge_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2361,7 +2785,7 @@ def test_purge_documents_field_headers(): @pytest.mark.asyncio async def test_purge_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2399,7 +2823,7 @@ async def test_purge_documents_field_headers_async(): ) def test_get_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2459,7 +2883,7 @@ def test_get_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2468,7 +2892,7 @@ def test_get_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2477,7 +2901,7 @@ def test_get_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2519,7 +2943,7 @@ def test_get_document_rest_required_fields( def test_get_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_document._get_unset_required_fields({}) @@ -2529,7 +2953,7 @@ def test_get_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -2585,7 +3009,7 @@ def test_get_document_rest_bad_request( transport: str = "rest", request_type=document_service.GetDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2609,7 +3033,7 @@ def test_get_document_rest_bad_request( def test_get_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2653,7 +3077,7 @@ def test_get_document_rest_flattened(): def test_get_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2668,7 +3092,7 @@ def test_get_document_rest_flattened_error(transport: str = "rest"): def test_get_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2681,7 +3105,7 @@ def test_get_document_rest_error(): ) def test_list_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2734,7 +3158,7 @@ def test_list_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2743,7 +3167,7 @@ def test_list_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2759,7 +3183,7 @@ def test_list_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2801,7 +3225,7 @@ def test_list_documents_rest_required_fields( def test_list_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_documents._get_unset_required_fields({}) @@ -2819,7 +3243,7 @@ def test_list_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -2877,7 +3301,7 @@ def test_list_documents_rest_bad_request( transport: str = "rest", request_type=document_service.ListDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2901,7 +3325,7 @@ def test_list_documents_rest_bad_request( def test_list_documents_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2945,7 +3369,7 @@ def test_list_documents_rest_flattened(): def test_list_documents_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2960,7 +3384,7 @@ def test_list_documents_rest_flattened_error(transport: str = "rest"): def test_list_documents_rest_pager(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3032,7 +3456,7 @@ def test_list_documents_rest_pager(transport: str = "rest"): ) def test_create_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3175,7 +3599,7 @@ def test_create_document_rest_required_fields( assert "documentId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3187,7 +3611,7 @@ def test_create_document_rest_required_fields( jsonified_request["documentId"] = "document_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("document_id",)) @@ -3200,7 +3624,7 @@ def test_create_document_rest_required_fields( assert jsonified_request["documentId"] == "document_id_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3249,7 +3673,7 @@ def test_create_document_rest_required_fields( def test_create_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_document._get_unset_required_fields({}) @@ -3268,7 +3692,7 @@ def test_create_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3326,7 +3750,7 @@ def test_create_document_rest_bad_request( transport: str = "rest", request_type=document_service.CreateDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3350,7 +3774,7 @@ def test_create_document_rest_bad_request( def test_create_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3404,7 +3828,7 @@ def test_create_document_rest_flattened(): def test_create_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3429,7 +3853,7 @@ def test_create_document_rest_flattened_error(transport: str = "rest"): def test_create_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3442,7 +3866,7 @@ def test_create_document_rest_error(): ) def test_update_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3584,14 +4008,14 @@ def test_update_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("allow_missing",)) @@ -3600,7 +4024,7 @@ def test_update_document_rest_required_fields( # verify required fields with non-default values are left alone client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3643,7 +4067,7 @@ def test_update_document_rest_required_fields( def test_update_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_document._get_unset_required_fields({}) @@ -3653,7 +4077,7 @@ def test_update_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3709,7 +4133,7 @@ def test_update_document_rest_bad_request( transport: str = "rest", request_type=document_service.UpdateDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3735,7 +4159,7 @@ def test_update_document_rest_bad_request( def test_update_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3748,7 +4172,7 @@ def test_update_document_rest_error(): ) def test_delete_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3796,7 +4220,7 @@ def test_delete_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3805,7 +4229,7 @@ def test_delete_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3814,7 +4238,7 @@ def test_delete_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3853,7 +4277,7 @@ def test_delete_document_rest_required_fields( def test_delete_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_document._get_unset_required_fields({}) @@ -3863,7 +4287,7 @@ def test_delete_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3913,7 +4337,7 @@ def test_delete_document_rest_bad_request( transport: str = "rest", request_type=document_service.DeleteDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3937,7 +4361,7 @@ def test_delete_document_rest_bad_request( def test_delete_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3979,7 +4403,7 @@ def test_delete_document_rest_flattened(): def test_delete_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3994,7 +4418,7 @@ def test_delete_document_rest_flattened_error(transport: str = "rest"): def test_delete_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4007,7 +4431,7 @@ def test_delete_document_rest_error(): ) def test_import_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4055,7 +4479,7 @@ def test_import_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4064,7 +4488,7 @@ def test_import_documents_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4073,7 +4497,7 @@ def test_import_documents_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4113,7 +4537,7 @@ def test_import_documents_rest_required_fields( def test_import_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_documents._get_unset_required_fields({}) @@ -4123,7 +4547,7 @@ def test_import_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -4183,7 +4607,7 @@ def test_import_documents_rest_bad_request( transport: str = "rest", request_type=import_config.ImportDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4207,7 +4631,7 @@ def test_import_documents_rest_bad_request( def test_import_documents_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4220,7 +4644,7 @@ def test_import_documents_rest_error(): ) def test_purge_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4269,7 +4693,7 @@ def test_purge_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).purge_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4279,7 +4703,7 @@ def test_purge_documents_rest_required_fields( jsonified_request["filter"] = "filter_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).purge_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4290,7 +4714,7 @@ def test_purge_documents_rest_required_fields( assert jsonified_request["filter"] == "filter_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4330,7 +4754,7 @@ def test_purge_documents_rest_required_fields( def test_purge_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.purge_documents._get_unset_required_fields({}) @@ -4348,7 +4772,7 @@ def test_purge_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_purge_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -4408,7 +4832,7 @@ def test_purge_documents_rest_bad_request( transport: str = "rest", request_type=purge_config.PurgeDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4432,24 +4856,24 @@ def test_purge_documents_rest_bad_request( def test_purge_documents_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( @@ -4459,7 +4883,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4470,16 +4894,17 @@ 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 = DocumentServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( @@ -4491,7 +4916,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DocumentServiceClient(transport=transport) assert client.transport is transport @@ -4500,13 +4925,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DocumentServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4523,7 +4948,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4537,7 +4962,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DocumentServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4545,7 +4970,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4557,7 +4982,7 @@ def test_document_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DocumentServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4569,7 +4994,7 @@ def test_document_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DocumentServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4614,7 +5039,7 @@ def test_document_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1beta.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4633,7 +5058,7 @@ def test_document_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1beta.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentServiceTransport() adc.assert_called_once() @@ -4641,7 +5066,7 @@ def test_document_service_base_transport_with_adc(): def test_document_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DocumentServiceClient() adc.assert_called_once_with( scopes=None, @@ -4661,7 +5086,7 @@ def test_document_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4708,7 +5133,7 @@ def test_document_service_transport_create_channel(transport_class, grpc_helpers ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -4736,7 +5161,7 @@ def test_document_service_transport_create_channel(transport_class, grpc_helpers ], ) def test_document_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -4774,7 +5199,7 @@ def test_document_service_grpc_transport_client_cert_source_for_mtls(transport_c def test_document_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -4786,7 +5211,7 @@ def test_document_service_http_transport_client_cert_source_for_mtls(): def test_document_service_rest_lro_client(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -4811,7 +5236,7 @@ def test_document_service_rest_lro_client(): ) def test_document_service_host_no_port(transport_name): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -4834,7 +5259,7 @@ def test_document_service_host_no_port(transport_name): ) def test_document_service_host_with_port(transport_name): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4854,8 +5279,8 @@ def test_document_service_host_with_port(transport_name): ], ) def test_document_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DocumentServiceClient( credentials=creds1, transport=transport_name, @@ -4937,7 +5362,7 @@ def test_document_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5015,7 +5440,7 @@ def test_document_service_transport_channel_mtls_with_adc(transport_class): def test_document_service_grpc_lro_client(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5032,7 +5457,7 @@ def test_document_service_grpc_lro_client(): def test_document_service_grpc_lro_async_client(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -5220,7 +5645,7 @@ def test_client_with_default_client_info(): transports.DocumentServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5230,7 +5655,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5239,7 +5664,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5254,7 +5679,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5287,7 +5712,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -5317,7 +5742,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5350,7 +5775,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -5378,7 +5803,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5403,7 +5828,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5429,7 +5854,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5458,7 +5883,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5487,7 +5912,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5505,7 +5930,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -5523,7 +5948,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5548,7 +5973,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5574,7 +5999,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5603,7 +6028,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5632,7 +6057,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5650,7 +6075,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -5674,7 +6099,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5691,7 +6116,7 @@ def test_client_ctx(): ] for transport in transports: client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5722,7 +6147,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_recommendation_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_recommendation_service.py index 8d697814ddf5..8e6e2993f9cc 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_recommendation_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_recommendation_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -74,6 +74,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -104,6 +127,291 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert RecommendationServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert RecommendationServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert RecommendationServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + RecommendationServiceClient._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 RecommendationServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert RecommendationServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert RecommendationServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + RecommendationServiceClient._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 RecommendationServiceClient._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 RecommendationServiceClient._get_client_cert_source(None, False) is None + assert ( + RecommendationServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + RecommendationServiceClient._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 ( + RecommendationServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + RecommendationServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + RecommendationServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceClient), +) +@mock.patch.object( + RecommendationServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = RecommendationServiceClient._DEFAULT_UNIVERSE + default_endpoint = RecommendationServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = RecommendationServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + RecommendationServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == RecommendationServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + RecommendationServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + RecommendationServiceClient._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 ( + RecommendationServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + RecommendationServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + RecommendationServiceClient._get_universe_domain(None, None) + == RecommendationServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + RecommendationServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + RecommendationServiceClient, + transports.RecommendationServiceGrpcTransport, + "grpc", + ), + ( + RecommendationServiceClient, + transports.RecommendationServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -115,7 +423,7 @@ def test__get_default_mtls_endpoint(): def test_recommendation_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -169,7 +477,7 @@ def test_recommendation_service_client_service_account_always_use_jwt( def test_recommendation_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -227,20 +535,22 @@ def test_recommendation_service_client_get_transport_class(): ) @mock.patch.object( RecommendationServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(RecommendationServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceClient), ) @mock.patch.object( RecommendationServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(RecommendationServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceAsyncClient), ) def test_recommendation_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(RecommendationServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -275,7 +585,9 @@ def test_recommendation_service_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, @@ -305,15 +617,23 @@ def test_recommendation_service_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") @@ -323,7 +643,9 @@ def test_recommendation_service_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", @@ -341,7 +663,9 @@ def test_recommendation_service_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, @@ -394,13 +718,13 @@ def test_recommendation_service_client_client_options( ) @mock.patch.object( RecommendationServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(RecommendationServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceClient), ) @mock.patch.object( RecommendationServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(RecommendationServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_recommendation_service_client_mtls_env_auto( @@ -423,7 +747,9 @@ def test_recommendation_service_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 @@ -455,7 +781,9 @@ def test_recommendation_service_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 @@ -489,7 +817,9 @@ def test_recommendation_service_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, @@ -579,6 +909,118 @@ def test_recommendation_service_client_get_mtls_endpoint_and_cert_source(client_ 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", [RecommendationServiceClient, RecommendationServiceAsyncClient] +) +@mock.patch.object( + RecommendationServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceClient), +) +@mock.patch.object( + RecommendationServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(RecommendationServiceAsyncClient), +) +def test_recommendation_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = RecommendationServiceClient._DEFAULT_UNIVERSE + default_endpoint = RecommendationServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = RecommendationServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -613,7 +1055,9 @@ def test_recommendation_service_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, @@ -658,7 +1102,9 @@ def test_recommendation_service_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, @@ -718,7 +1164,9 @@ def test_recommendation_service_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, @@ -735,8 +1183,8 @@ def test_recommendation_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -765,7 +1213,7 @@ def test_recommendation_service_client_create_channel_credentials_file( ) def test_recommend(request_type, transport: str = "grpc"): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -799,7 +1247,7 @@ def test_recommend_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -817,7 +1265,7 @@ async def test_recommend_async( request_type=recommendation_service.RecommendRequest, ): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -856,7 +1304,7 @@ async def test_recommend_async_from_dict(): def test_recommend_field_headers(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -886,7 +1334,7 @@ def test_recommend_field_headers(): @pytest.mark.asyncio async def test_recommend_field_headers_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -924,7 +1372,7 @@ async def test_recommend_field_headers_async(): ) def test_recommend_rest(request_type): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -981,7 +1429,7 @@ def test_recommend_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).recommend._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -990,7 +1438,7 @@ def test_recommend_rest_required_fields( jsonified_request["servingConfig"] = "serving_config_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).recommend._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -999,7 +1447,7 @@ def test_recommend_rest_required_fields( assert jsonified_request["servingConfig"] == "serving_config_value" client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1042,7 +1490,7 @@ def test_recommend_rest_required_fields( def test_recommend_rest_unset_required_fields(): transport = transports.RecommendationServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.recommend._get_unset_required_fields({}) @@ -1060,7 +1508,7 @@ def test_recommend_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_recommend_rest_interceptors(null_interceptor): transport = transports.RecommendationServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.RecommendationServiceRestInterceptor(), @@ -1118,7 +1566,7 @@ def test_recommend_rest_bad_request( transport: str = "rest", request_type=recommendation_service.RecommendRequest ): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1142,24 +1590,24 @@ def test_recommend_rest_bad_request( def test_recommend_rest_error(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = RecommendationServiceClient( @@ -1169,7 +1617,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1180,16 +1628,17 @@ 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 = RecommendationServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = RecommendationServiceClient( @@ -1201,7 +1650,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = RecommendationServiceClient(transport=transport) assert client.transport is transport @@ -1210,13 +1659,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.RecommendationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.RecommendationServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1233,7 +1682,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1247,7 +1696,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = RecommendationServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1255,7 +1704,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1267,7 +1716,7 @@ def test_recommendation_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.RecommendationServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1279,7 +1728,7 @@ def test_recommendation_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.RecommendationServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1313,7 +1762,7 @@ def test_recommendation_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1beta.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.RecommendationServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1332,7 +1781,7 @@ def test_recommendation_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1beta.services.recommendation_service.transports.RecommendationServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.RecommendationServiceTransport() adc.assert_called_once() @@ -1340,7 +1789,7 @@ def test_recommendation_service_base_transport_with_adc(): def test_recommendation_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) RecommendationServiceClient() adc.assert_called_once_with( scopes=None, @@ -1360,7 +1809,7 @@ def test_recommendation_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1407,7 +1856,7 @@ def test_recommendation_service_transport_create_channel(transport_class, grpc_h ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1437,7 +1886,7 @@ def test_recommendation_service_transport_create_channel(transport_class, grpc_h def test_recommendation_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1475,7 +1924,7 @@ def test_recommendation_service_grpc_transport_client_cert_source_for_mtls( def test_recommendation_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1495,7 +1944,7 @@ def test_recommendation_service_http_transport_client_cert_source_for_mtls(): ) def test_recommendation_service_host_no_port(transport_name): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -1518,7 +1967,7 @@ def test_recommendation_service_host_no_port(transport_name): ) def test_recommendation_service_host_with_port(transport_name): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -1538,8 +1987,8 @@ def test_recommendation_service_host_with_port(transport_name): ], ) def test_recommendation_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = RecommendationServiceClient( credentials=creds1, transport=transport_name, @@ -1603,7 +2052,7 @@ def test_recommendation_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -1854,7 +2303,7 @@ def test_client_with_default_client_info(): transports.RecommendationServiceTransport, "_prep_wrapped_messages" ) as prep: client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1864,7 +2313,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = RecommendationServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1873,7 +2322,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -1888,7 +2337,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1921,7 +2370,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -1951,7 +2400,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1984,7 +2433,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -2012,7 +2461,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2037,7 +2486,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2063,7 +2512,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2092,7 +2541,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2121,7 +2570,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2139,7 +2588,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2157,7 +2606,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2182,7 +2631,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2208,7 +2657,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2237,7 +2686,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2266,7 +2715,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2284,7 +2733,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = RecommendationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2308,7 +2757,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2325,7 +2774,7 @@ def test_client_ctx(): ] for transport in transports: client = RecommendationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2359,7 +2808,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_schema_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_schema_service.py index dbc450f4cd0b..2ec8309f5ac4 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_schema_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_schema_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -81,6 +81,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -110,6 +133,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SchemaServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SchemaServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SchemaServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SchemaServiceClient._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 SchemaServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SchemaServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SchemaServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SchemaServiceClient._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 SchemaServiceClient._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 SchemaServiceClient._get_client_cert_source(None, False) is None + assert ( + SchemaServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + SchemaServiceClient._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 ( + SchemaServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SchemaServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SchemaServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), +) +@mock.patch.object( + SchemaServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SchemaServiceClient._DEFAULT_UNIVERSE + default_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SchemaServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SchemaServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, default_universe, "always") + == SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SchemaServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SchemaServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SchemaServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SchemaServiceClient._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 ( + SchemaServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SchemaServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SchemaServiceClient._get_universe_domain(None, None) + == SchemaServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SchemaServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SchemaServiceClient, transports.SchemaServiceGrpcTransport, "grpc"), + (SchemaServiceClient, transports.SchemaServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -119,7 +399,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_schema_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -171,7 +451,7 @@ def test_schema_service_client_service_account_always_use_jwt( ], ) def test_schema_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -221,20 +501,22 @@ def test_schema_service_client_get_transport_class(): ) @mock.patch.object( SchemaServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), ) @mock.patch.object( SchemaServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), ) def test_schema_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SchemaServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -269,7 +551,9 @@ def test_schema_service_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, @@ -299,15 +583,23 @@ def test_schema_service_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") @@ -317,7 +609,9 @@ def test_schema_service_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", @@ -335,7 +629,9 @@ def test_schema_service_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, @@ -368,13 +664,13 @@ def test_schema_service_client_client_options( ) @mock.patch.object( SchemaServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), ) @mock.patch.object( SchemaServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SchemaServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_schema_service_client_mtls_env_auto( @@ -397,7 +693,9 @@ def test_schema_service_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 @@ -429,7 +727,9 @@ def test_schema_service_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 @@ -463,7 +763,9 @@ def test_schema_service_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, @@ -553,6 +855,118 @@ def test_schema_service_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", [SchemaServiceClient, SchemaServiceAsyncClient] +) +@mock.patch.object( + SchemaServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceClient), +) +@mock.patch.object( + SchemaServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SchemaServiceAsyncClient), +) +def test_schema_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SchemaServiceClient._DEFAULT_UNIVERSE + default_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SchemaServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -579,7 +993,9 @@ def test_schema_service_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, @@ -619,7 +1035,9 @@ def test_schema_service_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, @@ -679,7 +1097,9 @@ def test_schema_service_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, @@ -696,8 +1116,8 @@ def test_schema_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -726,7 +1146,7 @@ def test_schema_service_client_create_channel_credentials_file( ) def test_get_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -757,7 +1177,7 @@ def test_get_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -774,7 +1194,7 @@ async def test_get_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.GetSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -809,7 +1229,7 @@ async def test_get_schema_async_from_dict(): def test_get_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -839,7 +1259,7 @@ def test_get_schema_field_headers(): @pytest.mark.asyncio async def test_get_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -868,7 +1288,7 @@ async def test_get_schema_field_headers_async(): def test_get_schema_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -892,7 +1312,7 @@ def test_get_schema_flattened(): def test_get_schema_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -907,7 +1327,7 @@ def test_get_schema_flattened_error(): @pytest.mark.asyncio async def test_get_schema_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -934,7 +1354,7 @@ async def test_get_schema_flattened_async(): @pytest.mark.asyncio async def test_get_schema_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -955,7 +1375,7 @@ async def test_get_schema_flattened_error_async(): ) def test_list_schemas(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -985,7 +1405,7 @@ def test_list_schemas_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1002,7 +1422,7 @@ async def test_list_schemas_async( transport: str = "grpc_asyncio", request_type=schema_service.ListSchemasRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1037,7 +1457,7 @@ async def test_list_schemas_async_from_dict(): def test_list_schemas_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1067,7 +1487,7 @@ def test_list_schemas_field_headers(): @pytest.mark.asyncio async def test_list_schemas_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1098,7 +1518,7 @@ async def test_list_schemas_field_headers_async(): def test_list_schemas_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1122,7 +1542,7 @@ def test_list_schemas_flattened(): def test_list_schemas_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1137,7 +1557,7 @@ def test_list_schemas_flattened_error(): @pytest.mark.asyncio async def test_list_schemas_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1166,7 +1586,7 @@ async def test_list_schemas_flattened_async(): @pytest.mark.asyncio async def test_list_schemas_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1180,7 +1600,7 @@ async def test_list_schemas_flattened_error_async(): def test_list_schemas_pager(transport_name: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1230,7 +1650,7 @@ def test_list_schemas_pager(transport_name: str = "grpc"): def test_list_schemas_pages(transport_name: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1272,7 +1692,7 @@ def test_list_schemas_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_schemas_async_pager(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1322,7 +1742,7 @@ async def test_list_schemas_async_pager(): @pytest.mark.asyncio async def test_list_schemas_async_pages(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1377,7 +1797,7 @@ async def test_list_schemas_async_pages(): ) def test_create_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1404,7 +1824,7 @@ def test_create_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1421,7 +1841,7 @@ async def test_create_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.CreateSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1453,7 +1873,7 @@ async def test_create_schema_async_from_dict(): def test_create_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1483,7 +1903,7 @@ def test_create_schema_field_headers(): @pytest.mark.asyncio async def test_create_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1514,7 +1934,7 @@ async def test_create_schema_field_headers_async(): def test_create_schema_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1562,7 +1982,7 @@ def test_create_schema_flattened(): def test_create_schema_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1587,7 +2007,7 @@ def test_create_schema_flattened_error(): @pytest.mark.asyncio async def test_create_schema_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1640,7 +2060,7 @@ async def test_create_schema_flattened_async(): @pytest.mark.asyncio async def test_create_schema_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1671,7 +2091,7 @@ async def test_create_schema_flattened_error_async(): ) def test_update_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1698,7 +2118,7 @@ def test_update_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1715,7 +2135,7 @@ async def test_update_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.UpdateSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1747,7 +2167,7 @@ async def test_update_schema_async_from_dict(): def test_update_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1777,7 +2197,7 @@ def test_update_schema_field_headers(): @pytest.mark.asyncio async def test_update_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1815,7 +2235,7 @@ async def test_update_schema_field_headers_async(): ) def test_delete_schema(request_type, transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1842,7 +2262,7 @@ def test_delete_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1859,7 +2279,7 @@ async def test_delete_schema_async( transport: str = "grpc_asyncio", request_type=schema_service.DeleteSchemaRequest ): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1891,7 +2311,7 @@ async def test_delete_schema_async_from_dict(): def test_delete_schema_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1921,7 +2341,7 @@ def test_delete_schema_field_headers(): @pytest.mark.asyncio async def test_delete_schema_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1952,7 +2372,7 @@ async def test_delete_schema_field_headers_async(): def test_delete_schema_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1976,7 +2396,7 @@ def test_delete_schema_flattened(): def test_delete_schema_flattened_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1991,7 +2411,7 @@ def test_delete_schema_flattened_error(): @pytest.mark.asyncio async def test_delete_schema_flattened_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2020,7 +2440,7 @@ async def test_delete_schema_flattened_async(): @pytest.mark.asyncio async def test_delete_schema_flattened_error_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2041,7 +2461,7 @@ async def test_delete_schema_flattened_error_async(): ) def test_get_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2093,7 +2513,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2102,7 +2522,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2111,7 +2531,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe assert jsonified_request["name"] == "name_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2153,7 +2573,7 @@ def test_get_schema_rest_required_fields(request_type=schema_service.GetSchemaRe def test_get_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_schema._get_unset_required_fields({}) @@ -2163,7 +2583,7 @@ def test_get_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -2219,7 +2639,7 @@ def test_get_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.GetSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2243,7 +2663,7 @@ def test_get_schema_rest_bad_request( def test_get_schema_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2287,7 +2707,7 @@ def test_get_schema_rest_flattened(): def test_get_schema_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2302,7 +2722,7 @@ def test_get_schema_rest_flattened_error(transport: str = "rest"): def test_get_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2315,7 +2735,7 @@ def test_get_schema_rest_error(): ) def test_list_schemas_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2366,7 +2786,7 @@ def test_list_schemas_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_schemas._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2375,7 +2795,7 @@ def test_list_schemas_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_schemas._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2391,7 +2811,7 @@ def test_list_schemas_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2433,7 +2853,7 @@ def test_list_schemas_rest_required_fields( def test_list_schemas_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_schemas._get_unset_required_fields({}) @@ -2451,7 +2871,7 @@ def test_list_schemas_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_schemas_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -2509,7 +2929,7 @@ def test_list_schemas_rest_bad_request( transport: str = "rest", request_type=schema_service.ListSchemasRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2531,7 +2951,7 @@ def test_list_schemas_rest_bad_request( def test_list_schemas_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2575,7 +2995,7 @@ def test_list_schemas_rest_flattened(): def test_list_schemas_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2590,7 +3010,7 @@ def test_list_schemas_rest_flattened_error(transport: str = "rest"): def test_list_schemas_rest_pager(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2662,7 +3082,7 @@ def test_list_schemas_rest_pager(transport: str = "rest"): ) def test_create_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2782,7 +3202,7 @@ def test_create_schema_rest_required_fields( assert "schemaId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2794,7 +3214,7 @@ def test_create_schema_rest_required_fields( jsonified_request["schemaId"] = "schema_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_schema._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("schema_id",)) @@ -2807,7 +3227,7 @@ def test_create_schema_rest_required_fields( assert jsonified_request["schemaId"] == "schema_id_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2853,7 +3273,7 @@ def test_create_schema_rest_required_fields( def test_create_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_schema._get_unset_required_fields({}) @@ -2872,7 +3292,7 @@ def test_create_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -2932,7 +3352,7 @@ def test_create_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.CreateSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2954,7 +3374,7 @@ def test_create_schema_rest_bad_request( def test_create_schema_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3006,7 +3426,7 @@ def test_create_schema_rest_flattened(): def test_create_schema_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3031,7 +3451,7 @@ def test_create_schema_rest_flattened_error(transport: str = "rest"): def test_create_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3044,7 +3464,7 @@ def test_create_schema_rest_error(): ) def test_update_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3165,14 +3585,14 @@ def test_update_schema_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_schema._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("allow_missing",)) @@ -3181,7 +3601,7 @@ def test_update_schema_rest_required_fields( # verify required fields with non-default values are left alone client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3221,7 +3641,7 @@ def test_update_schema_rest_required_fields( def test_update_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_schema._get_unset_required_fields({}) @@ -3231,7 +3651,7 @@ def test_update_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -3291,7 +3711,7 @@ def test_update_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.UpdateSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3317,7 +3737,7 @@ def test_update_schema_rest_bad_request( def test_update_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3330,7 +3750,7 @@ def test_update_schema_rest_error(): ) def test_delete_schema_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3378,7 +3798,7 @@ def test_delete_schema_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3387,7 +3807,7 @@ def test_delete_schema_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3396,7 +3816,7 @@ def test_delete_schema_rest_required_fields( assert jsonified_request["name"] == "name_value" client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3435,7 +3855,7 @@ def test_delete_schema_rest_required_fields( def test_delete_schema_rest_unset_required_fields(): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_schema._get_unset_required_fields({}) @@ -3445,7 +3865,7 @@ def test_delete_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_schema_rest_interceptors(null_interceptor): transport = transports.SchemaServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SchemaServiceRestInterceptor(), @@ -3505,7 +3925,7 @@ def test_delete_schema_rest_bad_request( transport: str = "rest", request_type=schema_service.DeleteSchemaRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3529,7 +3949,7 @@ def test_delete_schema_rest_bad_request( def test_delete_schema_rest_flattened(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3571,7 +3991,7 @@ def test_delete_schema_rest_flattened(): def test_delete_schema_rest_flattened_error(transport: str = "rest"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3586,24 +4006,24 @@ def test_delete_schema_rest_flattened_error(transport: str = "rest"): def test_delete_schema_rest_error(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SchemaServiceClient( @@ -3613,7 +4033,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3624,16 +4044,17 @@ 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 = SchemaServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SchemaServiceClient( @@ -3645,7 +4066,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SchemaServiceClient(transport=transport) assert client.transport is transport @@ -3654,13 +4075,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SchemaServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SchemaServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3677,7 +4098,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3691,7 +4112,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SchemaServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3699,7 +4120,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3711,7 +4132,7 @@ def test_schema_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SchemaServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3723,7 +4144,7 @@ def test_schema_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SchemaServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3766,7 +4187,7 @@ def test_schema_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1beta.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SchemaServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3785,7 +4206,7 @@ def test_schema_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1beta.services.schema_service.transports.SchemaServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SchemaServiceTransport() adc.assert_called_once() @@ -3793,7 +4214,7 @@ def test_schema_service_base_transport_with_adc(): def test_schema_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SchemaServiceClient() adc.assert_called_once_with( scopes=None, @@ -3813,7 +4234,7 @@ def test_schema_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -3860,7 +4281,7 @@ def test_schema_service_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3888,7 +4309,7 @@ def test_schema_service_transport_create_channel(transport_class, grpc_helpers): ], ) def test_schema_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3926,7 +4347,7 @@ def test_schema_service_grpc_transport_client_cert_source_for_mtls(transport_cla def test_schema_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -3938,7 +4359,7 @@ def test_schema_service_http_transport_client_cert_source_for_mtls(): def test_schema_service_rest_lro_client(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -3963,7 +4384,7 @@ def test_schema_service_rest_lro_client(): ) def test_schema_service_host_no_port(transport_name): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -3986,7 +4407,7 @@ def test_schema_service_host_no_port(transport_name): ) def test_schema_service_host_with_port(transport_name): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -4006,8 +4427,8 @@ def test_schema_service_host_with_port(transport_name): ], ) def test_schema_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SchemaServiceClient( credentials=creds1, transport=transport_name, @@ -4081,7 +4502,7 @@ def test_schema_service_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4159,7 +4580,7 @@ def test_schema_service_transport_channel_mtls_with_adc(transport_class): def test_schema_service_grpc_lro_client(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -4176,7 +4597,7 @@ def test_schema_service_grpc_lro_client(): def test_schema_service_grpc_lro_async_client(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -4356,7 +4777,7 @@ def test_client_with_default_client_info(): transports.SchemaServiceTransport, "_prep_wrapped_messages" ) as prep: client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4366,7 +4787,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SchemaServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4375,7 +4796,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4390,7 +4811,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4423,7 +4844,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -4453,7 +4874,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4486,7 +4907,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -4514,7 +4935,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4539,7 +4960,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4565,7 +4986,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4594,7 +5015,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4623,7 +5044,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4641,7 +5062,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4659,7 +5080,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4684,7 +5105,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4710,7 +5131,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4739,7 +5160,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4768,7 +5189,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -4786,7 +5207,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SchemaServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -4810,7 +5231,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -4827,7 +5248,7 @@ def test_client_ctx(): ] for transport in transports: client = SchemaServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -4858,7 +5279,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_service.py index 405e07ee738a..a4d8346093b8 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_search_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -69,6 +69,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -98,6 +121,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert SearchServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert SearchServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert SearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + SearchServiceClient._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 SearchServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert SearchServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert SearchServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + SearchServiceClient._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 SearchServiceClient._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 SearchServiceClient._get_client_cert_source(None, False) is None + assert ( + SearchServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + SearchServiceClient._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 ( + SearchServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + SearchServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + SearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), +) +@mock.patch.object( + SearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = SearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + SearchServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + SearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == SearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, default_universe, "always") + == SearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == SearchServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + SearchServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + SearchServiceClient._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 ( + SearchServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + SearchServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + SearchServiceClient._get_universe_domain(None, None) + == SearchServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + SearchServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (SearchServiceClient, transports.SearchServiceGrpcTransport, "grpc"), + (SearchServiceClient, transports.SearchServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -107,7 +387,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_search_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -159,7 +439,7 @@ def test_search_service_client_service_account_always_use_jwt( ], ) def test_search_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -209,20 +489,22 @@ def test_search_service_client_get_transport_class(): ) @mock.patch.object( SearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), ) @mock.patch.object( SearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), ) def test_search_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(SearchServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -257,7 +539,9 @@ def test_search_service_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, @@ -287,15 +571,23 @@ def test_search_service_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") @@ -305,7 +597,9 @@ def test_search_service_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", @@ -323,7 +617,9 @@ def test_search_service_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, @@ -356,13 +652,13 @@ def test_search_service_client_client_options( ) @mock.patch.object( SearchServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), ) @mock.patch.object( SearchServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(SearchServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_search_service_client_mtls_env_auto( @@ -385,7 +681,9 @@ def test_search_service_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 @@ -417,7 +715,9 @@ def test_search_service_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 @@ -451,7 +751,9 @@ def test_search_service_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, @@ -541,6 +843,118 @@ def test_search_service_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", [SearchServiceClient, SearchServiceAsyncClient] +) +@mock.patch.object( + SearchServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceClient), +) +@mock.patch.object( + SearchServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(SearchServiceAsyncClient), +) +def test_search_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = SearchServiceClient._DEFAULT_UNIVERSE + default_endpoint = SearchServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = SearchServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -567,7 +981,9 @@ def test_search_service_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, @@ -607,7 +1023,9 @@ def test_search_service_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, @@ -667,7 +1085,9 @@ def test_search_service_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, @@ -684,8 +1104,8 @@ def test_search_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -714,7 +1134,7 @@ def test_search_service_client_create_channel_credentials_file( ) def test_search(request_type, transport: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -754,7 +1174,7 @@ def test_search_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -771,7 +1191,7 @@ async def test_search_async( transport: str = "grpc_asyncio", request_type=search_service.SearchRequest ): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -816,7 +1236,7 @@ async def test_search_async_from_dict(): def test_search_field_headers(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -846,7 +1266,7 @@ def test_search_field_headers(): @pytest.mark.asyncio async def test_search_field_headers_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -877,7 +1297,7 @@ async def test_search_field_headers_async(): def test_search_pager(transport_name: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -929,7 +1349,7 @@ def test_search_pager(transport_name: str = "grpc"): def test_search_pages(transport_name: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -971,7 +1391,7 @@ def test_search_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_search_async_pager(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1023,7 +1443,7 @@ async def test_search_async_pager(): @pytest.mark.asyncio async def test_search_async_pages(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1076,7 +1496,7 @@ async def test_search_async_pages(): ) def test_search_rest(request_type): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1137,7 +1557,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1146,7 +1566,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): jsonified_request["servingConfig"] = "serving_config_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1155,7 +1575,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): assert jsonified_request["servingConfig"] == "serving_config_value" client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1198,7 +1618,7 @@ def test_search_rest_required_fields(request_type=search_service.SearchRequest): def test_search_rest_unset_required_fields(): transport = transports.SearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search._get_unset_required_fields({}) @@ -1208,7 +1628,7 @@ def test_search_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_rest_interceptors(null_interceptor): transport = transports.SearchServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.SearchServiceRestInterceptor(), @@ -1264,7 +1684,7 @@ def test_search_rest_bad_request( transport: str = "rest", request_type=search_service.SearchRequest ): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1288,7 +1708,7 @@ def test_search_rest_bad_request( def test_search_rest_pager(transport: str = "rest"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1354,17 +1774,17 @@ def test_search_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchServiceClient( @@ -1374,7 +1794,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1385,16 +1805,17 @@ 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 = SearchServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = SearchServiceClient( @@ -1406,7 +1827,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = SearchServiceClient(transport=transport) assert client.transport is transport @@ -1415,13 +1836,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.SearchServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.SearchServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1438,7 +1859,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1452,7 +1873,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = SearchServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1460,7 +1881,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1472,7 +1893,7 @@ def test_search_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.SearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1484,7 +1905,7 @@ def test_search_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.SearchServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1518,7 +1939,7 @@ def test_search_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1beta.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SearchServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1537,7 +1958,7 @@ def test_search_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1beta.services.search_service.transports.SearchServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.SearchServiceTransport() adc.assert_called_once() @@ -1545,7 +1966,7 @@ def test_search_service_base_transport_with_adc(): def test_search_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) SearchServiceClient() adc.assert_called_once_with( scopes=None, @@ -1565,7 +1986,7 @@ def test_search_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1612,7 +2033,7 @@ def test_search_service_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1640,7 +2061,7 @@ def test_search_service_transport_create_channel(transport_class, grpc_helpers): ], ) def test_search_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1678,7 +2099,7 @@ def test_search_service_grpc_transport_client_cert_source_for_mtls(transport_cla def test_search_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1698,7 +2119,7 @@ def test_search_service_http_transport_client_cert_source_for_mtls(): ) def test_search_service_host_no_port(transport_name): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -1721,7 +2142,7 @@ def test_search_service_host_no_port(transport_name): ) def test_search_service_host_with_port(transport_name): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -1741,8 +2162,8 @@ def test_search_service_host_with_port(transport_name): ], ) def test_search_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = SearchServiceClient( credentials=creds1, transport=transport_name, @@ -1804,7 +2225,7 @@ def test_search_service_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2084,7 +2505,7 @@ def test_client_with_default_client_info(): transports.SearchServiceTransport, "_prep_wrapped_messages" ) as prep: client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2094,7 +2515,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = SearchServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2103,7 +2524,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2118,7 +2539,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2151,7 +2572,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -2181,7 +2602,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2214,7 +2635,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -2242,7 +2663,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2267,7 +2688,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2293,7 +2714,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2322,7 +2743,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2351,7 +2772,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2369,7 +2790,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2387,7 +2808,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2412,7 +2833,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2438,7 +2859,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2467,7 +2888,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2496,7 +2917,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2514,7 +2935,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = SearchServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2538,7 +2959,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2555,7 +2976,7 @@ def test_client_ctx(): ] for transport in transports: client = SearchServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2586,7 +3007,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, diff --git a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_user_event_service.py b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_user_event_service.py index e5baca929fa2..a513c956f608 100644 --- a/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_user_event_service.py +++ b/packages/google-cloud-discoveryengine/tests/unit/gapic/discoveryengine_v1beta/test_user_event_service.py @@ -36,7 +36,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -86,6 +86,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -116,6 +139,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert UserEventServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert UserEventServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert UserEventServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + UserEventServiceClient._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 UserEventServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert UserEventServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert UserEventServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + UserEventServiceClient._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 UserEventServiceClient._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 UserEventServiceClient._get_client_cert_source(None, False) is None + assert ( + UserEventServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + UserEventServiceClient._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 ( + UserEventServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + UserEventServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + UserEventServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), +) +@mock.patch.object( + UserEventServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = UserEventServiceClient._DEFAULT_UNIVERSE + default_endpoint = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + UserEventServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + UserEventServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, default_universe, "always") + == UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + UserEventServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == UserEventServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + UserEventServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + UserEventServiceClient._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 ( + UserEventServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + UserEventServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + UserEventServiceClient._get_universe_domain(None, None) + == UserEventServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + UserEventServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (UserEventServiceClient, transports.UserEventServiceGrpcTransport, "grpc"), + (UserEventServiceClient, transports.UserEventServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -127,7 +411,7 @@ def test__get_default_mtls_endpoint(): def test_user_event_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -181,7 +465,7 @@ def test_user_event_service_client_service_account_always_use_jwt( def test_user_event_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -231,20 +515,22 @@ def test_user_event_service_client_get_transport_class(): ) @mock.patch.object( UserEventServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), ) @mock.patch.object( UserEventServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), ) def test_user_event_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(UserEventServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -279,7 +565,9 @@ def test_user_event_service_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, @@ -309,15 +597,23 @@ def test_user_event_service_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") @@ -327,7 +623,9 @@ def test_user_event_service_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", @@ -345,7 +643,9 @@ def test_user_event_service_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, @@ -398,13 +698,13 @@ def test_user_event_service_client_client_options( ) @mock.patch.object( UserEventServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), ) @mock.patch.object( UserEventServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(UserEventServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_user_event_service_client_mtls_env_auto( @@ -427,7 +727,9 @@ def test_user_event_service_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 @@ -459,7 +761,9 @@ def test_user_event_service_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 @@ -493,7 +797,9 @@ def test_user_event_service_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, @@ -583,6 +889,118 @@ def test_user_event_service_client_get_mtls_endpoint_and_cert_source(client_clas 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", [UserEventServiceClient, UserEventServiceAsyncClient] +) +@mock.patch.object( + UserEventServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceClient), +) +@mock.patch.object( + UserEventServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(UserEventServiceAsyncClient), +) +def test_user_event_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = UserEventServiceClient._DEFAULT_UNIVERSE + default_endpoint = UserEventServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = UserEventServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -609,7 +1027,9 @@ def test_user_event_service_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, @@ -654,7 +1074,9 @@ def test_user_event_service_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, @@ -714,7 +1136,9 @@ def test_user_event_service_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, @@ -731,8 +1155,8 @@ def test_user_event_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -761,7 +1185,7 @@ def test_user_event_service_client_create_channel_credentials_file( ) def test_write_user_event(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -805,7 +1229,7 @@ def test_write_user_event_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -823,7 +1247,7 @@ async def test_write_user_event_async( request_type=user_event_service.WriteUserEventRequest, ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -872,7 +1296,7 @@ async def test_write_user_event_async_from_dict(): def test_write_user_event_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -902,7 +1326,7 @@ def test_write_user_event_field_headers(): @pytest.mark.asyncio async def test_write_user_event_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -940,7 +1364,7 @@ async def test_write_user_event_field_headers_async(): ) def test_collect_user_event(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -974,7 +1398,7 @@ def test_collect_user_event_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -994,7 +1418,7 @@ async def test_collect_user_event_async( request_type=user_event_service.CollectUserEventRequest, ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1033,7 +1457,7 @@ async def test_collect_user_event_async_from_dict(): def test_collect_user_event_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1065,7 +1489,7 @@ def test_collect_user_event_field_headers(): @pytest.mark.asyncio async def test_collect_user_event_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1105,7 +1529,7 @@ async def test_collect_user_event_field_headers_async(): ) def test_import_user_events(request_type, transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1134,7 +1558,7 @@ def test_import_user_events_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1153,7 +1577,7 @@ async def test_import_user_events_async( transport: str = "grpc_asyncio", request_type=import_config.ImportUserEventsRequest ): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1187,7 +1611,7 @@ async def test_import_user_events_async_from_dict(): def test_import_user_events_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1219,7 +1643,7 @@ def test_import_user_events_field_headers(): @pytest.mark.asyncio async def test_import_user_events_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1259,7 +1683,7 @@ async def test_import_user_events_field_headers_async(): ) def test_write_user_event_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1446,7 +1870,7 @@ def test_write_user_event_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).write_user_event._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1455,7 +1879,7 @@ def test_write_user_event_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).write_user_event._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1464,7 +1888,7 @@ def test_write_user_event_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1507,7 +1931,7 @@ def test_write_user_event_rest_required_fields( def test_write_user_event_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.write_user_event._get_unset_required_fields({}) @@ -1525,7 +1949,7 @@ def test_write_user_event_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_write_user_event_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -1581,7 +2005,7 @@ def test_write_user_event_rest_bad_request( transport: str = "rest", request_type=user_event_service.WriteUserEventRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1603,7 +2027,7 @@ def test_write_user_event_rest_bad_request( def test_write_user_event_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -1616,7 +2040,7 @@ def test_write_user_event_rest_error(): ) def test_collect_user_event_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1669,7 +2093,7 @@ def test_collect_user_event_rest_required_fields( assert "userEvent" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).collect_user_event._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1681,7 +2105,7 @@ def test_collect_user_event_rest_required_fields( jsonified_request["userEvent"] = "user_event_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).collect_user_event._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -1700,7 +2124,7 @@ def test_collect_user_event_rest_required_fields( assert jsonified_request["userEvent"] == "user_event_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1746,7 +2170,7 @@ def test_collect_user_event_rest_required_fields( def test_collect_user_event_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.collect_user_event._get_unset_required_fields({}) @@ -1770,7 +2194,7 @@ def test_collect_user_event_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_collect_user_event_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -1826,7 +2250,7 @@ def test_collect_user_event_rest_bad_request( transport: str = "rest", request_type=user_event_service.CollectUserEventRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1848,7 +2272,7 @@ def test_collect_user_event_rest_bad_request( def test_collect_user_event_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -1861,7 +2285,7 @@ def test_collect_user_event_rest_error(): ) def test_import_user_events_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1907,7 +2331,7 @@ def test_import_user_events_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_user_events._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1916,7 +2340,7 @@ def test_import_user_events_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_user_events._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1925,7 +2349,7 @@ def test_import_user_events_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1965,7 +2389,7 @@ def test_import_user_events_rest_required_fields( def test_import_user_events_rest_unset_required_fields(): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_user_events._get_unset_required_fields({}) @@ -1975,7 +2399,7 @@ def test_import_user_events_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_user_events_rest_interceptors(null_interceptor): transport = transports.UserEventServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.UserEventServiceRestInterceptor(), @@ -2035,7 +2459,7 @@ def test_import_user_events_rest_bad_request( transport: str = "rest", request_type=import_config.ImportUserEventsRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2057,24 +2481,24 @@ def test_import_user_events_rest_bad_request( def test_import_user_events_rest_error(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = UserEventServiceClient( @@ -2084,7 +2508,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -2095,16 +2519,17 @@ 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 = UserEventServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = UserEventServiceClient( @@ -2116,7 +2541,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = UserEventServiceClient(transport=transport) assert client.transport is transport @@ -2125,13 +2550,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.UserEventServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.UserEventServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -2148,7 +2573,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -2162,7 +2587,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = UserEventServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -2170,7 +2595,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -2182,7 +2607,7 @@ def test_user_event_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.UserEventServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -2194,7 +2619,7 @@ def test_user_event_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.UserEventServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -2235,7 +2660,7 @@ def test_user_event_service_base_transport_with_credentials_file(): "google.cloud.discoveryengine_v1beta.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.UserEventServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2254,7 +2679,7 @@ def test_user_event_service_base_transport_with_adc(): "google.cloud.discoveryengine_v1beta.services.user_event_service.transports.UserEventServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.UserEventServiceTransport() adc.assert_called_once() @@ -2262,7 +2687,7 @@ def test_user_event_service_base_transport_with_adc(): def test_user_event_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) UserEventServiceClient() adc.assert_called_once_with( scopes=None, @@ -2282,7 +2707,7 @@ def test_user_event_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2329,7 +2754,7 @@ def test_user_event_service_transport_create_channel(transport_class, grpc_helpe ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2357,7 +2782,7 @@ def test_user_event_service_transport_create_channel(transport_class, grpc_helpe ], ) def test_user_event_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2395,7 +2820,7 @@ def test_user_event_service_grpc_transport_client_cert_source_for_mtls(transport def test_user_event_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -2407,7 +2832,7 @@ def test_user_event_service_http_transport_client_cert_source_for_mtls(): def test_user_event_service_rest_lro_client(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -2432,7 +2857,7 @@ def test_user_event_service_rest_lro_client(): ) def test_user_event_service_host_no_port(transport_name): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com" ), @@ -2455,7 +2880,7 @@ def test_user_event_service_host_no_port(transport_name): ) def test_user_event_service_host_with_port(transport_name): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="discoveryengine.googleapis.com:8000" ), @@ -2475,8 +2900,8 @@ def test_user_event_service_host_with_port(transport_name): ], ) def test_user_event_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = UserEventServiceClient( credentials=creds1, transport=transport_name, @@ -2546,7 +2971,7 @@ def test_user_event_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2624,7 +3049,7 @@ def test_user_event_service_transport_channel_mtls_with_adc(transport_class): def test_user_event_service_grpc_lro_client(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -2641,7 +3066,7 @@ def test_user_event_service_grpc_lro_client(): def test_user_event_service_grpc_lro_async_client(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -2826,7 +3251,7 @@ def test_client_with_default_client_info(): transports.UserEventServiceTransport, "_prep_wrapped_messages" ) as prep: client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2836,7 +3261,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = UserEventServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2845,7 +3270,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2860,7 +3285,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2893,7 +3318,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -2923,7 +3348,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2956,7 +3381,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -2984,7 +3409,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3009,7 +3434,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3035,7 +3460,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3064,7 +3489,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3093,7 +3518,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3111,7 +3536,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -3129,7 +3554,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3154,7 +3579,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3180,7 +3605,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3209,7 +3634,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3238,7 +3663,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3256,7 +3681,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = UserEventServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -3280,7 +3705,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3297,7 +3722,7 @@ def test_client_ctx(): ] for transport in transports: client = UserEventServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3328,7 +3753,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, diff --git a/packages/google-cloud-dlp/google/cloud/dlp/gapic_version.py b/packages/google-cloud-dlp/google/cloud/dlp/gapic_version.py index cd6578cfc6b0..360a0d13ebdd 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp/gapic_version.py +++ b/packages/google-cloud-dlp/google/cloud/dlp/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "3.14.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dlp/google/cloud/dlp_v2/gapic_version.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/gapic_version.py index cd6578cfc6b0..360a0d13ebdd 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/gapic_version.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "3.14.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/async_client.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/async_client.py index 4ad37ba402ed..444fd9f71003 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/async_client.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.dlp_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore @@ -70,8 +70,12 @@ class DlpServiceAsyncClient: _client: DlpServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DlpServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DlpServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DlpServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DlpServiceClient._DEFAULT_UNIVERSE deidentify_template_path = staticmethod(DlpServiceClient.deidentify_template_path) parse_deidentify_template_path = staticmethod( @@ -194,6 +198,25 @@ def transport(self) -> DlpServiceTransport: """ 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(DlpServiceClient).get_transport_class, type(DlpServiceClient) ) @@ -206,7 +229,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the dlp service client. + """Instantiates the dlp service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -217,23 +240,38 @@ def __init__( transport (Union[str, ~.DlpServiceTransport]): 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. @@ -332,6 +370,9 @@ async def sample_inspect_content(): 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, @@ -429,6 +470,9 @@ async def sample_redact_image(): 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, @@ -526,6 +570,9 @@ async def sample_deidentify_content(): 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, @@ -615,6 +662,9 @@ async def sample_reidentify_content(): 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, @@ -727,6 +777,9 @@ async def sample_list_info_types(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -870,6 +923,9 @@ async def sample_create_inspect_template(): 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, @@ -999,6 +1055,9 @@ async def sample_update_inspect_template(): 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, @@ -1120,6 +1179,9 @@ async def sample_get_inspect_template(): 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, @@ -1260,6 +1322,9 @@ async def sample_list_inspect_templates(): 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, @@ -1376,6 +1441,9 @@ async def sample_delete_inspect_template(): 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, @@ -1514,6 +1582,9 @@ async def sample_create_deidentify_template(): 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, @@ -1642,6 +1713,9 @@ async def sample_update_deidentify_template(): 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, @@ -1762,6 +1836,9 @@ async def sample_get_deidentify_template(): 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, @@ -1903,6 +1980,9 @@ async def sample_list_deidentify_templates(): 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, @@ -2020,6 +2100,9 @@ async def sample_delete_deidentify_template(): 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, @@ -2153,6 +2236,9 @@ async def sample_create_job_trigger(): 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, @@ -2278,6 +2364,9 @@ async def sample_update_job_trigger(): 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, @@ -2384,6 +2473,9 @@ async def sample_hybrid_inspect_job_trigger(): 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, @@ -2501,6 +2593,9 @@ async def sample_get_job_trigger(): 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, @@ -2636,6 +2731,9 @@ async def sample_list_job_triggers(): 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, @@ -2751,6 +2849,9 @@ async def sample_delete_job_trigger(): 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, @@ -2830,6 +2931,9 @@ async def sample_activate_job_trigger(): 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, @@ -2963,6 +3067,9 @@ async def sample_create_discovery_config(): 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, @@ -3093,6 +3200,9 @@ async def sample_update_discovery_config(): 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, @@ -3211,6 +3321,9 @@ async def sample_get_discovery_config(): 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, @@ -3338,6 +3451,9 @@ async def sample_list_discovery_configs(): 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, @@ -3451,6 +3567,9 @@ async def sample_delete_discovery_config(): 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, @@ -3600,6 +3719,9 @@ async def sample_create_dlp_job(): 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, @@ -3737,6 +3859,9 @@ async def sample_list_dlp_jobs(): 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, @@ -3861,6 +3986,9 @@ async def sample_get_dlp_job(): 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, @@ -3970,6 +4098,9 @@ async def sample_delete_dlp_job(): 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, @@ -4044,6 +4175,9 @@ async def sample_cancel_dlp_job(): 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, @@ -4179,6 +4313,9 @@ async def sample_create_stored_info_type(): 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, @@ -4310,6 +4447,9 @@ async def sample_update_stored_info_type(): 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, @@ -4428,6 +4568,9 @@ async def sample_get_stored_info_type(): 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, @@ -4565,6 +4708,9 @@ async def sample_list_stored_info_types(): 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, @@ -4682,6 +4828,9 @@ async def sample_delete_stored_info_type(): 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, @@ -4784,6 +4933,9 @@ async def sample_hybrid_inspect_dlp_job(): 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, @@ -4857,6 +5009,9 @@ async def sample_finish_dlp_job(): 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-dlp/google/cloud/dlp_v2/services/dlp_service/client.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/client.py index 209fd322ab2e..d0c2c62d1694 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/client.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.dlp_v2 import gapic_version as package_version 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.location import locations_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore @@ -138,11 +139,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 = "dlp.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "dlp.{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 @@ -428,7 +433,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 @@ -458,6 +463,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") @@ -491,6 +501,175 @@ 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 + + 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 + + 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 = DlpServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DlpServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DlpServiceClient._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 = DlpServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DlpServiceClient._DEFAULT_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 DlpServiceClient._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, *, @@ -510,22 +689,32 @@ def __init__( transport (Union[str, DlpServiceTransport]): 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. @@ -536,17 +725,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, + ) = DlpServiceClient._read_environment_variables() + self._client_cert_source = DlpServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = DlpServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -555,20 +761,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, DlpServiceTransport): + transport_provided = isinstance(transport, DlpServiceTransport) + if transport_provided: # transport is a DlpServiceTransport 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(DlpServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or DlpServiceClient._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( @@ -578,17 +794,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 inspect_content( @@ -669,6 +885,9 @@ def sample_inspect_content(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -757,6 +976,9 @@ def sample_redact_image(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -845,6 +1067,9 @@ def sample_deidentify_content(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -925,6 +1150,9 @@ def sample_reidentify_content(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1027,6 +1255,9 @@ def sample_list_info_types(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_info_types] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1170,6 +1401,9 @@ def sample_create_inspect_template(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1299,6 +1533,9 @@ def sample_update_inspect_template(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1410,6 +1647,9 @@ def sample_get_inspect_template(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1540,6 +1780,9 @@ def sample_list_inspect_templates(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1646,6 +1889,9 @@ def sample_delete_inspect_template(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1786,6 +2032,9 @@ def sample_create_deidentify_template(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1916,6 +2165,9 @@ def sample_update_deidentify_template(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2026,6 +2278,9 @@ def sample_get_deidentify_template(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2159,6 +2414,9 @@ def sample_list_deidentify_templates(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2268,6 +2526,9 @@ def sample_delete_deidentify_template(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -2401,6 +2662,9 @@ def sample_create_job_trigger(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2526,6 +2790,9 @@ def sample_update_job_trigger(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2634,6 +2901,9 @@ def sample_hybrid_inspect_job_trigger(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2741,6 +3011,9 @@ def sample_get_job_trigger(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2866,6 +3139,9 @@ def sample_list_job_triggers(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2971,6 +3247,9 @@ def sample_delete_job_trigger(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3051,6 +3330,9 @@ def sample_activate_job_trigger(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3184,6 +3466,9 @@ def sample_create_discovery_config(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3314,6 +3599,9 @@ def sample_update_discovery_config(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3422,6 +3710,9 @@ def sample_get_discovery_config(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3539,6 +3830,9 @@ def sample_list_discovery_configs(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3642,6 +3936,9 @@ def sample_delete_discovery_config(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3791,6 +4088,9 @@ def sample_create_dlp_job(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3918,6 +4218,9 @@ def sample_list_dlp_jobs(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4032,6 +4335,9 @@ def sample_get_dlp_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4131,6 +4437,9 @@ def sample_delete_dlp_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -4206,6 +4515,9 @@ def sample_cancel_dlp_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -4341,6 +4653,9 @@ def sample_create_stored_info_type(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4472,6 +4787,9 @@ def sample_update_stored_info_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4580,6 +4898,9 @@ def sample_get_stored_info_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4707,6 +5028,9 @@ def sample_list_stored_info_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4814,6 +5138,9 @@ def sample_delete_stored_info_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -4916,6 +5243,9 @@ def sample_hybrid_inspect_dlp_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4990,6 +5320,9 @@ def sample_finish_dlp_job(): 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-dlp/google/cloud/dlp_v2/services/dlp_service/transports/base.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/base.py index 6042e3af0cfe..5e5d6c724754 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/base.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dlp.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 @@ -121,6 +121,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-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py index ccf00215fc88..accdb8025b16 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py @@ -75,7 +75,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dlp.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-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py index 8e339c593044..86bef6c1e91c 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py @@ -120,7 +120,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dlp.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-dlp/google/cloud/dlp_v2/services/dlp_service/transports/rest.py b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/rest.py index 50895ceae57b..afc23fb890fe 100644 --- a/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/rest.py +++ b/packages/google-cloud-dlp/google/cloud/dlp_v2/services/dlp_service/transports/rest.py @@ -32,9 +32,9 @@ from requests import __version__ as requests_version 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.protobuf import empty_pb2 # type: ignore @@ -1165,7 +1165,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'dlp.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-dlp/noxfile.py b/packages/google-cloud-dlp/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-dlp/noxfile.py +++ b/packages/google-cloud-dlp/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-dlp/samples/generated_samples/snippet_metadata_google.privacy.dlp.v2.json b/packages/google-cloud-dlp/samples/generated_samples/snippet_metadata_google.privacy.dlp.v2.json index af2ffe7a4fde..767b85649645 100644 --- a/packages/google-cloud-dlp/samples/generated_samples/snippet_metadata_google.privacy.dlp.v2.json +++ b/packages/google-cloud-dlp/samples/generated_samples/snippet_metadata_google.privacy.dlp.v2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-dlp", - "version": "3.14.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-dlp/tests/unit/gapic/dlp_v2/test_dlp_service.py b/packages/google-cloud-dlp/tests/unit/gapic/dlp_v2/test_dlp_service.py index 00952daf2f8e..4ade2eedcdca 100644 --- a/packages/google-cloud-dlp/tests/unit/gapic/dlp_v2/test_dlp_service.py +++ b/packages/google-cloud-dlp/tests/unit/gapic/dlp_v2/test_dlp_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -76,6 +76,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -102,6 +125,247 @@ def test__get_default_mtls_endpoint(): assert DlpServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert DlpServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DlpServiceClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DlpServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DlpServiceClient._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 DlpServiceClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DlpServiceClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DlpServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DlpServiceClient._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 DlpServiceClient._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 DlpServiceClient._get_client_cert_source(None, False) is None + assert ( + DlpServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + DlpServiceClient._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 ( + DlpServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DlpServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DlpServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DlpServiceClient), +) +@mock.patch.object( + DlpServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DlpServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DlpServiceClient._DEFAULT_UNIVERSE + default_endpoint = DlpServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DlpServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DlpServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DlpServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DlpServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DlpServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DlpServiceClient._get_api_endpoint(None, None, default_universe, "always") + == DlpServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DlpServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DlpServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DlpServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DlpServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DlpServiceClient._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 ( + DlpServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DlpServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DlpServiceClient._get_universe_domain(None, None) + == DlpServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DlpServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DlpServiceClient, transports.DlpServiceGrpcTransport, "grpc"), + (DlpServiceClient, transports.DlpServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -111,7 +375,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_dlp_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -163,7 +427,7 @@ def test_dlp_service_client_service_account_always_use_jwt( ], ) def test_dlp_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -212,19 +476,23 @@ def test_dlp_service_client_get_transport_class(): ], ) @mock.patch.object( - DlpServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DlpServiceClient) + DlpServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DlpServiceClient), ) @mock.patch.object( DlpServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DlpServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DlpServiceAsyncClient), ) def test_dlp_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(DlpServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -259,7 +527,9 @@ def test_dlp_service_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, @@ -289,15 +559,23 @@ def test_dlp_service_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") @@ -307,7 +585,9 @@ def test_dlp_service_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", @@ -325,7 +605,9 @@ def test_dlp_service_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, @@ -357,12 +639,14 @@ def test_dlp_service_client_client_options( ], ) @mock.patch.object( - DlpServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DlpServiceClient) + DlpServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DlpServiceClient), ) @mock.patch.object( DlpServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DlpServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DlpServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_dlp_service_client_mtls_env_auto( @@ -385,7 +669,9 @@ def test_dlp_service_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 @@ -417,7 +703,9 @@ def test_dlp_service_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 @@ -451,7 +739,9 @@ def test_dlp_service_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, @@ -537,6 +827,116 @@ def test_dlp_service_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", [DlpServiceClient, DlpServiceAsyncClient]) +@mock.patch.object( + DlpServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DlpServiceClient), +) +@mock.patch.object( + DlpServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DlpServiceAsyncClient), +) +def test_dlp_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DlpServiceClient._DEFAULT_UNIVERSE + default_endpoint = DlpServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DlpServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -563,7 +963,9 @@ def test_dlp_service_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, @@ -598,7 +1000,9 @@ def test_dlp_service_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, @@ -651,7 +1055,9 @@ def test_dlp_service_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, @@ -668,8 +1074,8 @@ def test_dlp_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -698,7 +1104,7 @@ def test_dlp_service_client_create_channel_credentials_file( ) def test_inspect_content(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -725,7 +1131,7 @@ def test_inspect_content_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -742,7 +1148,7 @@ async def test_inspect_content_async( transport: str = "grpc_asyncio", request_type=dlp.InspectContentRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -774,7 +1180,7 @@ async def test_inspect_content_async_from_dict(): def test_inspect_content_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -804,7 +1210,7 @@ def test_inspect_content_field_headers(): @pytest.mark.asyncio async def test_inspect_content_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -842,7 +1248,7 @@ async def test_inspect_content_field_headers_async(): ) def test_redact_image(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -874,7 +1280,7 @@ def test_redact_image_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -891,7 +1297,7 @@ async def test_redact_image_async( transport: str = "grpc_asyncio", request_type=dlp.RedactImageRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -928,7 +1334,7 @@ async def test_redact_image_async_from_dict(): def test_redact_image_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -958,7 +1364,7 @@ def test_redact_image_field_headers(): @pytest.mark.asyncio async def test_redact_image_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -996,7 +1402,7 @@ async def test_redact_image_field_headers_async(): ) def test_deidentify_content(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1025,7 +1431,7 @@ def test_deidentify_content_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1044,7 +1450,7 @@ async def test_deidentify_content_async( transport: str = "grpc_asyncio", request_type=dlp.DeidentifyContentRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1078,7 +1484,7 @@ async def test_deidentify_content_async_from_dict(): def test_deidentify_content_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1110,7 +1516,7 @@ def test_deidentify_content_field_headers(): @pytest.mark.asyncio async def test_deidentify_content_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1150,7 +1556,7 @@ async def test_deidentify_content_field_headers_async(): ) def test_reidentify_content(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1179,7 +1585,7 @@ def test_reidentify_content_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1198,7 +1604,7 @@ async def test_reidentify_content_async( transport: str = "grpc_asyncio", request_type=dlp.ReidentifyContentRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1232,7 +1638,7 @@ async def test_reidentify_content_async_from_dict(): def test_reidentify_content_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1264,7 +1670,7 @@ def test_reidentify_content_field_headers(): @pytest.mark.asyncio async def test_reidentify_content_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1304,7 +1710,7 @@ async def test_reidentify_content_field_headers_async(): ) def test_list_info_types(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1331,7 +1737,7 @@ def test_list_info_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1348,7 +1754,7 @@ async def test_list_info_types_async( transport: str = "grpc_asyncio", request_type=dlp.ListInfoTypesRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1380,7 +1786,7 @@ async def test_list_info_types_async_from_dict(): def test_list_info_types_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1404,7 +1810,7 @@ def test_list_info_types_flattened(): def test_list_info_types_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1419,7 +1825,7 @@ def test_list_info_types_flattened_error(): @pytest.mark.asyncio async def test_list_info_types_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1448,7 +1854,7 @@ async def test_list_info_types_flattened_async(): @pytest.mark.asyncio async def test_list_info_types_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1469,7 +1875,7 @@ async def test_list_info_types_flattened_error_async(): ) def test_create_inspect_template(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1505,7 +1911,7 @@ def test_create_inspect_template_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1524,7 +1930,7 @@ async def test_create_inspect_template_async( transport: str = "grpc_asyncio", request_type=dlp.CreateInspectTemplateRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1565,7 +1971,7 @@ async def test_create_inspect_template_async_from_dict(): def test_create_inspect_template_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1597,7 +2003,7 @@ def test_create_inspect_template_field_headers(): @pytest.mark.asyncio async def test_create_inspect_template_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1628,7 +2034,7 @@ async def test_create_inspect_template_field_headers_async(): def test_create_inspect_template_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1658,7 +2064,7 @@ def test_create_inspect_template_flattened(): def test_create_inspect_template_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1674,7 +2080,7 @@ def test_create_inspect_template_flattened_error(): @pytest.mark.asyncio async def test_create_inspect_template_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1707,7 +2113,7 @@ async def test_create_inspect_template_flattened_async(): @pytest.mark.asyncio async def test_create_inspect_template_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1729,7 +2135,7 @@ async def test_create_inspect_template_flattened_error_async(): ) def test_update_inspect_template(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1765,7 +2171,7 @@ def test_update_inspect_template_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1784,7 +2190,7 @@ async def test_update_inspect_template_async( transport: str = "grpc_asyncio", request_type=dlp.UpdateInspectTemplateRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1825,7 +2231,7 @@ async def test_update_inspect_template_async_from_dict(): def test_update_inspect_template_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1857,7 +2263,7 @@ def test_update_inspect_template_field_headers(): @pytest.mark.asyncio async def test_update_inspect_template_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1888,7 +2294,7 @@ async def test_update_inspect_template_field_headers_async(): def test_update_inspect_template_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1922,7 +2328,7 @@ def test_update_inspect_template_flattened(): def test_update_inspect_template_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1939,7 +2345,7 @@ def test_update_inspect_template_flattened_error(): @pytest.mark.asyncio async def test_update_inspect_template_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1976,7 +2382,7 @@ async def test_update_inspect_template_flattened_async(): @pytest.mark.asyncio async def test_update_inspect_template_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1999,7 +2405,7 @@ async def test_update_inspect_template_flattened_error_async(): ) def test_get_inspect_template(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2035,7 +2441,7 @@ def test_get_inspect_template_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2054,7 +2460,7 @@ async def test_get_inspect_template_async( transport: str = "grpc_asyncio", request_type=dlp.GetInspectTemplateRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2095,7 +2501,7 @@ async def test_get_inspect_template_async_from_dict(): def test_get_inspect_template_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2127,7 +2533,7 @@ def test_get_inspect_template_field_headers(): @pytest.mark.asyncio async def test_get_inspect_template_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2158,7 +2564,7 @@ async def test_get_inspect_template_field_headers_async(): def test_get_inspect_template_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2184,7 +2590,7 @@ def test_get_inspect_template_flattened(): def test_get_inspect_template_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2199,7 +2605,7 @@ def test_get_inspect_template_flattened_error(): @pytest.mark.asyncio async def test_get_inspect_template_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2228,7 +2634,7 @@ async def test_get_inspect_template_flattened_async(): @pytest.mark.asyncio async def test_get_inspect_template_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2249,7 +2655,7 @@ async def test_get_inspect_template_flattened_error_async(): ) def test_list_inspect_templates(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2281,7 +2687,7 @@ def test_list_inspect_templates_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2300,7 +2706,7 @@ async def test_list_inspect_templates_async( transport: str = "grpc_asyncio", request_type=dlp.ListInspectTemplatesRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2337,7 +2743,7 @@ async def test_list_inspect_templates_async_from_dict(): def test_list_inspect_templates_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2369,7 +2775,7 @@ def test_list_inspect_templates_field_headers(): @pytest.mark.asyncio async def test_list_inspect_templates_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2402,7 +2808,7 @@ async def test_list_inspect_templates_field_headers_async(): def test_list_inspect_templates_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2428,7 +2834,7 @@ def test_list_inspect_templates_flattened(): def test_list_inspect_templates_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2443,7 +2849,7 @@ def test_list_inspect_templates_flattened_error(): @pytest.mark.asyncio async def test_list_inspect_templates_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2474,7 +2880,7 @@ async def test_list_inspect_templates_flattened_async(): @pytest.mark.asyncio async def test_list_inspect_templates_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2488,7 +2894,7 @@ async def test_list_inspect_templates_flattened_error_async(): def test_list_inspect_templates_pager(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2540,7 +2946,7 @@ def test_list_inspect_templates_pager(transport_name: str = "grpc"): def test_list_inspect_templates_pages(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2584,7 +2990,7 @@ def test_list_inspect_templates_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_inspect_templates_async_pager(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2636,7 +3042,7 @@ async def test_list_inspect_templates_async_pager(): @pytest.mark.asyncio async def test_list_inspect_templates_async_pages(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2693,7 +3099,7 @@ async def test_list_inspect_templates_async_pages(): ) def test_delete_inspect_template(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2722,7 +3128,7 @@ def test_delete_inspect_template_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2741,7 +3147,7 @@ async def test_delete_inspect_template_async( transport: str = "grpc_asyncio", request_type=dlp.DeleteInspectTemplateRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2773,7 +3179,7 @@ async def test_delete_inspect_template_async_from_dict(): def test_delete_inspect_template_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2805,7 +3211,7 @@ def test_delete_inspect_template_field_headers(): @pytest.mark.asyncio async def test_delete_inspect_template_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2836,7 +3242,7 @@ async def test_delete_inspect_template_field_headers_async(): def test_delete_inspect_template_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2862,7 +3268,7 @@ def test_delete_inspect_template_flattened(): def test_delete_inspect_template_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2877,7 +3283,7 @@ def test_delete_inspect_template_flattened_error(): @pytest.mark.asyncio async def test_delete_inspect_template_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2906,7 +3312,7 @@ async def test_delete_inspect_template_flattened_async(): @pytest.mark.asyncio async def test_delete_inspect_template_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2927,7 +3333,7 @@ async def test_delete_inspect_template_flattened_error_async(): ) def test_create_deidentify_template(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2963,7 +3369,7 @@ def test_create_deidentify_template_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2982,7 +3388,7 @@ async def test_create_deidentify_template_async( transport: str = "grpc_asyncio", request_type=dlp.CreateDeidentifyTemplateRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3023,7 +3429,7 @@ async def test_create_deidentify_template_async_from_dict(): def test_create_deidentify_template_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3055,7 +3461,7 @@ def test_create_deidentify_template_field_headers(): @pytest.mark.asyncio async def test_create_deidentify_template_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3088,7 +3494,7 @@ async def test_create_deidentify_template_field_headers_async(): def test_create_deidentify_template_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3118,7 +3524,7 @@ def test_create_deidentify_template_flattened(): def test_create_deidentify_template_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3134,7 +3540,7 @@ def test_create_deidentify_template_flattened_error(): @pytest.mark.asyncio async def test_create_deidentify_template_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3169,7 +3575,7 @@ async def test_create_deidentify_template_flattened_async(): @pytest.mark.asyncio async def test_create_deidentify_template_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3191,7 +3597,7 @@ async def test_create_deidentify_template_flattened_error_async(): ) def test_update_deidentify_template(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3227,7 +3633,7 @@ def test_update_deidentify_template_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3246,7 +3652,7 @@ async def test_update_deidentify_template_async( transport: str = "grpc_asyncio", request_type=dlp.UpdateDeidentifyTemplateRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3287,7 +3693,7 @@ async def test_update_deidentify_template_async_from_dict(): def test_update_deidentify_template_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3319,7 +3725,7 @@ def test_update_deidentify_template_field_headers(): @pytest.mark.asyncio async def test_update_deidentify_template_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3352,7 +3758,7 @@ async def test_update_deidentify_template_field_headers_async(): def test_update_deidentify_template_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3386,7 +3792,7 @@ def test_update_deidentify_template_flattened(): def test_update_deidentify_template_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3403,7 +3809,7 @@ def test_update_deidentify_template_flattened_error(): @pytest.mark.asyncio async def test_update_deidentify_template_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3442,7 +3848,7 @@ async def test_update_deidentify_template_flattened_async(): @pytest.mark.asyncio async def test_update_deidentify_template_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3465,7 +3871,7 @@ async def test_update_deidentify_template_flattened_error_async(): ) def test_get_deidentify_template(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3501,7 +3907,7 @@ def test_get_deidentify_template_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3520,7 +3926,7 @@ async def test_get_deidentify_template_async( transport: str = "grpc_asyncio", request_type=dlp.GetDeidentifyTemplateRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3561,7 +3967,7 @@ async def test_get_deidentify_template_async_from_dict(): def test_get_deidentify_template_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3593,7 +3999,7 @@ def test_get_deidentify_template_field_headers(): @pytest.mark.asyncio async def test_get_deidentify_template_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3626,7 +4032,7 @@ async def test_get_deidentify_template_field_headers_async(): def test_get_deidentify_template_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3652,7 +4058,7 @@ def test_get_deidentify_template_flattened(): def test_get_deidentify_template_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3667,7 +4073,7 @@ def test_get_deidentify_template_flattened_error(): @pytest.mark.asyncio async def test_get_deidentify_template_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3698,7 +4104,7 @@ async def test_get_deidentify_template_flattened_async(): @pytest.mark.asyncio async def test_get_deidentify_template_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3719,7 +4125,7 @@ async def test_get_deidentify_template_flattened_error_async(): ) def test_list_deidentify_templates(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3751,7 +4157,7 @@ def test_list_deidentify_templates_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3770,7 +4176,7 @@ async def test_list_deidentify_templates_async( transport: str = "grpc_asyncio", request_type=dlp.ListDeidentifyTemplatesRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3807,7 +4213,7 @@ async def test_list_deidentify_templates_async_from_dict(): def test_list_deidentify_templates_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3839,7 +4245,7 @@ def test_list_deidentify_templates_field_headers(): @pytest.mark.asyncio async def test_list_deidentify_templates_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3872,7 +4278,7 @@ async def test_list_deidentify_templates_field_headers_async(): def test_list_deidentify_templates_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3898,7 +4304,7 @@ def test_list_deidentify_templates_flattened(): def test_list_deidentify_templates_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3913,7 +4319,7 @@ def test_list_deidentify_templates_flattened_error(): @pytest.mark.asyncio async def test_list_deidentify_templates_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3944,7 +4350,7 @@ async def test_list_deidentify_templates_flattened_async(): @pytest.mark.asyncio async def test_list_deidentify_templates_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3958,7 +4364,7 @@ async def test_list_deidentify_templates_flattened_error_async(): def test_list_deidentify_templates_pager(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4010,7 +4416,7 @@ def test_list_deidentify_templates_pager(transport_name: str = "grpc"): def test_list_deidentify_templates_pages(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4054,7 +4460,7 @@ def test_list_deidentify_templates_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_deidentify_templates_async_pager(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4106,7 +4512,7 @@ async def test_list_deidentify_templates_async_pager(): @pytest.mark.asyncio async def test_list_deidentify_templates_async_pages(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4163,7 +4569,7 @@ async def test_list_deidentify_templates_async_pages(): ) def test_delete_deidentify_template(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4192,7 +4598,7 @@ def test_delete_deidentify_template_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4211,7 +4617,7 @@ async def test_delete_deidentify_template_async( transport: str = "grpc_asyncio", request_type=dlp.DeleteDeidentifyTemplateRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4243,7 +4649,7 @@ async def test_delete_deidentify_template_async_from_dict(): def test_delete_deidentify_template_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4275,7 +4681,7 @@ def test_delete_deidentify_template_field_headers(): @pytest.mark.asyncio async def test_delete_deidentify_template_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4306,7 +4712,7 @@ async def test_delete_deidentify_template_field_headers_async(): def test_delete_deidentify_template_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4332,7 +4738,7 @@ def test_delete_deidentify_template_flattened(): def test_delete_deidentify_template_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4347,7 +4753,7 @@ def test_delete_deidentify_template_flattened_error(): @pytest.mark.asyncio async def test_delete_deidentify_template_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4376,7 +4782,7 @@ async def test_delete_deidentify_template_flattened_async(): @pytest.mark.asyncio async def test_delete_deidentify_template_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4397,7 +4803,7 @@ async def test_delete_deidentify_template_flattened_error_async(): ) def test_create_job_trigger(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4435,7 +4841,7 @@ def test_create_job_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4454,7 +4860,7 @@ async def test_create_job_trigger_async( transport: str = "grpc_asyncio", request_type=dlp.CreateJobTriggerRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4497,7 +4903,7 @@ async def test_create_job_trigger_async_from_dict(): def test_create_job_trigger_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4529,7 +4935,7 @@ def test_create_job_trigger_field_headers(): @pytest.mark.asyncio async def test_create_job_trigger_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4560,7 +4966,7 @@ async def test_create_job_trigger_field_headers_async(): def test_create_job_trigger_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4590,7 +4996,7 @@ def test_create_job_trigger_flattened(): def test_create_job_trigger_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4606,7 +5012,7 @@ def test_create_job_trigger_flattened_error(): @pytest.mark.asyncio async def test_create_job_trigger_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4639,7 +5045,7 @@ async def test_create_job_trigger_flattened_async(): @pytest.mark.asyncio async def test_create_job_trigger_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4661,7 +5067,7 @@ async def test_create_job_trigger_flattened_error_async(): ) def test_update_job_trigger(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4699,7 +5105,7 @@ def test_update_job_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4718,7 +5124,7 @@ async def test_update_job_trigger_async( transport: str = "grpc_asyncio", request_type=dlp.UpdateJobTriggerRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4761,7 +5167,7 @@ async def test_update_job_trigger_async_from_dict(): def test_update_job_trigger_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4793,7 +5199,7 @@ def test_update_job_trigger_field_headers(): @pytest.mark.asyncio async def test_update_job_trigger_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4824,7 +5230,7 @@ async def test_update_job_trigger_field_headers_async(): def test_update_job_trigger_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4858,7 +5264,7 @@ def test_update_job_trigger_flattened(): def test_update_job_trigger_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4875,7 +5281,7 @@ def test_update_job_trigger_flattened_error(): @pytest.mark.asyncio async def test_update_job_trigger_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4912,7 +5318,7 @@ async def test_update_job_trigger_flattened_async(): @pytest.mark.asyncio async def test_update_job_trigger_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4935,7 +5341,7 @@ async def test_update_job_trigger_flattened_error_async(): ) def test_hybrid_inspect_job_trigger(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4964,7 +5370,7 @@ def test_hybrid_inspect_job_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4983,7 +5389,7 @@ async def test_hybrid_inspect_job_trigger_async( transport: str = "grpc_asyncio", request_type=dlp.HybridInspectJobTriggerRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5017,7 +5423,7 @@ async def test_hybrid_inspect_job_trigger_async_from_dict(): def test_hybrid_inspect_job_trigger_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5049,7 +5455,7 @@ def test_hybrid_inspect_job_trigger_field_headers(): @pytest.mark.asyncio async def test_hybrid_inspect_job_trigger_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5082,7 +5488,7 @@ async def test_hybrid_inspect_job_trigger_field_headers_async(): def test_hybrid_inspect_job_trigger_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5108,7 +5514,7 @@ def test_hybrid_inspect_job_trigger_flattened(): def test_hybrid_inspect_job_trigger_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5123,7 +5529,7 @@ def test_hybrid_inspect_job_trigger_flattened_error(): @pytest.mark.asyncio async def test_hybrid_inspect_job_trigger_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5154,7 +5560,7 @@ async def test_hybrid_inspect_job_trigger_flattened_async(): @pytest.mark.asyncio async def test_hybrid_inspect_job_trigger_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5175,7 +5581,7 @@ async def test_hybrid_inspect_job_trigger_flattened_error_async(): ) def test_get_job_trigger(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5211,7 +5617,7 @@ def test_get_job_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5228,7 +5634,7 @@ async def test_get_job_trigger_async( transport: str = "grpc_asyncio", request_type=dlp.GetJobTriggerRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5269,7 +5675,7 @@ async def test_get_job_trigger_async_from_dict(): def test_get_job_trigger_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5299,7 +5705,7 @@ def test_get_job_trigger_field_headers(): @pytest.mark.asyncio async def test_get_job_trigger_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5328,7 +5734,7 @@ async def test_get_job_trigger_field_headers_async(): def test_get_job_trigger_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5352,7 +5758,7 @@ def test_get_job_trigger_flattened(): def test_get_job_trigger_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5367,7 +5773,7 @@ def test_get_job_trigger_flattened_error(): @pytest.mark.asyncio async def test_get_job_trigger_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5394,7 +5800,7 @@ async def test_get_job_trigger_flattened_async(): @pytest.mark.asyncio async def test_get_job_trigger_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5415,7 +5821,7 @@ async def test_get_job_trigger_flattened_error_async(): ) def test_list_job_triggers(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5447,7 +5853,7 @@ def test_list_job_triggers_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5466,7 +5872,7 @@ async def test_list_job_triggers_async( transport: str = "grpc_asyncio", request_type=dlp.ListJobTriggersRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5503,7 +5909,7 @@ async def test_list_job_triggers_async_from_dict(): def test_list_job_triggers_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5535,7 +5941,7 @@ def test_list_job_triggers_field_headers(): @pytest.mark.asyncio async def test_list_job_triggers_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5568,7 +5974,7 @@ async def test_list_job_triggers_field_headers_async(): def test_list_job_triggers_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5594,7 +6000,7 @@ def test_list_job_triggers_flattened(): def test_list_job_triggers_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5609,7 +6015,7 @@ def test_list_job_triggers_flattened_error(): @pytest.mark.asyncio async def test_list_job_triggers_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5640,7 +6046,7 @@ async def test_list_job_triggers_flattened_async(): @pytest.mark.asyncio async def test_list_job_triggers_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5654,7 +6060,7 @@ async def test_list_job_triggers_flattened_error_async(): def test_list_job_triggers_pager(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -5706,7 +6112,7 @@ def test_list_job_triggers_pager(transport_name: str = "grpc"): def test_list_job_triggers_pages(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -5750,7 +6156,7 @@ def test_list_job_triggers_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_job_triggers_async_pager(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5802,7 +6208,7 @@ async def test_list_job_triggers_async_pager(): @pytest.mark.asyncio async def test_list_job_triggers_async_pages(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5859,7 +6265,7 @@ async def test_list_job_triggers_async_pages(): ) def test_delete_job_trigger(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5888,7 +6294,7 @@ def test_delete_job_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5907,7 +6313,7 @@ async def test_delete_job_trigger_async( transport: str = "grpc_asyncio", request_type=dlp.DeleteJobTriggerRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5939,7 +6345,7 @@ async def test_delete_job_trigger_async_from_dict(): def test_delete_job_trigger_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5971,7 +6377,7 @@ def test_delete_job_trigger_field_headers(): @pytest.mark.asyncio async def test_delete_job_trigger_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6002,7 +6408,7 @@ async def test_delete_job_trigger_field_headers_async(): def test_delete_job_trigger_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6028,7 +6434,7 @@ def test_delete_job_trigger_flattened(): def test_delete_job_trigger_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6043,7 +6449,7 @@ def test_delete_job_trigger_flattened_error(): @pytest.mark.asyncio async def test_delete_job_trigger_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6072,7 +6478,7 @@ async def test_delete_job_trigger_flattened_async(): @pytest.mark.asyncio async def test_delete_job_trigger_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6093,7 +6499,7 @@ async def test_delete_job_trigger_flattened_error_async(): ) def test_activate_job_trigger(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6131,7 +6537,7 @@ def test_activate_job_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6150,7 +6556,7 @@ async def test_activate_job_trigger_async( transport: str = "grpc_asyncio", request_type=dlp.ActivateJobTriggerRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6193,7 +6599,7 @@ async def test_activate_job_trigger_async_from_dict(): def test_activate_job_trigger_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6225,7 +6631,7 @@ def test_activate_job_trigger_field_headers(): @pytest.mark.asyncio async def test_activate_job_trigger_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6263,7 +6669,7 @@ async def test_activate_job_trigger_field_headers_async(): ) def test_create_discovery_config(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6301,7 +6707,7 @@ def test_create_discovery_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6320,7 +6726,7 @@ async def test_create_discovery_config_async( transport: str = "grpc_asyncio", request_type=dlp.CreateDiscoveryConfigRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6363,7 +6769,7 @@ async def test_create_discovery_config_async_from_dict(): def test_create_discovery_config_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6395,7 +6801,7 @@ def test_create_discovery_config_field_headers(): @pytest.mark.asyncio async def test_create_discovery_config_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6426,7 +6832,7 @@ async def test_create_discovery_config_field_headers_async(): def test_create_discovery_config_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6456,7 +6862,7 @@ def test_create_discovery_config_flattened(): def test_create_discovery_config_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6472,7 +6878,7 @@ def test_create_discovery_config_flattened_error(): @pytest.mark.asyncio async def test_create_discovery_config_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6505,7 +6911,7 @@ async def test_create_discovery_config_flattened_async(): @pytest.mark.asyncio async def test_create_discovery_config_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6527,7 +6933,7 @@ async def test_create_discovery_config_flattened_error_async(): ) def test_update_discovery_config(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6565,7 +6971,7 @@ def test_update_discovery_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6584,7 +6990,7 @@ async def test_update_discovery_config_async( transport: str = "grpc_asyncio", request_type=dlp.UpdateDiscoveryConfigRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6627,7 +7033,7 @@ async def test_update_discovery_config_async_from_dict(): def test_update_discovery_config_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6659,7 +7065,7 @@ def test_update_discovery_config_field_headers(): @pytest.mark.asyncio async def test_update_discovery_config_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6690,7 +7096,7 @@ async def test_update_discovery_config_field_headers_async(): def test_update_discovery_config_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6724,7 +7130,7 @@ def test_update_discovery_config_flattened(): def test_update_discovery_config_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6741,7 +7147,7 @@ def test_update_discovery_config_flattened_error(): @pytest.mark.asyncio async def test_update_discovery_config_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6778,7 +7184,7 @@ async def test_update_discovery_config_flattened_async(): @pytest.mark.asyncio async def test_update_discovery_config_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6801,7 +7207,7 @@ async def test_update_discovery_config_flattened_error_async(): ) def test_get_discovery_config(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6839,7 +7245,7 @@ def test_get_discovery_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6858,7 +7264,7 @@ async def test_get_discovery_config_async( transport: str = "grpc_asyncio", request_type=dlp.GetDiscoveryConfigRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6901,7 +7307,7 @@ async def test_get_discovery_config_async_from_dict(): def test_get_discovery_config_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6933,7 +7339,7 @@ def test_get_discovery_config_field_headers(): @pytest.mark.asyncio async def test_get_discovery_config_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6964,7 +7370,7 @@ async def test_get_discovery_config_field_headers_async(): def test_get_discovery_config_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6990,7 +7396,7 @@ def test_get_discovery_config_flattened(): def test_get_discovery_config_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7005,7 +7411,7 @@ def test_get_discovery_config_flattened_error(): @pytest.mark.asyncio async def test_get_discovery_config_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7034,7 +7440,7 @@ async def test_get_discovery_config_flattened_async(): @pytest.mark.asyncio async def test_get_discovery_config_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7055,7 +7461,7 @@ async def test_get_discovery_config_flattened_error_async(): ) def test_list_discovery_configs(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7087,7 +7493,7 @@ def test_list_discovery_configs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7106,7 +7512,7 @@ async def test_list_discovery_configs_async( transport: str = "grpc_asyncio", request_type=dlp.ListDiscoveryConfigsRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7143,7 +7549,7 @@ async def test_list_discovery_configs_async_from_dict(): def test_list_discovery_configs_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7175,7 +7581,7 @@ def test_list_discovery_configs_field_headers(): @pytest.mark.asyncio async def test_list_discovery_configs_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7208,7 +7614,7 @@ async def test_list_discovery_configs_field_headers_async(): def test_list_discovery_configs_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7234,7 +7640,7 @@ def test_list_discovery_configs_flattened(): def test_list_discovery_configs_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7249,7 +7655,7 @@ def test_list_discovery_configs_flattened_error(): @pytest.mark.asyncio async def test_list_discovery_configs_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7280,7 +7686,7 @@ async def test_list_discovery_configs_flattened_async(): @pytest.mark.asyncio async def test_list_discovery_configs_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7294,7 +7700,7 @@ async def test_list_discovery_configs_flattened_error_async(): def test_list_discovery_configs_pager(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -7346,7 +7752,7 @@ def test_list_discovery_configs_pager(transport_name: str = "grpc"): def test_list_discovery_configs_pages(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -7390,7 +7796,7 @@ def test_list_discovery_configs_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_discovery_configs_async_pager(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7442,7 +7848,7 @@ async def test_list_discovery_configs_async_pager(): @pytest.mark.asyncio async def test_list_discovery_configs_async_pages(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7499,7 +7905,7 @@ async def test_list_discovery_configs_async_pages(): ) def test_delete_discovery_config(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7528,7 +7934,7 @@ def test_delete_discovery_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7547,7 +7953,7 @@ async def test_delete_discovery_config_async( transport: str = "grpc_asyncio", request_type=dlp.DeleteDiscoveryConfigRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7579,7 +7985,7 @@ async def test_delete_discovery_config_async_from_dict(): def test_delete_discovery_config_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7611,7 +8017,7 @@ def test_delete_discovery_config_field_headers(): @pytest.mark.asyncio async def test_delete_discovery_config_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7642,7 +8048,7 @@ async def test_delete_discovery_config_field_headers_async(): def test_delete_discovery_config_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7668,7 +8074,7 @@ def test_delete_discovery_config_flattened(): def test_delete_discovery_config_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7683,7 +8089,7 @@ def test_delete_discovery_config_flattened_error(): @pytest.mark.asyncio async def test_delete_discovery_config_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7712,7 +8118,7 @@ async def test_delete_discovery_config_flattened_async(): @pytest.mark.asyncio async def test_delete_discovery_config_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7733,7 +8139,7 @@ async def test_delete_discovery_config_flattened_error_async(): ) def test_create_dlp_job(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7769,7 +8175,7 @@ def test_create_dlp_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7786,7 +8192,7 @@ async def test_create_dlp_job_async( transport: str = "grpc_asyncio", request_type=dlp.CreateDlpJobRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7827,7 +8233,7 @@ async def test_create_dlp_job_async_from_dict(): def test_create_dlp_job_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7857,7 +8263,7 @@ def test_create_dlp_job_field_headers(): @pytest.mark.asyncio async def test_create_dlp_job_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7886,7 +8292,7 @@ async def test_create_dlp_job_field_headers_async(): def test_create_dlp_job_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7931,7 +8337,7 @@ def test_create_dlp_job_flattened(): def test_create_dlp_job_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7960,7 +8366,7 @@ def test_create_dlp_job_flattened_error(): @pytest.mark.asyncio async def test_create_dlp_job_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8008,7 +8414,7 @@ async def test_create_dlp_job_flattened_async(): @pytest.mark.asyncio async def test_create_dlp_job_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8043,7 +8449,7 @@ async def test_create_dlp_job_flattened_error_async(): ) def test_list_dlp_jobs(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8073,7 +8479,7 @@ def test_list_dlp_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -8090,7 +8496,7 @@ async def test_list_dlp_jobs_async( transport: str = "grpc_asyncio", request_type=dlp.ListDlpJobsRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8125,7 +8531,7 @@ async def test_list_dlp_jobs_async_from_dict(): def test_list_dlp_jobs_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8155,7 +8561,7 @@ def test_list_dlp_jobs_field_headers(): @pytest.mark.asyncio async def test_list_dlp_jobs_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8186,7 +8592,7 @@ async def test_list_dlp_jobs_field_headers_async(): def test_list_dlp_jobs_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8210,7 +8616,7 @@ def test_list_dlp_jobs_flattened(): def test_list_dlp_jobs_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8225,7 +8631,7 @@ def test_list_dlp_jobs_flattened_error(): @pytest.mark.asyncio async def test_list_dlp_jobs_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8254,7 +8660,7 @@ async def test_list_dlp_jobs_flattened_async(): @pytest.mark.asyncio async def test_list_dlp_jobs_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8268,7 +8674,7 @@ async def test_list_dlp_jobs_flattened_error_async(): def test_list_dlp_jobs_pager(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -8318,7 +8724,7 @@ def test_list_dlp_jobs_pager(transport_name: str = "grpc"): def test_list_dlp_jobs_pages(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -8360,7 +8766,7 @@ def test_list_dlp_jobs_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_dlp_jobs_async_pager(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8410,7 +8816,7 @@ async def test_list_dlp_jobs_async_pager(): @pytest.mark.asyncio async def test_list_dlp_jobs_async_pages(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8465,7 +8871,7 @@ async def test_list_dlp_jobs_async_pages(): ) def test_get_dlp_job(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8501,7 +8907,7 @@ def test_get_dlp_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -8518,7 +8924,7 @@ async def test_get_dlp_job_async( transport: str = "grpc_asyncio", request_type=dlp.GetDlpJobRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8559,7 +8965,7 @@ async def test_get_dlp_job_async_from_dict(): def test_get_dlp_job_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8589,7 +8995,7 @@ def test_get_dlp_job_field_headers(): @pytest.mark.asyncio async def test_get_dlp_job_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8618,7 +9024,7 @@ async def test_get_dlp_job_field_headers_async(): def test_get_dlp_job_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8642,7 +9048,7 @@ def test_get_dlp_job_flattened(): def test_get_dlp_job_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8657,7 +9063,7 @@ def test_get_dlp_job_flattened_error(): @pytest.mark.asyncio async def test_get_dlp_job_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8684,7 +9090,7 @@ async def test_get_dlp_job_flattened_async(): @pytest.mark.asyncio async def test_get_dlp_job_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8705,7 +9111,7 @@ async def test_get_dlp_job_flattened_error_async(): ) def test_delete_dlp_job(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8732,7 +9138,7 @@ def test_delete_dlp_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -8749,7 +9155,7 @@ async def test_delete_dlp_job_async( transport: str = "grpc_asyncio", request_type=dlp.DeleteDlpJobRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8779,7 +9185,7 @@ async def test_delete_dlp_job_async_from_dict(): def test_delete_dlp_job_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8809,7 +9215,7 @@ def test_delete_dlp_job_field_headers(): @pytest.mark.asyncio async def test_delete_dlp_job_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8838,7 +9244,7 @@ async def test_delete_dlp_job_field_headers_async(): def test_delete_dlp_job_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8862,7 +9268,7 @@ def test_delete_dlp_job_flattened(): def test_delete_dlp_job_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8877,7 +9283,7 @@ def test_delete_dlp_job_flattened_error(): @pytest.mark.asyncio async def test_delete_dlp_job_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8904,7 +9310,7 @@ async def test_delete_dlp_job_flattened_async(): @pytest.mark.asyncio async def test_delete_dlp_job_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8925,7 +9331,7 @@ async def test_delete_dlp_job_flattened_error_async(): ) def test_cancel_dlp_job(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8952,7 +9358,7 @@ def test_cancel_dlp_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -8969,7 +9375,7 @@ async def test_cancel_dlp_job_async( transport: str = "grpc_asyncio", request_type=dlp.CancelDlpJobRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8999,7 +9405,7 @@ async def test_cancel_dlp_job_async_from_dict(): def test_cancel_dlp_job_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9029,7 +9435,7 @@ def test_cancel_dlp_job_field_headers(): @pytest.mark.asyncio async def test_cancel_dlp_job_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9065,7 +9471,7 @@ async def test_cancel_dlp_job_field_headers_async(): ) def test_create_stored_info_type(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9097,7 +9503,7 @@ def test_create_stored_info_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9116,7 +9522,7 @@ async def test_create_stored_info_type_async( transport: str = "grpc_asyncio", request_type=dlp.CreateStoredInfoTypeRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9153,7 +9559,7 @@ async def test_create_stored_info_type_async_from_dict(): def test_create_stored_info_type_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9185,7 +9591,7 @@ def test_create_stored_info_type_field_headers(): @pytest.mark.asyncio async def test_create_stored_info_type_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9216,7 +9622,7 @@ async def test_create_stored_info_type_field_headers_async(): def test_create_stored_info_type_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -9246,7 +9652,7 @@ def test_create_stored_info_type_flattened(): def test_create_stored_info_type_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -9262,7 +9668,7 @@ def test_create_stored_info_type_flattened_error(): @pytest.mark.asyncio async def test_create_stored_info_type_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -9295,7 +9701,7 @@ async def test_create_stored_info_type_flattened_async(): @pytest.mark.asyncio async def test_create_stored_info_type_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -9317,7 +9723,7 @@ async def test_create_stored_info_type_flattened_error_async(): ) def test_update_stored_info_type(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9349,7 +9755,7 @@ def test_update_stored_info_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9368,7 +9774,7 @@ async def test_update_stored_info_type_async( transport: str = "grpc_asyncio", request_type=dlp.UpdateStoredInfoTypeRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9405,7 +9811,7 @@ async def test_update_stored_info_type_async_from_dict(): def test_update_stored_info_type_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9437,7 +9843,7 @@ def test_update_stored_info_type_field_headers(): @pytest.mark.asyncio async def test_update_stored_info_type_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9468,7 +9874,7 @@ async def test_update_stored_info_type_field_headers_async(): def test_update_stored_info_type_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -9502,7 +9908,7 @@ def test_update_stored_info_type_flattened(): def test_update_stored_info_type_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -9519,7 +9925,7 @@ def test_update_stored_info_type_flattened_error(): @pytest.mark.asyncio async def test_update_stored_info_type_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -9556,7 +9962,7 @@ async def test_update_stored_info_type_flattened_async(): @pytest.mark.asyncio async def test_update_stored_info_type_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -9579,7 +9985,7 @@ async def test_update_stored_info_type_flattened_error_async(): ) def test_get_stored_info_type(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9611,7 +10017,7 @@ def test_get_stored_info_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9630,7 +10036,7 @@ async def test_get_stored_info_type_async( transport: str = "grpc_asyncio", request_type=dlp.GetStoredInfoTypeRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9667,7 +10073,7 @@ async def test_get_stored_info_type_async_from_dict(): def test_get_stored_info_type_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9699,7 +10105,7 @@ def test_get_stored_info_type_field_headers(): @pytest.mark.asyncio async def test_get_stored_info_type_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9730,7 +10136,7 @@ async def test_get_stored_info_type_field_headers_async(): def test_get_stored_info_type_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -9756,7 +10162,7 @@ def test_get_stored_info_type_flattened(): def test_get_stored_info_type_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -9771,7 +10177,7 @@ def test_get_stored_info_type_flattened_error(): @pytest.mark.asyncio async def test_get_stored_info_type_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -9800,7 +10206,7 @@ async def test_get_stored_info_type_flattened_async(): @pytest.mark.asyncio async def test_get_stored_info_type_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -9821,7 +10227,7 @@ async def test_get_stored_info_type_flattened_error_async(): ) def test_list_stored_info_types(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9853,7 +10259,7 @@ def test_list_stored_info_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9872,7 +10278,7 @@ async def test_list_stored_info_types_async( transport: str = "grpc_asyncio", request_type=dlp.ListStoredInfoTypesRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9909,7 +10315,7 @@ async def test_list_stored_info_types_async_from_dict(): def test_list_stored_info_types_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9941,7 +10347,7 @@ def test_list_stored_info_types_field_headers(): @pytest.mark.asyncio async def test_list_stored_info_types_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9974,7 +10380,7 @@ async def test_list_stored_info_types_field_headers_async(): def test_list_stored_info_types_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10000,7 +10406,7 @@ def test_list_stored_info_types_flattened(): def test_list_stored_info_types_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -10015,7 +10421,7 @@ def test_list_stored_info_types_flattened_error(): @pytest.mark.asyncio async def test_list_stored_info_types_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10046,7 +10452,7 @@ async def test_list_stored_info_types_flattened_async(): @pytest.mark.asyncio async def test_list_stored_info_types_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -10060,7 +10466,7 @@ async def test_list_stored_info_types_flattened_error_async(): def test_list_stored_info_types_pager(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -10112,7 +10518,7 @@ def test_list_stored_info_types_pager(transport_name: str = "grpc"): def test_list_stored_info_types_pages(transport_name: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -10156,7 +10562,7 @@ def test_list_stored_info_types_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_stored_info_types_async_pager(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10208,7 +10614,7 @@ async def test_list_stored_info_types_async_pager(): @pytest.mark.asyncio async def test_list_stored_info_types_async_pages(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10265,7 +10671,7 @@ async def test_list_stored_info_types_async_pages(): ) def test_delete_stored_info_type(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10294,7 +10700,7 @@ def test_delete_stored_info_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -10313,7 +10719,7 @@ async def test_delete_stored_info_type_async( transport: str = "grpc_asyncio", request_type=dlp.DeleteStoredInfoTypeRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10345,7 +10751,7 @@ async def test_delete_stored_info_type_async_from_dict(): def test_delete_stored_info_type_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10377,7 +10783,7 @@ def test_delete_stored_info_type_field_headers(): @pytest.mark.asyncio async def test_delete_stored_info_type_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10408,7 +10814,7 @@ async def test_delete_stored_info_type_field_headers_async(): def test_delete_stored_info_type_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10434,7 +10840,7 @@ def test_delete_stored_info_type_flattened(): def test_delete_stored_info_type_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -10449,7 +10855,7 @@ def test_delete_stored_info_type_flattened_error(): @pytest.mark.asyncio async def test_delete_stored_info_type_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10478,7 +10884,7 @@ async def test_delete_stored_info_type_flattened_async(): @pytest.mark.asyncio async def test_delete_stored_info_type_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -10499,7 +10905,7 @@ async def test_delete_stored_info_type_flattened_error_async(): ) def test_hybrid_inspect_dlp_job(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10528,7 +10934,7 @@ def test_hybrid_inspect_dlp_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -10547,7 +10953,7 @@ async def test_hybrid_inspect_dlp_job_async( transport: str = "grpc_asyncio", request_type=dlp.HybridInspectDlpJobRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10581,7 +10987,7 @@ async def test_hybrid_inspect_dlp_job_async_from_dict(): def test_hybrid_inspect_dlp_job_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10613,7 +11019,7 @@ def test_hybrid_inspect_dlp_job_field_headers(): @pytest.mark.asyncio async def test_hybrid_inspect_dlp_job_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10646,7 +11052,7 @@ async def test_hybrid_inspect_dlp_job_field_headers_async(): def test_hybrid_inspect_dlp_job_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10672,7 +11078,7 @@ def test_hybrid_inspect_dlp_job_flattened(): def test_hybrid_inspect_dlp_job_flattened_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -10687,7 +11093,7 @@ def test_hybrid_inspect_dlp_job_flattened_error(): @pytest.mark.asyncio async def test_hybrid_inspect_dlp_job_flattened_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10718,7 +11124,7 @@ async def test_hybrid_inspect_dlp_job_flattened_async(): @pytest.mark.asyncio async def test_hybrid_inspect_dlp_job_flattened_error_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -10739,7 +11145,7 @@ async def test_hybrid_inspect_dlp_job_flattened_error_async(): ) def test_finish_dlp_job(request_type, transport: str = "grpc"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10766,7 +11172,7 @@ def test_finish_dlp_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -10783,7 +11189,7 @@ async def test_finish_dlp_job_async( transport: str = "grpc_asyncio", request_type=dlp.FinishDlpJobRequest ): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10813,7 +11219,7 @@ async def test_finish_dlp_job_async_from_dict(): def test_finish_dlp_job_field_headers(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10843,7 +11249,7 @@ def test_finish_dlp_job_field_headers(): @pytest.mark.asyncio async def test_finish_dlp_job_field_headers_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10879,7 +11285,7 @@ async def test_finish_dlp_job_field_headers_async(): ) def test_inspect_content_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10910,7 +11316,7 @@ def test_inspect_content_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_inspect_content_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -10966,7 +11372,7 @@ def test_inspect_content_rest_bad_request( transport: str = "rest", request_type=dlp.InspectContentRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10988,7 +11394,7 @@ def test_inspect_content_rest_bad_request( def test_inspect_content_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11001,7 +11407,7 @@ def test_inspect_content_rest_error(): ) def test_redact_image_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11037,7 +11443,7 @@ def test_redact_image_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_redact_image_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -11093,7 +11499,7 @@ def test_redact_image_rest_bad_request( transport: str = "rest", request_type=dlp.RedactImageRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11115,7 +11521,7 @@ def test_redact_image_rest_bad_request( def test_redact_image_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11128,7 +11534,7 @@ def test_redact_image_rest_error(): ) def test_deidentify_content_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11159,7 +11565,7 @@ def test_deidentify_content_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_deidentify_content_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -11215,7 +11621,7 @@ def test_deidentify_content_rest_bad_request( transport: str = "rest", request_type=dlp.DeidentifyContentRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11237,7 +11643,7 @@ def test_deidentify_content_rest_bad_request( def test_deidentify_content_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11250,7 +11656,7 @@ def test_deidentify_content_rest_error(): ) def test_reidentify_content_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11298,7 +11704,7 @@ def test_reidentify_content_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reidentify_content._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11307,7 +11713,7 @@ def test_reidentify_content_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reidentify_content._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11316,7 +11722,7 @@ def test_reidentify_content_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11359,7 +11765,7 @@ def test_reidentify_content_rest_required_fields( def test_reidentify_content_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.reidentify_content._get_unset_required_fields({}) @@ -11369,7 +11775,7 @@ def test_reidentify_content_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_reidentify_content_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -11425,7 +11831,7 @@ def test_reidentify_content_rest_bad_request( transport: str = "rest", request_type=dlp.ReidentifyContentRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11447,7 +11853,7 @@ def test_reidentify_content_rest_bad_request( def test_reidentify_content_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11460,7 +11866,7 @@ def test_reidentify_content_rest_error(): ) def test_list_info_types_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11491,7 +11897,7 @@ def test_list_info_types_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_info_types_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -11547,7 +11953,7 @@ def test_list_info_types_rest_bad_request( transport: str = "rest", request_type=dlp.ListInfoTypesRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11569,7 +11975,7 @@ def test_list_info_types_rest_bad_request( def test_list_info_types_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11609,7 +12015,7 @@ def test_list_info_types_rest_flattened(): def test_list_info_types_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11624,7 +12030,7 @@ def test_list_info_types_rest_flattened_error(transport: str = "rest"): def test_list_info_types_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11637,7 +12043,7 @@ def test_list_info_types_rest_error(): ) def test_create_inspect_template_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11692,7 +12098,7 @@ def test_create_inspect_template_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_inspect_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11701,7 +12107,7 @@ def test_create_inspect_template_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_inspect_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11710,7 +12116,7 @@ def test_create_inspect_template_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11753,7 +12159,7 @@ def test_create_inspect_template_rest_required_fields( def test_create_inspect_template_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_inspect_template._get_unset_required_fields({}) @@ -11771,7 +12177,7 @@ def test_create_inspect_template_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_inspect_template_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -11827,7 +12233,7 @@ def test_create_inspect_template_rest_bad_request( transport: str = "rest", request_type=dlp.CreateInspectTemplateRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11849,7 +12255,7 @@ def test_create_inspect_template_rest_bad_request( def test_create_inspect_template_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11891,7 +12297,7 @@ def test_create_inspect_template_rest_flattened(): def test_create_inspect_template_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11907,7 +12313,7 @@ def test_create_inspect_template_rest_flattened_error(transport: str = "rest"): def test_create_inspect_template_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11920,7 +12326,7 @@ def test_create_inspect_template_rest_error(): ) def test_update_inspect_template_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11975,7 +12381,7 @@ def test_update_inspect_template_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_inspect_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11984,7 +12390,7 @@ def test_update_inspect_template_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_inspect_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11993,7 +12399,7 @@ def test_update_inspect_template_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12036,7 +12442,7 @@ def test_update_inspect_template_rest_required_fields( def test_update_inspect_template_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_inspect_template._get_unset_required_fields({}) @@ -12046,7 +12452,7 @@ def test_update_inspect_template_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_inspect_template_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -12102,7 +12508,7 @@ def test_update_inspect_template_rest_bad_request( transport: str = "rest", request_type=dlp.UpdateInspectTemplateRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12124,7 +12530,7 @@ def test_update_inspect_template_rest_bad_request( def test_update_inspect_template_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12167,7 +12573,7 @@ def test_update_inspect_template_rest_flattened(): def test_update_inspect_template_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12184,7 +12590,7 @@ def test_update_inspect_template_rest_flattened_error(transport: str = "rest"): def test_update_inspect_template_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12197,7 +12603,7 @@ def test_update_inspect_template_rest_error(): ) def test_get_inspect_template_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12252,7 +12658,7 @@ def test_get_inspect_template_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_inspect_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12261,7 +12667,7 @@ def test_get_inspect_template_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_inspect_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12270,7 +12676,7 @@ def test_get_inspect_template_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12312,7 +12718,7 @@ def test_get_inspect_template_rest_required_fields( def test_get_inspect_template_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_inspect_template._get_unset_required_fields({}) @@ -12322,7 +12728,7 @@ def test_get_inspect_template_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_inspect_template_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -12376,7 +12782,7 @@ def test_get_inspect_template_rest_bad_request( transport: str = "rest", request_type=dlp.GetInspectTemplateRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12398,7 +12804,7 @@ def test_get_inspect_template_rest_bad_request( def test_get_inspect_template_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12439,7 +12845,7 @@ def test_get_inspect_template_rest_flattened(): def test_get_inspect_template_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12454,7 +12860,7 @@ def test_get_inspect_template_rest_flattened_error(transport: str = "rest"): def test_get_inspect_template_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12467,7 +12873,7 @@ def test_get_inspect_template_rest_error(): ) def test_list_inspect_templates_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12518,7 +12924,7 @@ def test_list_inspect_templates_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_inspect_templates._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12527,7 +12933,7 @@ def test_list_inspect_templates_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_inspect_templates._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -12545,7 +12951,7 @@ def test_list_inspect_templates_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12587,7 +12993,7 @@ def test_list_inspect_templates_rest_required_fields( def test_list_inspect_templates_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_inspect_templates._get_unset_required_fields({}) @@ -12607,7 +13013,7 @@ def test_list_inspect_templates_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_inspect_templates_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -12665,7 +13071,7 @@ def test_list_inspect_templates_rest_bad_request( transport: str = "rest", request_type=dlp.ListInspectTemplatesRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12687,7 +13093,7 @@ def test_list_inspect_templates_rest_bad_request( def test_list_inspect_templates_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12728,7 +13134,7 @@ def test_list_inspect_templates_rest_flattened(): def test_list_inspect_templates_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12743,7 +13149,7 @@ def test_list_inspect_templates_rest_flattened_error(transport: str = "rest"): def test_list_inspect_templates_rest_pager(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12811,7 +13217,7 @@ def test_list_inspect_templates_rest_pager(transport: str = "rest"): ) def test_delete_inspect_template_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12857,7 +13263,7 @@ def test_delete_inspect_template_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_inspect_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12866,7 +13272,7 @@ def test_delete_inspect_template_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_inspect_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12875,7 +13281,7 @@ def test_delete_inspect_template_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12914,7 +13320,7 @@ def test_delete_inspect_template_rest_required_fields( def test_delete_inspect_template_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_inspect_template._get_unset_required_fields({}) @@ -12924,7 +13330,7 @@ def test_delete_inspect_template_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_inspect_template_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -12974,7 +13380,7 @@ def test_delete_inspect_template_rest_bad_request( transport: str = "rest", request_type=dlp.DeleteInspectTemplateRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12996,7 +13402,7 @@ def test_delete_inspect_template_rest_bad_request( def test_delete_inspect_template_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13035,7 +13441,7 @@ def test_delete_inspect_template_rest_flattened(): def test_delete_inspect_template_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13050,7 +13456,7 @@ def test_delete_inspect_template_rest_flattened_error(transport: str = "rest"): def test_delete_inspect_template_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -13063,7 +13469,7 @@ def test_delete_inspect_template_rest_error(): ) def test_create_deidentify_template_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13118,7 +13524,7 @@ def test_create_deidentify_template_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_deidentify_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13127,7 +13533,7 @@ def test_create_deidentify_template_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_deidentify_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13136,7 +13542,7 @@ def test_create_deidentify_template_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13179,7 +13585,7 @@ def test_create_deidentify_template_rest_required_fields( def test_create_deidentify_template_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_deidentify_template._get_unset_required_fields({}) @@ -13197,7 +13603,7 @@ def test_create_deidentify_template_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_deidentify_template_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -13255,7 +13661,7 @@ def test_create_deidentify_template_rest_bad_request( transport: str = "rest", request_type=dlp.CreateDeidentifyTemplateRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13277,7 +13683,7 @@ def test_create_deidentify_template_rest_bad_request( def test_create_deidentify_template_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13320,7 +13726,7 @@ def test_create_deidentify_template_rest_flattened(): def test_create_deidentify_template_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13336,7 +13742,7 @@ def test_create_deidentify_template_rest_flattened_error(transport: str = "rest" def test_create_deidentify_template_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -13349,7 +13755,7 @@ def test_create_deidentify_template_rest_error(): ) def test_update_deidentify_template_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13404,7 +13810,7 @@ def test_update_deidentify_template_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_deidentify_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13413,7 +13819,7 @@ def test_update_deidentify_template_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_deidentify_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13422,7 +13828,7 @@ def test_update_deidentify_template_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13465,7 +13871,7 @@ def test_update_deidentify_template_rest_required_fields( def test_update_deidentify_template_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_deidentify_template._get_unset_required_fields({}) @@ -13475,7 +13881,7 @@ def test_update_deidentify_template_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_deidentify_template_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -13533,7 +13939,7 @@ def test_update_deidentify_template_rest_bad_request( transport: str = "rest", request_type=dlp.UpdateDeidentifyTemplateRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13555,7 +13961,7 @@ def test_update_deidentify_template_rest_bad_request( def test_update_deidentify_template_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13599,7 +14005,7 @@ def test_update_deidentify_template_rest_flattened(): def test_update_deidentify_template_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13616,7 +14022,7 @@ def test_update_deidentify_template_rest_flattened_error(transport: str = "rest" def test_update_deidentify_template_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -13629,7 +14035,7 @@ def test_update_deidentify_template_rest_error(): ) def test_get_deidentify_template_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13684,7 +14090,7 @@ def test_get_deidentify_template_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_deidentify_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13693,7 +14099,7 @@ def test_get_deidentify_template_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_deidentify_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13702,7 +14108,7 @@ def test_get_deidentify_template_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13744,7 +14150,7 @@ def test_get_deidentify_template_rest_required_fields( def test_get_deidentify_template_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_deidentify_template._get_unset_required_fields({}) @@ -13754,7 +14160,7 @@ def test_get_deidentify_template_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_deidentify_template_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -13812,7 +14218,7 @@ def test_get_deidentify_template_rest_bad_request( transport: str = "rest", request_type=dlp.GetDeidentifyTemplateRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13834,7 +14240,7 @@ def test_get_deidentify_template_rest_bad_request( def test_get_deidentify_template_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13876,7 +14282,7 @@ def test_get_deidentify_template_rest_flattened(): def test_get_deidentify_template_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13891,7 +14297,7 @@ def test_get_deidentify_template_rest_flattened_error(transport: str = "rest"): def test_get_deidentify_template_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -13904,7 +14310,7 @@ def test_get_deidentify_template_rest_error(): ) def test_list_deidentify_templates_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13955,7 +14361,7 @@ def test_list_deidentify_templates_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_deidentify_templates._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13964,7 +14370,7 @@ def test_list_deidentify_templates_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_deidentify_templates._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -13982,7 +14388,7 @@ def test_list_deidentify_templates_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14024,7 +14430,7 @@ def test_list_deidentify_templates_rest_required_fields( def test_list_deidentify_templates_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_deidentify_templates._get_unset_required_fields({}) @@ -14044,7 +14450,7 @@ def test_list_deidentify_templates_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_deidentify_templates_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -14102,7 +14508,7 @@ def test_list_deidentify_templates_rest_bad_request( transport: str = "rest", request_type=dlp.ListDeidentifyTemplatesRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14124,7 +14530,7 @@ def test_list_deidentify_templates_rest_bad_request( def test_list_deidentify_templates_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14166,7 +14572,7 @@ def test_list_deidentify_templates_rest_flattened(): def test_list_deidentify_templates_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14181,7 +14587,7 @@ def test_list_deidentify_templates_rest_flattened_error(transport: str = "rest") def test_list_deidentify_templates_rest_pager(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14251,7 +14657,7 @@ def test_list_deidentify_templates_rest_pager(transport: str = "rest"): ) def test_delete_deidentify_template_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14297,7 +14703,7 @@ def test_delete_deidentify_template_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_deidentify_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14306,7 +14712,7 @@ def test_delete_deidentify_template_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_deidentify_template._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14315,7 +14721,7 @@ def test_delete_deidentify_template_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14354,7 +14760,7 @@ def test_delete_deidentify_template_rest_required_fields( def test_delete_deidentify_template_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_deidentify_template._get_unset_required_fields({}) @@ -14364,7 +14770,7 @@ def test_delete_deidentify_template_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_deidentify_template_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -14414,7 +14820,7 @@ def test_delete_deidentify_template_rest_bad_request( transport: str = "rest", request_type=dlp.DeleteDeidentifyTemplateRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14436,7 +14842,7 @@ def test_delete_deidentify_template_rest_bad_request( def test_delete_deidentify_template_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14476,7 +14882,7 @@ def test_delete_deidentify_template_rest_flattened(): def test_delete_deidentify_template_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14491,7 +14897,7 @@ def test_delete_deidentify_template_rest_flattened_error(transport: str = "rest" def test_delete_deidentify_template_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -14504,7 +14910,7 @@ def test_delete_deidentify_template_rest_error(): ) def test_create_job_trigger_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14561,7 +14967,7 @@ def test_create_job_trigger_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14570,7 +14976,7 @@ def test_create_job_trigger_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14579,7 +14985,7 @@ def test_create_job_trigger_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14622,7 +15028,7 @@ def test_create_job_trigger_rest_required_fields( def test_create_job_trigger_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_job_trigger._get_unset_required_fields({}) @@ -14640,7 +15046,7 @@ def test_create_job_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_job_trigger_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -14694,7 +15100,7 @@ def test_create_job_trigger_rest_bad_request( transport: str = "rest", request_type=dlp.CreateJobTriggerRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14716,7 +15122,7 @@ def test_create_job_trigger_rest_bad_request( def test_create_job_trigger_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14757,7 +15163,7 @@ def test_create_job_trigger_rest_flattened(): def test_create_job_trigger_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14773,7 +15179,7 @@ def test_create_job_trigger_rest_flattened_error(transport: str = "rest"): def test_create_job_trigger_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -14786,7 +15192,7 @@ def test_create_job_trigger_rest_error(): ) def test_update_job_trigger_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14843,7 +15249,7 @@ def test_update_job_trigger_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14852,7 +15258,7 @@ def test_update_job_trigger_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14861,7 +15267,7 @@ def test_update_job_trigger_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14904,7 +15310,7 @@ def test_update_job_trigger_rest_required_fields( def test_update_job_trigger_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_job_trigger._get_unset_required_fields({}) @@ -14914,7 +15320,7 @@ def test_update_job_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_job_trigger_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -14968,7 +15374,7 @@ def test_update_job_trigger_rest_bad_request( transport: str = "rest", request_type=dlp.UpdateJobTriggerRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14990,7 +15396,7 @@ def test_update_job_trigger_rest_bad_request( def test_update_job_trigger_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15032,7 +15438,7 @@ def test_update_job_trigger_rest_flattened(): def test_update_job_trigger_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15049,7 +15455,7 @@ def test_update_job_trigger_rest_flattened_error(transport: str = "rest"): def test_update_job_trigger_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -15062,7 +15468,7 @@ def test_update_job_trigger_rest_error(): ) def test_hybrid_inspect_job_trigger_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15110,7 +15516,7 @@ def test_hybrid_inspect_job_trigger_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).hybrid_inspect_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15119,7 +15525,7 @@ def test_hybrid_inspect_job_trigger_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).hybrid_inspect_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15128,7 +15534,7 @@ def test_hybrid_inspect_job_trigger_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -15171,7 +15577,7 @@ def test_hybrid_inspect_job_trigger_rest_required_fields( def test_hybrid_inspect_job_trigger_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.hybrid_inspect_job_trigger._get_unset_required_fields({}) @@ -15181,7 +15587,7 @@ def test_hybrid_inspect_job_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_hybrid_inspect_job_trigger_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -15239,7 +15645,7 @@ def test_hybrid_inspect_job_trigger_rest_bad_request( transport: str = "rest", request_type=dlp.HybridInspectJobTriggerRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15261,7 +15667,7 @@ def test_hybrid_inspect_job_trigger_rest_bad_request( def test_hybrid_inspect_job_trigger_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15305,7 +15711,7 @@ def test_hybrid_inspect_job_trigger_rest_flattened(): def test_hybrid_inspect_job_trigger_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15320,7 +15726,7 @@ def test_hybrid_inspect_job_trigger_rest_flattened_error(transport: str = "rest" def test_hybrid_inspect_job_trigger_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -15333,7 +15739,7 @@ def test_hybrid_inspect_job_trigger_rest_error(): ) def test_get_job_trigger_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15388,7 +15794,7 @@ def test_get_job_trigger_rest_required_fields(request_type=dlp.GetJobTriggerRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15397,7 +15803,7 @@ def test_get_job_trigger_rest_required_fields(request_type=dlp.GetJobTriggerRequ jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15406,7 +15812,7 @@ def test_get_job_trigger_rest_required_fields(request_type=dlp.GetJobTriggerRequ assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -15448,7 +15854,7 @@ def test_get_job_trigger_rest_required_fields(request_type=dlp.GetJobTriggerRequ def test_get_job_trigger_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_job_trigger._get_unset_required_fields({}) @@ -15458,7 +15864,7 @@ def test_get_job_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_job_trigger_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -15512,7 +15918,7 @@ def test_get_job_trigger_rest_bad_request( transport: str = "rest", request_type=dlp.GetJobTriggerRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15534,7 +15940,7 @@ def test_get_job_trigger_rest_bad_request( def test_get_job_trigger_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15574,7 +15980,7 @@ def test_get_job_trigger_rest_flattened(): def test_get_job_trigger_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15589,7 +15995,7 @@ def test_get_job_trigger_rest_flattened_error(transport: str = "rest"): def test_get_job_trigger_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -15602,7 +16008,7 @@ def test_get_job_trigger_rest_error(): ) def test_list_job_triggers_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15653,7 +16059,7 @@ def test_list_job_triggers_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_job_triggers._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15662,7 +16068,7 @@ def test_list_job_triggers_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_job_triggers._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -15682,7 +16088,7 @@ def test_list_job_triggers_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -15724,7 +16130,7 @@ def test_list_job_triggers_rest_required_fields( def test_list_job_triggers_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_job_triggers._get_unset_required_fields({}) @@ -15746,7 +16152,7 @@ def test_list_job_triggers_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_job_triggers_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -15802,7 +16208,7 @@ def test_list_job_triggers_rest_bad_request( transport: str = "rest", request_type=dlp.ListJobTriggersRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15824,7 +16230,7 @@ def test_list_job_triggers_rest_bad_request( def test_list_job_triggers_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15864,7 +16270,7 @@ def test_list_job_triggers_rest_flattened(): def test_list_job_triggers_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15879,7 +16285,7 @@ def test_list_job_triggers_rest_flattened_error(transport: str = "rest"): def test_list_job_triggers_rest_pager(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15947,7 +16353,7 @@ def test_list_job_triggers_rest_pager(transport: str = "rest"): ) def test_delete_job_trigger_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15993,7 +16399,7 @@ def test_delete_job_trigger_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -16002,7 +16408,7 @@ def test_delete_job_trigger_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -16011,7 +16417,7 @@ def test_delete_job_trigger_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -16050,7 +16456,7 @@ def test_delete_job_trigger_rest_required_fields( def test_delete_job_trigger_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_job_trigger._get_unset_required_fields({}) @@ -16060,7 +16466,7 @@ def test_delete_job_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_job_trigger_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -16108,7 +16514,7 @@ def test_delete_job_trigger_rest_bad_request( transport: str = "rest", request_type=dlp.DeleteJobTriggerRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16130,7 +16536,7 @@ def test_delete_job_trigger_rest_bad_request( def test_delete_job_trigger_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16168,7 +16574,7 @@ def test_delete_job_trigger_rest_flattened(): def test_delete_job_trigger_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16183,7 +16589,7 @@ def test_delete_job_trigger_rest_flattened_error(transport: str = "rest"): def test_delete_job_trigger_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -16196,7 +16602,7 @@ def test_delete_job_trigger_rest_error(): ) def test_activate_job_trigger_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16253,7 +16659,7 @@ def test_activate_job_trigger_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).activate_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -16262,7 +16668,7 @@ def test_activate_job_trigger_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).activate_job_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -16271,7 +16677,7 @@ def test_activate_job_trigger_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -16314,7 +16720,7 @@ def test_activate_job_trigger_rest_required_fields( def test_activate_job_trigger_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.activate_job_trigger._get_unset_required_fields({}) @@ -16324,7 +16730,7 @@ def test_activate_job_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_activate_job_trigger_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -16378,7 +16784,7 @@ def test_activate_job_trigger_rest_bad_request( transport: str = "rest", request_type=dlp.ActivateJobTriggerRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16400,7 +16806,7 @@ def test_activate_job_trigger_rest_bad_request( def test_activate_job_trigger_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -16413,7 +16819,7 @@ def test_activate_job_trigger_rest_error(): ) def test_create_discovery_config_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16470,7 +16876,7 @@ def test_create_discovery_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_discovery_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -16479,7 +16885,7 @@ def test_create_discovery_config_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_discovery_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -16488,7 +16894,7 @@ def test_create_discovery_config_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -16531,7 +16937,7 @@ def test_create_discovery_config_rest_required_fields( def test_create_discovery_config_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_discovery_config._get_unset_required_fields({}) @@ -16549,7 +16955,7 @@ def test_create_discovery_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_discovery_config_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -16605,7 +17011,7 @@ def test_create_discovery_config_rest_bad_request( transport: str = "rest", request_type=dlp.CreateDiscoveryConfigRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16627,7 +17033,7 @@ def test_create_discovery_config_rest_bad_request( def test_create_discovery_config_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16670,7 +17076,7 @@ def test_create_discovery_config_rest_flattened(): def test_create_discovery_config_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16686,7 +17092,7 @@ def test_create_discovery_config_rest_flattened_error(transport: str = "rest"): def test_create_discovery_config_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -16699,7 +17105,7 @@ def test_create_discovery_config_rest_error(): ) def test_update_discovery_config_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16758,7 +17164,7 @@ def test_update_discovery_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_discovery_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -16767,7 +17173,7 @@ def test_update_discovery_config_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_discovery_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -16776,7 +17182,7 @@ def test_update_discovery_config_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -16819,7 +17225,7 @@ def test_update_discovery_config_rest_required_fields( def test_update_discovery_config_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_discovery_config._get_unset_required_fields({}) @@ -16837,7 +17243,7 @@ def test_update_discovery_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_discovery_config_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -16893,7 +17299,7 @@ def test_update_discovery_config_rest_bad_request( transport: str = "rest", request_type=dlp.UpdateDiscoveryConfigRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16917,7 +17323,7 @@ def test_update_discovery_config_rest_bad_request( def test_update_discovery_config_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16963,7 +17369,7 @@ def test_update_discovery_config_rest_flattened(): def test_update_discovery_config_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16980,7 +17386,7 @@ def test_update_discovery_config_rest_flattened_error(transport: str = "rest"): def test_update_discovery_config_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -16993,7 +17399,7 @@ def test_update_discovery_config_rest_error(): ) def test_get_discovery_config_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -17052,7 +17458,7 @@ def test_get_discovery_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_discovery_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -17061,7 +17467,7 @@ def test_get_discovery_config_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_discovery_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -17070,7 +17476,7 @@ def test_get_discovery_config_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -17112,7 +17518,7 @@ def test_get_discovery_config_rest_required_fields( def test_get_discovery_config_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_discovery_config._get_unset_required_fields({}) @@ -17122,7 +17528,7 @@ def test_get_discovery_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_discovery_config_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -17176,7 +17582,7 @@ def test_get_discovery_config_rest_bad_request( transport: str = "rest", request_type=dlp.GetDiscoveryConfigRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17200,7 +17606,7 @@ def test_get_discovery_config_rest_bad_request( def test_get_discovery_config_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -17244,7 +17650,7 @@ def test_get_discovery_config_rest_flattened(): def test_get_discovery_config_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17259,7 +17665,7 @@ def test_get_discovery_config_rest_flattened_error(transport: str = "rest"): def test_get_discovery_config_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -17272,7 +17678,7 @@ def test_get_discovery_config_rest_error(): ) def test_list_discovery_configs_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -17323,7 +17729,7 @@ def test_list_discovery_configs_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_discovery_configs._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -17332,7 +17738,7 @@ def test_list_discovery_configs_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_discovery_configs._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -17349,7 +17755,7 @@ def test_list_discovery_configs_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -17391,7 +17797,7 @@ def test_list_discovery_configs_rest_required_fields( def test_list_discovery_configs_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_discovery_configs._get_unset_required_fields({}) @@ -17410,7 +17816,7 @@ def test_list_discovery_configs_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_discovery_configs_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -17468,7 +17874,7 @@ def test_list_discovery_configs_rest_bad_request( transport: str = "rest", request_type=dlp.ListDiscoveryConfigsRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17490,7 +17896,7 @@ def test_list_discovery_configs_rest_bad_request( def test_list_discovery_configs_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -17532,7 +17938,7 @@ def test_list_discovery_configs_rest_flattened(): def test_list_discovery_configs_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17547,7 +17953,7 @@ def test_list_discovery_configs_rest_flattened_error(transport: str = "rest"): def test_list_discovery_configs_rest_pager(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17615,7 +18021,7 @@ def test_list_discovery_configs_rest_pager(transport: str = "rest"): ) def test_delete_discovery_config_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -17663,7 +18069,7 @@ def test_delete_discovery_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_discovery_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -17672,7 +18078,7 @@ def test_delete_discovery_config_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_discovery_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -17681,7 +18087,7 @@ def test_delete_discovery_config_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -17720,7 +18126,7 @@ def test_delete_discovery_config_rest_required_fields( def test_delete_discovery_config_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_discovery_config._get_unset_required_fields({}) @@ -17730,7 +18136,7 @@ def test_delete_discovery_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_discovery_config_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -17780,7 +18186,7 @@ def test_delete_discovery_config_rest_bad_request( transport: str = "rest", request_type=dlp.DeleteDiscoveryConfigRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17804,7 +18210,7 @@ def test_delete_discovery_config_rest_bad_request( def test_delete_discovery_config_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -17846,7 +18252,7 @@ def test_delete_discovery_config_rest_flattened(): def test_delete_discovery_config_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17861,7 +18267,7 @@ def test_delete_discovery_config_rest_flattened_error(transport: str = "rest"): def test_delete_discovery_config_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -17874,7 +18280,7 @@ def test_delete_discovery_config_rest_error(): ) def test_create_dlp_job_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -17929,7 +18335,7 @@ def test_create_dlp_job_rest_required_fields(request_type=dlp.CreateDlpJobReques # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -17938,7 +18344,7 @@ def test_create_dlp_job_rest_required_fields(request_type=dlp.CreateDlpJobReques jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -17947,7 +18353,7 @@ def test_create_dlp_job_rest_required_fields(request_type=dlp.CreateDlpJobReques assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -17990,7 +18396,7 @@ def test_create_dlp_job_rest_required_fields(request_type=dlp.CreateDlpJobReques def test_create_dlp_job_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_dlp_job._get_unset_required_fields({}) @@ -18000,7 +18406,7 @@ def test_create_dlp_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_dlp_job_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -18054,7 +18460,7 @@ def test_create_dlp_job_rest_bad_request( transport: str = "rest", request_type=dlp.CreateDlpJobRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18076,7 +18482,7 @@ def test_create_dlp_job_rest_bad_request( def test_create_dlp_job_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -18116,7 +18522,7 @@ def test_create_dlp_job_rest_flattened(): def test_create_dlp_job_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18145,7 +18551,7 @@ def test_create_dlp_job_rest_flattened_error(transport: str = "rest"): def test_create_dlp_job_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -18158,7 +18564,7 @@ def test_create_dlp_job_rest_error(): ) def test_list_dlp_jobs_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -18207,7 +18613,7 @@ def test_list_dlp_jobs_rest_required_fields(request_type=dlp.ListDlpJobsRequest) # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_dlp_jobs._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -18216,7 +18622,7 @@ def test_list_dlp_jobs_rest_required_fields(request_type=dlp.ListDlpJobsRequest) jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_dlp_jobs._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -18236,7 +18642,7 @@ def test_list_dlp_jobs_rest_required_fields(request_type=dlp.ListDlpJobsRequest) assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -18278,7 +18684,7 @@ def test_list_dlp_jobs_rest_required_fields(request_type=dlp.ListDlpJobsRequest) def test_list_dlp_jobs_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_dlp_jobs._get_unset_required_fields({}) @@ -18300,7 +18706,7 @@ def test_list_dlp_jobs_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_dlp_jobs_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -18356,7 +18762,7 @@ def test_list_dlp_jobs_rest_bad_request( transport: str = "rest", request_type=dlp.ListDlpJobsRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18378,7 +18784,7 @@ def test_list_dlp_jobs_rest_bad_request( def test_list_dlp_jobs_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -18418,7 +18824,7 @@ def test_list_dlp_jobs_rest_flattened(): def test_list_dlp_jobs_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18433,7 +18839,7 @@ def test_list_dlp_jobs_rest_flattened_error(transport: str = "rest"): def test_list_dlp_jobs_rest_pager(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18501,7 +18907,7 @@ def test_list_dlp_jobs_rest_pager(transport: str = "rest"): ) def test_get_dlp_job_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -18556,7 +18962,7 @@ def test_get_dlp_job_rest_required_fields(request_type=dlp.GetDlpJobRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -18565,7 +18971,7 @@ def test_get_dlp_job_rest_required_fields(request_type=dlp.GetDlpJobRequest): jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -18574,7 +18980,7 @@ def test_get_dlp_job_rest_required_fields(request_type=dlp.GetDlpJobRequest): assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -18616,7 +19022,7 @@ def test_get_dlp_job_rest_required_fields(request_type=dlp.GetDlpJobRequest): def test_get_dlp_job_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_dlp_job._get_unset_required_fields({}) @@ -18626,7 +19032,7 @@ def test_get_dlp_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_dlp_job_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -18680,7 +19086,7 @@ def test_get_dlp_job_rest_bad_request( transport: str = "rest", request_type=dlp.GetDlpJobRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18702,7 +19108,7 @@ def test_get_dlp_job_rest_bad_request( def test_get_dlp_job_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -18742,7 +19148,7 @@ def test_get_dlp_job_rest_flattened(): def test_get_dlp_job_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18757,7 +19163,7 @@ def test_get_dlp_job_rest_flattened_error(transport: str = "rest"): def test_get_dlp_job_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -18770,7 +19176,7 @@ def test_get_dlp_job_rest_error(): ) def test_delete_dlp_job_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -18814,7 +19220,7 @@ def test_delete_dlp_job_rest_required_fields(request_type=dlp.DeleteDlpJobReques # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -18823,7 +19229,7 @@ def test_delete_dlp_job_rest_required_fields(request_type=dlp.DeleteDlpJobReques jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -18832,7 +19238,7 @@ def test_delete_dlp_job_rest_required_fields(request_type=dlp.DeleteDlpJobReques assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -18871,7 +19277,7 @@ def test_delete_dlp_job_rest_required_fields(request_type=dlp.DeleteDlpJobReques def test_delete_dlp_job_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_dlp_job._get_unset_required_fields({}) @@ -18881,7 +19287,7 @@ def test_delete_dlp_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_dlp_job_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -18929,7 +19335,7 @@ def test_delete_dlp_job_rest_bad_request( transport: str = "rest", request_type=dlp.DeleteDlpJobRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18951,7 +19357,7 @@ def test_delete_dlp_job_rest_bad_request( def test_delete_dlp_job_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -18989,7 +19395,7 @@ def test_delete_dlp_job_rest_flattened(): def test_delete_dlp_job_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -19004,7 +19410,7 @@ def test_delete_dlp_job_rest_flattened_error(transport: str = "rest"): def test_delete_dlp_job_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -19017,7 +19423,7 @@ def test_delete_dlp_job_rest_error(): ) def test_cancel_dlp_job_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -19061,7 +19467,7 @@ def test_cancel_dlp_job_rest_required_fields(request_type=dlp.CancelDlpJobReques # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).cancel_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -19070,7 +19476,7 @@ def test_cancel_dlp_job_rest_required_fields(request_type=dlp.CancelDlpJobReques jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).cancel_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -19079,7 +19485,7 @@ def test_cancel_dlp_job_rest_required_fields(request_type=dlp.CancelDlpJobReques assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -19119,7 +19525,7 @@ def test_cancel_dlp_job_rest_required_fields(request_type=dlp.CancelDlpJobReques def test_cancel_dlp_job_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.cancel_dlp_job._get_unset_required_fields({}) @@ -19129,7 +19535,7 @@ def test_cancel_dlp_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_cancel_dlp_job_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -19177,7 +19583,7 @@ def test_cancel_dlp_job_rest_bad_request( transport: str = "rest", request_type=dlp.CancelDlpJobRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -19199,7 +19605,7 @@ def test_cancel_dlp_job_rest_bad_request( def test_cancel_dlp_job_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -19212,7 +19618,7 @@ def test_cancel_dlp_job_rest_error(): ) def test_create_stored_info_type_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -19263,7 +19669,7 @@ def test_create_stored_info_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_stored_info_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -19272,7 +19678,7 @@ def test_create_stored_info_type_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_stored_info_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -19281,7 +19687,7 @@ def test_create_stored_info_type_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -19324,7 +19730,7 @@ def test_create_stored_info_type_rest_required_fields( def test_create_stored_info_type_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_stored_info_type._get_unset_required_fields({}) @@ -19342,7 +19748,7 @@ def test_create_stored_info_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_stored_info_type_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -19398,7 +19804,7 @@ def test_create_stored_info_type_rest_bad_request( transport: str = "rest", request_type=dlp.CreateStoredInfoTypeRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -19420,7 +19826,7 @@ def test_create_stored_info_type_rest_bad_request( def test_create_stored_info_type_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -19462,7 +19868,7 @@ def test_create_stored_info_type_rest_flattened(): def test_create_stored_info_type_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -19478,7 +19884,7 @@ def test_create_stored_info_type_rest_flattened_error(transport: str = "rest"): def test_create_stored_info_type_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -19491,7 +19897,7 @@ def test_create_stored_info_type_rest_error(): ) def test_update_stored_info_type_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -19542,7 +19948,7 @@ def test_update_stored_info_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_stored_info_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -19551,7 +19957,7 @@ def test_update_stored_info_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_stored_info_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -19560,7 +19966,7 @@ def test_update_stored_info_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -19603,7 +20009,7 @@ def test_update_stored_info_type_rest_required_fields( def test_update_stored_info_type_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_stored_info_type._get_unset_required_fields({}) @@ -19613,7 +20019,7 @@ def test_update_stored_info_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_stored_info_type_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -19669,7 +20075,7 @@ def test_update_stored_info_type_rest_bad_request( transport: str = "rest", request_type=dlp.UpdateStoredInfoTypeRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -19691,7 +20097,7 @@ def test_update_stored_info_type_rest_bad_request( def test_update_stored_info_type_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -19734,7 +20140,7 @@ def test_update_stored_info_type_rest_flattened(): def test_update_stored_info_type_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -19751,7 +20157,7 @@ def test_update_stored_info_type_rest_flattened_error(transport: str = "rest"): def test_update_stored_info_type_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -19764,7 +20170,7 @@ def test_update_stored_info_type_rest_error(): ) def test_get_stored_info_type_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -19815,7 +20221,7 @@ def test_get_stored_info_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_stored_info_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -19824,7 +20230,7 @@ def test_get_stored_info_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_stored_info_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -19833,7 +20239,7 @@ def test_get_stored_info_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -19875,7 +20281,7 @@ def test_get_stored_info_type_rest_required_fields( def test_get_stored_info_type_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_stored_info_type._get_unset_required_fields({}) @@ -19885,7 +20291,7 @@ def test_get_stored_info_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_stored_info_type_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -19939,7 +20345,7 @@ def test_get_stored_info_type_rest_bad_request( transport: str = "rest", request_type=dlp.GetStoredInfoTypeRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -19961,7 +20367,7 @@ def test_get_stored_info_type_rest_bad_request( def test_get_stored_info_type_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -20002,7 +20408,7 @@ def test_get_stored_info_type_rest_flattened(): def test_get_stored_info_type_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -20017,7 +20423,7 @@ def test_get_stored_info_type_rest_flattened_error(transport: str = "rest"): def test_get_stored_info_type_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -20030,7 +20436,7 @@ def test_get_stored_info_type_rest_error(): ) def test_list_stored_info_types_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -20081,7 +20487,7 @@ def test_list_stored_info_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_stored_info_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -20090,7 +20496,7 @@ def test_list_stored_info_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_stored_info_types._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -20108,7 +20514,7 @@ def test_list_stored_info_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -20150,7 +20556,7 @@ def test_list_stored_info_types_rest_required_fields( def test_list_stored_info_types_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_stored_info_types._get_unset_required_fields({}) @@ -20170,7 +20576,7 @@ def test_list_stored_info_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_stored_info_types_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -20226,7 +20632,7 @@ def test_list_stored_info_types_rest_bad_request( transport: str = "rest", request_type=dlp.ListStoredInfoTypesRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -20248,7 +20654,7 @@ def test_list_stored_info_types_rest_bad_request( def test_list_stored_info_types_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -20289,7 +20695,7 @@ def test_list_stored_info_types_rest_flattened(): def test_list_stored_info_types_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -20304,7 +20710,7 @@ def test_list_stored_info_types_rest_flattened_error(transport: str = "rest"): def test_list_stored_info_types_rest_pager(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -20372,7 +20778,7 @@ def test_list_stored_info_types_rest_pager(transport: str = "rest"): ) def test_delete_stored_info_type_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -20418,7 +20824,7 @@ def test_delete_stored_info_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_stored_info_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -20427,7 +20833,7 @@ def test_delete_stored_info_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_stored_info_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -20436,7 +20842,7 @@ def test_delete_stored_info_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -20475,7 +20881,7 @@ def test_delete_stored_info_type_rest_required_fields( def test_delete_stored_info_type_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_stored_info_type._get_unset_required_fields({}) @@ -20485,7 +20891,7 @@ def test_delete_stored_info_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_stored_info_type_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -20535,7 +20941,7 @@ def test_delete_stored_info_type_rest_bad_request( transport: str = "rest", request_type=dlp.DeleteStoredInfoTypeRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -20557,7 +20963,7 @@ def test_delete_stored_info_type_rest_bad_request( def test_delete_stored_info_type_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -20596,7 +21002,7 @@ def test_delete_stored_info_type_rest_flattened(): def test_delete_stored_info_type_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -20611,7 +21017,7 @@ def test_delete_stored_info_type_rest_flattened_error(transport: str = "rest"): def test_delete_stored_info_type_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -20624,7 +21030,7 @@ def test_delete_stored_info_type_rest_error(): ) def test_hybrid_inspect_dlp_job_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -20672,7 +21078,7 @@ def test_hybrid_inspect_dlp_job_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).hybrid_inspect_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -20681,7 +21087,7 @@ def test_hybrid_inspect_dlp_job_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).hybrid_inspect_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -20690,7 +21096,7 @@ def test_hybrid_inspect_dlp_job_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -20733,7 +21139,7 @@ def test_hybrid_inspect_dlp_job_rest_required_fields( def test_hybrid_inspect_dlp_job_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.hybrid_inspect_dlp_job._get_unset_required_fields({}) @@ -20743,7 +21149,7 @@ def test_hybrid_inspect_dlp_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_hybrid_inspect_dlp_job_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -20799,7 +21205,7 @@ def test_hybrid_inspect_dlp_job_rest_bad_request( transport: str = "rest", request_type=dlp.HybridInspectDlpJobRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -20821,7 +21227,7 @@ def test_hybrid_inspect_dlp_job_rest_bad_request( def test_hybrid_inspect_dlp_job_rest_flattened(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -20863,7 +21269,7 @@ def test_hybrid_inspect_dlp_job_rest_flattened(): def test_hybrid_inspect_dlp_job_rest_flattened_error(transport: str = "rest"): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -20878,7 +21284,7 @@ def test_hybrid_inspect_dlp_job_rest_flattened_error(transport: str = "rest"): def test_hybrid_inspect_dlp_job_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -20891,7 +21297,7 @@ def test_hybrid_inspect_dlp_job_rest_error(): ) def test_finish_dlp_job_rest(request_type): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -20935,7 +21341,7 @@ def test_finish_dlp_job_rest_required_fields(request_type=dlp.FinishDlpJobReques # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).finish_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -20944,7 +21350,7 @@ def test_finish_dlp_job_rest_required_fields(request_type=dlp.FinishDlpJobReques jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).finish_dlp_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -20953,7 +21359,7 @@ def test_finish_dlp_job_rest_required_fields(request_type=dlp.FinishDlpJobReques assert jsonified_request["name"] == "name_value" client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -20993,7 +21399,7 @@ def test_finish_dlp_job_rest_required_fields(request_type=dlp.FinishDlpJobReques def test_finish_dlp_job_rest_unset_required_fields(): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.finish_dlp_job._get_unset_required_fields({}) @@ -21003,7 +21409,7 @@ def test_finish_dlp_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_finish_dlp_job_rest_interceptors(null_interceptor): transport = transports.DlpServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DlpServiceRestInterceptor(), @@ -21051,7 +21457,7 @@ def test_finish_dlp_job_rest_bad_request( transport: str = "rest", request_type=dlp.FinishDlpJobRequest ): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -21073,24 +21479,24 @@ def test_finish_dlp_job_rest_bad_request( def test_finish_dlp_job_rest_error(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DlpServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DlpServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DlpServiceClient( @@ -21100,7 +21506,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DlpServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -21111,16 +21517,17 @@ 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 = DlpServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DlpServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DlpServiceClient( @@ -21132,7 +21539,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DlpServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DlpServiceClient(transport=transport) assert client.transport is transport @@ -21141,13 +21548,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DlpServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DlpServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -21164,7 +21571,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -21178,7 +21585,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DlpServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -21186,7 +21593,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -21198,7 +21605,7 @@ def test_dlp_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DlpServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -21210,7 +21617,7 @@ def test_dlp_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DlpServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -21280,7 +21687,7 @@ def test_dlp_service_base_transport_with_credentials_file(): "google.cloud.dlp_v2.services.dlp_service.transports.DlpServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DlpServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -21299,7 +21706,7 @@ def test_dlp_service_base_transport_with_adc(): "google.cloud.dlp_v2.services.dlp_service.transports.DlpServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DlpServiceTransport() adc.assert_called_once() @@ -21307,7 +21714,7 @@ def test_dlp_service_base_transport_with_adc(): def test_dlp_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DlpServiceClient() adc.assert_called_once_with( scopes=None, @@ -21327,7 +21734,7 @@ def test_dlp_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -21374,7 +21781,7 @@ def test_dlp_service_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -21399,7 +21806,7 @@ def test_dlp_service_transport_create_channel(transport_class, grpc_helpers): [transports.DlpServiceGrpcTransport, transports.DlpServiceGrpcAsyncIOTransport], ) def test_dlp_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -21437,7 +21844,7 @@ def test_dlp_service_grpc_transport_client_cert_source_for_mtls(transport_class) def test_dlp_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -21457,7 +21864,7 @@ def test_dlp_service_http_transport_client_cert_source_for_mtls(): ) def test_dlp_service_host_no_port(transport_name): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions(api_endpoint="dlp.googleapis.com"), transport=transport_name, ) @@ -21478,7 +21885,7 @@ def test_dlp_service_host_no_port(transport_name): ) def test_dlp_service_host_with_port(transport_name): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="dlp.googleapis.com:8000" ), @@ -21498,8 +21905,8 @@ def test_dlp_service_host_with_port(transport_name): ], ) def test_dlp_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DlpServiceClient( credentials=creds1, transport=transport_name, @@ -21672,7 +22079,7 @@ def test_dlp_service_transport_channel_mtls_with_client_cert_source(transport_cl mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -22048,7 +22455,7 @@ def test_client_with_default_client_info(): transports.DlpServiceTransport, "_prep_wrapped_messages" ) as prep: client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -22058,7 +22465,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DlpServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -22067,7 +22474,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DlpServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -22086,7 +22493,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -22103,7 +22510,7 @@ def test_client_ctx(): ] for transport in transports: client = DlpServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -22134,7 +22541,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, diff --git a/packages/google-cloud-dms/google/cloud/clouddms/gapic_version.py b/packages/google-cloud-dms/google/cloud/clouddms/gapic_version.py index 97c03305daf2..360a0d13ebdd 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms/gapic_version.py +++ b/packages/google-cloud-dms/google/cloud/clouddms/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.8.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/gapic_version.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/gapic_version.py index 97c03305daf2..360a0d13ebdd 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/gapic_version.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.8.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/async_client.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/async_client.py index 17654bb0b12a..f26b919fc677 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/async_client.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.clouddms_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -71,8 +71,12 @@ class DataMigrationServiceAsyncClient: _client: DataMigrationServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DataMigrationServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DataMigrationServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DataMigrationServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DataMigrationServiceClient._DEFAULT_UNIVERSE connection_profile_path = staticmethod( DataMigrationServiceClient.connection_profile_path @@ -205,6 +209,25 @@ def transport(self) -> DataMigrationServiceTransport: """ 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(DataMigrationServiceClient).get_transport_class, type(DataMigrationServiceClient), @@ -218,7 +241,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the data migration service client. + """Instantiates the data migration service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -229,23 +252,38 @@ def __init__( transport (Union[str, ~.DataMigrationServiceTransport]): 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. @@ -352,6 +390,9 @@ async def sample_list_migration_jobs(): 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, @@ -463,6 +504,9 @@ async def sample_get_migration_job(): 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, @@ -605,6 +649,9 @@ async def sample_create_migration_job(): 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, @@ -744,6 +791,9 @@ async def sample_update_migration_job(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -868,6 +918,9 @@ async def sample_delete_migration_job(): 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, @@ -963,6 +1016,9 @@ async def sample_start_migration_job(): 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, @@ -1058,6 +1114,9 @@ async def sample_stop_migration_job(): 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, @@ -1154,6 +1213,9 @@ async def sample_resume_migration_job(): 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, @@ -1251,6 +1313,9 @@ async def sample_promote_migration_job(): 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, @@ -1348,6 +1413,9 @@ async def sample_verify_migration_job(): 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, @@ -1445,6 +1513,9 @@ async def sample_restart_migration_job(): 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, @@ -1540,6 +1611,9 @@ async def sample_generate_ssh_script(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1625,6 +1699,9 @@ async def sample_generate_tcp_proxy_script(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1732,6 +1809,9 @@ async def sample_list_connection_profiles(): 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, @@ -1841,6 +1921,9 @@ async def sample_get_connection_profile(): 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, @@ -1979,6 +2062,9 @@ async def sample_create_connection_profile(): 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, @@ -2117,6 +2203,9 @@ async def sample_update_connection_profile(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2244,6 +2333,9 @@ async def sample_delete_connection_profile(): 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, @@ -2388,6 +2480,9 @@ async def sample_create_private_connection(): 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, @@ -2499,6 +2594,9 @@ async def sample_get_private_connection(): 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, @@ -2607,6 +2705,9 @@ async def sample_list_private_connections(): 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, @@ -2733,6 +2834,9 @@ async def sample_delete_private_connection(): 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, @@ -2843,6 +2947,9 @@ async def sample_get_conversion_workspace(): 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, @@ -2951,6 +3058,9 @@ async def sample_list_conversion_workspaces(): 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, @@ -3105,6 +3215,9 @@ async def sample_create_conversion_workspace(): 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, @@ -3247,6 +3360,9 @@ async def sample_update_conversion_workspace(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -3373,6 +3489,9 @@ async def sample_delete_conversion_workspace(): 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, @@ -3517,6 +3636,9 @@ async def sample_create_mapping_rule(): 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, @@ -3610,6 +3732,9 @@ async def sample_delete_mapping_rule(): 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, @@ -3715,6 +3840,9 @@ async def sample_list_mapping_rules(): 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, @@ -3839,6 +3967,9 @@ async def sample_get_mapping_rule(): 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, @@ -3927,6 +4058,9 @@ async def sample_seed_conversion_workspace(): 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, @@ -4031,6 +4165,9 @@ async def sample_import_mapping_rules(): 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, @@ -4128,6 +4265,9 @@ async def sample_convert_conversion_workspace(): 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, @@ -4226,6 +4366,9 @@ async def sample_commit_conversion_workspace(): 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, @@ -4324,6 +4467,9 @@ async def sample_rollback_conversion_workspace(): 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, @@ -4421,6 +4567,9 @@ async def sample_apply_conversion_workspace(): 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, @@ -4522,6 +4671,9 @@ async def sample_describe_database_entities(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -4619,6 +4771,9 @@ async def sample_search_background_jobs(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -4706,6 +4861,9 @@ async def sample_describe_conversion_workspace_revisions(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -4815,6 +4973,9 @@ async def sample_fetch_static_ips(): 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, @@ -4878,6 +5039,9 @@ async def list_operations( 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, @@ -4932,6 +5096,9 @@ async def get_operation( 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, @@ -4990,6 +5157,9 @@ async def delete_operation( 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, @@ -5044,6 +5214,9 @@ async def cancel_operation( 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, @@ -5161,6 +5334,9 @@ async def set_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -5282,6 +5458,9 @@ async def get_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -5341,6 +5520,9 @@ async def test_iam_permissions( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -5395,6 +5577,9 @@ async def get_location( 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, @@ -5449,6 +5634,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/client.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/client.py index 908f6e8bb85f..7021c48d74b9 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/client.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.clouddms_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -139,11 +140,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 = "datamigration.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "datamigration.{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 @@ -403,7 +408,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 @@ -433,6 +438,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") @@ -466,6 +476,175 @@ 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 + + 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 + + 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 = DataMigrationServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DataMigrationServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DataMigrationServiceClient._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 = DataMigrationServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DataMigrationServiceClient._DEFAULT_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 DataMigrationServiceClient._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, *, @@ -485,22 +664,32 @@ def __init__( transport (Union[str, DataMigrationServiceTransport]): 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. @@ -511,17 +700,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = DataMigrationServiceClient._read_environment_variables() + self._client_cert_source = DataMigrationServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = DataMigrationServiceClient._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" @@ -530,20 +736,33 @@ 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, DataMigrationServiceTransport): + transport_provided = isinstance(transport, DataMigrationServiceTransport) + if transport_provided: # transport is a DataMigrationServiceTransport 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(DataMigrationServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or DataMigrationServiceClient._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( @@ -553,17 +772,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_migration_jobs( @@ -661,6 +880,9 @@ def sample_list_migration_jobs(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -772,6 +994,9 @@ def sample_get_migration_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -914,6 +1139,9 @@ def sample_create_migration_job(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1053,6 +1281,9 @@ def sample_update_migration_job(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1177,6 +1408,9 @@ def sample_delete_migration_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1273,6 +1507,9 @@ def sample_start_migration_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1369,6 +1606,9 @@ def sample_stop_migration_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1466,6 +1706,9 @@ def sample_resume_migration_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1564,6 +1807,9 @@ def sample_promote_migration_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1662,6 +1908,9 @@ def sample_verify_migration_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1760,6 +2009,9 @@ def sample_restart_migration_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1856,6 +2108,9 @@ def sample_generate_ssh_script(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1944,6 +2199,9 @@ def sample_generate_tcp_proxy_script(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2051,6 +2309,9 @@ def sample_list_connection_profiles(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2160,6 +2421,9 @@ def sample_get_connection_profile(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2300,6 +2564,9 @@ def sample_create_connection_profile(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2440,6 +2707,9 @@ def sample_update_connection_profile(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2569,6 +2839,9 @@ def sample_delete_connection_profile(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2715,6 +2988,9 @@ def sample_create_private_connection(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2826,6 +3102,9 @@ def sample_get_private_connection(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2934,6 +3213,9 @@ def sample_list_private_connections(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3062,6 +3344,9 @@ def sample_delete_private_connection(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3172,6 +3457,9 @@ def sample_get_conversion_workspace(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3282,6 +3570,9 @@ def sample_list_conversion_workspaces(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3438,6 +3729,9 @@ def sample_create_conversion_workspace(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3582,6 +3876,9 @@ def sample_update_conversion_workspace(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3710,6 +4007,9 @@ def sample_delete_conversion_workspace(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3854,6 +4154,9 @@ def sample_create_mapping_rule(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3947,6 +4250,9 @@ def sample_delete_mapping_rule(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -4052,6 +4358,9 @@ def sample_list_mapping_rules(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4176,6 +4485,9 @@ def sample_get_mapping_rule(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4267,6 +4579,9 @@ def sample_seed_conversion_workspace(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4372,6 +4687,9 @@ def sample_import_mapping_rules(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4472,6 +4790,9 @@ def sample_convert_conversion_workspace(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4573,6 +4894,9 @@ def sample_commit_conversion_workspace(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4674,6 +4998,9 @@ def sample_rollback_conversion_workspace(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4774,6 +5101,9 @@ def sample_apply_conversion_workspace(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4878,6 +5208,9 @@ def sample_describe_database_entities(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4976,6 +5309,9 @@ def sample_search_background_jobs(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -5068,6 +5404,9 @@ def sample_describe_conversion_workspace_revisions(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -5177,6 +5516,9 @@ def sample_fetch_static_ips(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -5253,6 +5595,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -5307,6 +5652,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -5365,6 +5713,9 @@ def delete_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -5419,6 +5770,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -5536,6 +5890,9 @@ def set_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -5657,6 +6014,9 @@ def get_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -5716,6 +6076,9 @@ def test_iam_permissions( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -5770,6 +6133,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -5824,6 +6190,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/base.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/base.py index 6881c63e3155..f4d93039a878 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/base.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/base.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'datamigration.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 @@ -128,6 +128,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-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc.py index d87f5d914280..7768756e3ce2 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc.py @@ -72,7 +72,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'datamigration.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-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc_asyncio.py b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc_asyncio.py index 0aa69eed070c..b9b1f7b35bb0 100644 --- a/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-dms/google/cloud/clouddms_v1/services/data_migration_service/transports/grpc_asyncio.py @@ -117,7 +117,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'datamigration.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-dms/noxfile.py b/packages/google-cloud-dms/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-dms/noxfile.py +++ b/packages/google-cloud-dms/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-dms/samples/generated_samples/snippet_metadata_google.cloud.clouddms.v1.json b/packages/google-cloud-dms/samples/generated_samples/snippet_metadata_google.cloud.clouddms.v1.json index 7cfb96b8e38a..92f5517525f3 100644 --- a/packages/google-cloud-dms/samples/generated_samples/snippet_metadata_google.cloud.clouddms.v1.json +++ b/packages/google-cloud-dms/samples/generated_samples/snippet_metadata_google.cloud.clouddms.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-dms", - "version": "1.8.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-dms/tests/unit/gapic/clouddms_v1/test_data_migration_service.py b/packages/google-cloud-dms/tests/unit/gapic/clouddms_v1/test_data_migration_service.py index 82d2f5368971..af7d1f645edc 100644 --- a/packages/google-cloud-dms/tests/unit/gapic/clouddms_v1/test_data_migration_service.py +++ b/packages/google-cloud-dms/tests/unit/gapic/clouddms_v1/test_data_migration_service.py @@ -33,7 +33,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -87,6 +87,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -117,6 +140,284 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert DataMigrationServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DataMigrationServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DataMigrationServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DataMigrationServiceClient._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 DataMigrationServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DataMigrationServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DataMigrationServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DataMigrationServiceClient._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 DataMigrationServiceClient._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 DataMigrationServiceClient._get_client_cert_source(None, False) is None + assert ( + DataMigrationServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + DataMigrationServiceClient._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 ( + DataMigrationServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DataMigrationServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DataMigrationServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataMigrationServiceClient), +) +@mock.patch.object( + DataMigrationServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataMigrationServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DataMigrationServiceClient._DEFAULT_UNIVERSE + default_endpoint = DataMigrationServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DataMigrationServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DataMigrationServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DataMigrationServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DataMigrationServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DataMigrationServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + DataMigrationServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == DataMigrationServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DataMigrationServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DataMigrationServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DataMigrationServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DataMigrationServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DataMigrationServiceClient._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 ( + DataMigrationServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DataMigrationServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DataMigrationServiceClient._get_universe_domain(None, None) + == DataMigrationServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DataMigrationServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + DataMigrationServiceClient, + transports.DataMigrationServiceGrpcTransport, + "grpc", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -127,7 +428,7 @@ def test__get_default_mtls_endpoint(): def test_data_migration_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -175,7 +476,7 @@ def test_data_migration_service_client_service_account_always_use_jwt( def test_data_migration_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -223,20 +524,22 @@ def test_data_migration_service_client_get_transport_class(): ) @mock.patch.object( DataMigrationServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DataMigrationServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataMigrationServiceClient), ) @mock.patch.object( DataMigrationServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DataMigrationServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataMigrationServiceAsyncClient), ) def test_data_migration_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(DataMigrationServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -271,7 +574,9 @@ def test_data_migration_service_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, @@ -301,15 +606,23 @@ def test_data_migration_service_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") @@ -319,7 +632,9 @@ def test_data_migration_service_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", @@ -337,7 +652,9 @@ def test_data_migration_service_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, @@ -378,13 +695,13 @@ def test_data_migration_service_client_client_options( ) @mock.patch.object( DataMigrationServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DataMigrationServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataMigrationServiceClient), ) @mock.patch.object( DataMigrationServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DataMigrationServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataMigrationServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_data_migration_service_client_mtls_env_auto( @@ -407,7 +724,9 @@ def test_data_migration_service_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 @@ -439,7 +758,9 @@ def test_data_migration_service_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 @@ -473,7 +794,9 @@ def test_data_migration_service_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, @@ -563,6 +886,118 @@ def test_data_migration_service_client_get_mtls_endpoint_and_cert_source(client_ 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", [DataMigrationServiceClient, DataMigrationServiceAsyncClient] +) +@mock.patch.object( + DataMigrationServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataMigrationServiceClient), +) +@mock.patch.object( + DataMigrationServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DataMigrationServiceAsyncClient), +) +def test_data_migration_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DataMigrationServiceClient._DEFAULT_UNIVERSE + default_endpoint = DataMigrationServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DataMigrationServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -592,7 +1027,9 @@ def test_data_migration_service_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, @@ -631,7 +1068,9 @@ def test_data_migration_service_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, @@ -691,7 +1130,9 @@ def test_data_migration_service_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, @@ -708,8 +1149,8 @@ def test_data_migration_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -738,7 +1179,7 @@ def test_data_migration_service_client_create_channel_credentials_file( ) def test_list_migration_jobs(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -772,7 +1213,7 @@ def test_list_migration_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -791,7 +1232,7 @@ async def test_list_migration_jobs_async( transport: str = "grpc_asyncio", request_type=clouddms.ListMigrationJobsRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -830,7 +1271,7 @@ async def test_list_migration_jobs_async_from_dict(): def test_list_migration_jobs_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -862,7 +1303,7 @@ def test_list_migration_jobs_field_headers(): @pytest.mark.asyncio async def test_list_migration_jobs_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -895,7 +1336,7 @@ async def test_list_migration_jobs_field_headers_async(): def test_list_migration_jobs_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -921,7 +1362,7 @@ def test_list_migration_jobs_flattened(): def test_list_migration_jobs_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -936,7 +1377,7 @@ def test_list_migration_jobs_flattened_error(): @pytest.mark.asyncio async def test_list_migration_jobs_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -967,7 +1408,7 @@ async def test_list_migration_jobs_flattened_async(): @pytest.mark.asyncio async def test_list_migration_jobs_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -981,7 +1422,7 @@ async def test_list_migration_jobs_flattened_error_async(): def test_list_migration_jobs_pager(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1033,7 +1474,7 @@ def test_list_migration_jobs_pager(transport_name: str = "grpc"): def test_list_migration_jobs_pages(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1077,7 +1518,7 @@ def test_list_migration_jobs_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_migration_jobs_async_pager(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1129,7 +1570,7 @@ async def test_list_migration_jobs_async_pager(): @pytest.mark.asyncio async def test_list_migration_jobs_async_pages(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1186,7 +1627,7 @@ async def test_list_migration_jobs_async_pages(): ) def test_get_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1236,7 +1677,7 @@ def test_get_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1255,7 +1696,7 @@ async def test_get_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.GetMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1310,7 +1751,7 @@ async def test_get_migration_job_async_from_dict(): def test_get_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1342,7 +1783,7 @@ def test_get_migration_job_field_headers(): @pytest.mark.asyncio async def test_get_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1375,7 +1816,7 @@ async def test_get_migration_job_field_headers_async(): def test_get_migration_job_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1401,7 +1842,7 @@ def test_get_migration_job_flattened(): def test_get_migration_job_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1416,7 +1857,7 @@ def test_get_migration_job_flattened_error(): @pytest.mark.asyncio async def test_get_migration_job_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1447,7 +1888,7 @@ async def test_get_migration_job_flattened_async(): @pytest.mark.asyncio async def test_get_migration_job_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1468,7 +1909,7 @@ async def test_get_migration_job_flattened_error_async(): ) def test_create_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1497,7 +1938,7 @@ def test_create_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1516,7 +1957,7 @@ async def test_create_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.CreateMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1550,7 +1991,7 @@ async def test_create_migration_job_async_from_dict(): def test_create_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1582,7 +2023,7 @@ def test_create_migration_job_field_headers(): @pytest.mark.asyncio async def test_create_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1615,7 +2056,7 @@ async def test_create_migration_job_field_headers_async(): def test_create_migration_job_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1649,7 +2090,7 @@ def test_create_migration_job_flattened(): def test_create_migration_job_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1666,7 +2107,7 @@ def test_create_migration_job_flattened_error(): @pytest.mark.asyncio async def test_create_migration_job_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1705,7 +2146,7 @@ async def test_create_migration_job_flattened_async(): @pytest.mark.asyncio async def test_create_migration_job_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1728,7 +2169,7 @@ async def test_create_migration_job_flattened_error_async(): ) def test_update_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1757,7 +2198,7 @@ def test_update_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1776,7 +2217,7 @@ async def test_update_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.UpdateMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1810,7 +2251,7 @@ async def test_update_migration_job_async_from_dict(): def test_update_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1842,7 +2283,7 @@ def test_update_migration_job_field_headers(): @pytest.mark.asyncio async def test_update_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1875,7 +2316,7 @@ async def test_update_migration_job_field_headers_async(): def test_update_migration_job_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1905,7 +2346,7 @@ def test_update_migration_job_flattened(): def test_update_migration_job_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1921,7 +2362,7 @@ def test_update_migration_job_flattened_error(): @pytest.mark.asyncio async def test_update_migration_job_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1956,7 +2397,7 @@ async def test_update_migration_job_flattened_async(): @pytest.mark.asyncio async def test_update_migration_job_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1978,7 +2419,7 @@ async def test_update_migration_job_flattened_error_async(): ) def test_delete_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2007,7 +2448,7 @@ def test_delete_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2026,7 +2467,7 @@ async def test_delete_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.DeleteMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2060,7 +2501,7 @@ async def test_delete_migration_job_async_from_dict(): def test_delete_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2092,7 +2533,7 @@ def test_delete_migration_job_field_headers(): @pytest.mark.asyncio async def test_delete_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2125,7 +2566,7 @@ async def test_delete_migration_job_field_headers_async(): def test_delete_migration_job_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2151,7 +2592,7 @@ def test_delete_migration_job_flattened(): def test_delete_migration_job_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2166,7 +2607,7 @@ def test_delete_migration_job_flattened_error(): @pytest.mark.asyncio async def test_delete_migration_job_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2197,7 +2638,7 @@ async def test_delete_migration_job_flattened_async(): @pytest.mark.asyncio async def test_delete_migration_job_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2218,7 +2659,7 @@ async def test_delete_migration_job_flattened_error_async(): ) def test_start_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2247,7 +2688,7 @@ def test_start_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2266,7 +2707,7 @@ async def test_start_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.StartMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2300,7 +2741,7 @@ async def test_start_migration_job_async_from_dict(): def test_start_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2332,7 +2773,7 @@ def test_start_migration_job_field_headers(): @pytest.mark.asyncio async def test_start_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2372,7 +2813,7 @@ async def test_start_migration_job_field_headers_async(): ) def test_stop_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2401,7 +2842,7 @@ def test_stop_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2420,7 +2861,7 @@ async def test_stop_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.StopMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2454,7 +2895,7 @@ async def test_stop_migration_job_async_from_dict(): def test_stop_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2486,7 +2927,7 @@ def test_stop_migration_job_field_headers(): @pytest.mark.asyncio async def test_stop_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2526,7 +2967,7 @@ async def test_stop_migration_job_field_headers_async(): ) def test_resume_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2555,7 +2996,7 @@ def test_resume_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2574,7 +3015,7 @@ async def test_resume_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.ResumeMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2608,7 +3049,7 @@ async def test_resume_migration_job_async_from_dict(): def test_resume_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2640,7 +3081,7 @@ def test_resume_migration_job_field_headers(): @pytest.mark.asyncio async def test_resume_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2680,7 +3121,7 @@ async def test_resume_migration_job_field_headers_async(): ) def test_promote_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2709,7 +3150,7 @@ def test_promote_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2728,7 +3169,7 @@ async def test_promote_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.PromoteMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2762,7 +3203,7 @@ async def test_promote_migration_job_async_from_dict(): def test_promote_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2794,7 +3235,7 @@ def test_promote_migration_job_field_headers(): @pytest.mark.asyncio async def test_promote_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2834,7 +3275,7 @@ async def test_promote_migration_job_field_headers_async(): ) def test_verify_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2863,7 +3304,7 @@ def test_verify_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2882,7 +3323,7 @@ async def test_verify_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.VerifyMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2916,7 +3357,7 @@ async def test_verify_migration_job_async_from_dict(): def test_verify_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2948,7 +3389,7 @@ def test_verify_migration_job_field_headers(): @pytest.mark.asyncio async def test_verify_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2988,7 +3429,7 @@ async def test_verify_migration_job_field_headers_async(): ) def test_restart_migration_job(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3017,7 +3458,7 @@ def test_restart_migration_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3036,7 +3477,7 @@ async def test_restart_migration_job_async( transport: str = "grpc_asyncio", request_type=clouddms.RestartMigrationJobRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3070,7 +3511,7 @@ async def test_restart_migration_job_async_from_dict(): def test_restart_migration_job_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3102,7 +3543,7 @@ def test_restart_migration_job_field_headers(): @pytest.mark.asyncio async def test_restart_migration_job_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3142,7 +3583,7 @@ async def test_restart_migration_job_field_headers_async(): ) def test_generate_ssh_script(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3174,7 +3615,7 @@ def test_generate_ssh_script_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3193,7 +3634,7 @@ async def test_generate_ssh_script_async( transport: str = "grpc_asyncio", request_type=clouddms.GenerateSshScriptRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3230,7 +3671,7 @@ async def test_generate_ssh_script_async_from_dict(): def test_generate_ssh_script_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3262,7 +3703,7 @@ def test_generate_ssh_script_field_headers(): @pytest.mark.asyncio async def test_generate_ssh_script_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3300,7 +3741,7 @@ async def test_generate_ssh_script_field_headers_async(): ) def test_generate_tcp_proxy_script(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3332,7 +3773,7 @@ def test_generate_tcp_proxy_script_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3351,7 +3792,7 @@ async def test_generate_tcp_proxy_script_async( transport: str = "grpc_asyncio", request_type=clouddms.GenerateTcpProxyScriptRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3388,7 +3829,7 @@ async def test_generate_tcp_proxy_script_async_from_dict(): def test_generate_tcp_proxy_script_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3420,7 +3861,7 @@ def test_generate_tcp_proxy_script_field_headers(): @pytest.mark.asyncio async def test_generate_tcp_proxy_script_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3460,7 +3901,7 @@ async def test_generate_tcp_proxy_script_field_headers_async(): ) def test_list_connection_profiles(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3494,7 +3935,7 @@ def test_list_connection_profiles_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3513,7 +3954,7 @@ async def test_list_connection_profiles_async( transport: str = "grpc_asyncio", request_type=clouddms.ListConnectionProfilesRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3552,7 +3993,7 @@ async def test_list_connection_profiles_async_from_dict(): def test_list_connection_profiles_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3584,7 +4025,7 @@ def test_list_connection_profiles_field_headers(): @pytest.mark.asyncio async def test_list_connection_profiles_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3617,7 +4058,7 @@ async def test_list_connection_profiles_field_headers_async(): def test_list_connection_profiles_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3643,7 +4084,7 @@ def test_list_connection_profiles_flattened(): def test_list_connection_profiles_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3658,7 +4099,7 @@ def test_list_connection_profiles_flattened_error(): @pytest.mark.asyncio async def test_list_connection_profiles_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3689,7 +4130,7 @@ async def test_list_connection_profiles_flattened_async(): @pytest.mark.asyncio async def test_list_connection_profiles_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3703,7 +4144,7 @@ async def test_list_connection_profiles_flattened_error_async(): def test_list_connection_profiles_pager(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3755,7 +4196,7 @@ def test_list_connection_profiles_pager(transport_name: str = "grpc"): def test_list_connection_profiles_pages(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3799,7 +4240,7 @@ def test_list_connection_profiles_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_connection_profiles_async_pager(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3853,7 +4294,7 @@ async def test_list_connection_profiles_async_pager(): @pytest.mark.asyncio async def test_list_connection_profiles_async_pages(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3910,7 +4351,7 @@ async def test_list_connection_profiles_async_pages(): ) def test_get_connection_profile(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3948,7 +4389,7 @@ def test_get_connection_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3967,7 +4408,7 @@ async def test_get_connection_profile_async( transport: str = "grpc_asyncio", request_type=clouddms.GetConnectionProfileRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4010,7 +4451,7 @@ async def test_get_connection_profile_async_from_dict(): def test_get_connection_profile_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4042,7 +4483,7 @@ def test_get_connection_profile_field_headers(): @pytest.mark.asyncio async def test_get_connection_profile_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4075,7 +4516,7 @@ async def test_get_connection_profile_field_headers_async(): def test_get_connection_profile_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4101,7 +4542,7 @@ def test_get_connection_profile_flattened(): def test_get_connection_profile_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4116,7 +4557,7 @@ def test_get_connection_profile_flattened_error(): @pytest.mark.asyncio async def test_get_connection_profile_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4147,7 +4588,7 @@ async def test_get_connection_profile_flattened_async(): @pytest.mark.asyncio async def test_get_connection_profile_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4168,7 +4609,7 @@ async def test_get_connection_profile_flattened_error_async(): ) def test_create_connection_profile(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4197,7 +4638,7 @@ def test_create_connection_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4217,7 +4658,7 @@ async def test_create_connection_profile_async( request_type=clouddms.CreateConnectionProfileRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4251,7 +4692,7 @@ async def test_create_connection_profile_async_from_dict(): def test_create_connection_profile_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4283,7 +4724,7 @@ def test_create_connection_profile_field_headers(): @pytest.mark.asyncio async def test_create_connection_profile_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4316,7 +4757,7 @@ async def test_create_connection_profile_field_headers_async(): def test_create_connection_profile_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4350,7 +4791,7 @@ def test_create_connection_profile_flattened(): def test_create_connection_profile_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4367,7 +4808,7 @@ def test_create_connection_profile_flattened_error(): @pytest.mark.asyncio async def test_create_connection_profile_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4406,7 +4847,7 @@ async def test_create_connection_profile_flattened_async(): @pytest.mark.asyncio async def test_create_connection_profile_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4429,7 +4870,7 @@ async def test_create_connection_profile_flattened_error_async(): ) def test_update_connection_profile(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4458,7 +4899,7 @@ def test_update_connection_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4478,7 +4919,7 @@ async def test_update_connection_profile_async( request_type=clouddms.UpdateConnectionProfileRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4512,7 +4953,7 @@ async def test_update_connection_profile_async_from_dict(): def test_update_connection_profile_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4544,7 +4985,7 @@ def test_update_connection_profile_field_headers(): @pytest.mark.asyncio async def test_update_connection_profile_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4577,7 +5018,7 @@ async def test_update_connection_profile_field_headers_async(): def test_update_connection_profile_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4607,7 +5048,7 @@ def test_update_connection_profile_flattened(): def test_update_connection_profile_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4623,7 +5064,7 @@ def test_update_connection_profile_flattened_error(): @pytest.mark.asyncio async def test_update_connection_profile_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4658,7 +5099,7 @@ async def test_update_connection_profile_flattened_async(): @pytest.mark.asyncio async def test_update_connection_profile_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4680,7 +5121,7 @@ async def test_update_connection_profile_flattened_error_async(): ) def test_delete_connection_profile(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4709,7 +5150,7 @@ def test_delete_connection_profile_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4729,7 +5170,7 @@ async def test_delete_connection_profile_async( request_type=clouddms.DeleteConnectionProfileRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4763,7 +5204,7 @@ async def test_delete_connection_profile_async_from_dict(): def test_delete_connection_profile_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4795,7 +5236,7 @@ def test_delete_connection_profile_field_headers(): @pytest.mark.asyncio async def test_delete_connection_profile_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4828,7 +5269,7 @@ async def test_delete_connection_profile_field_headers_async(): def test_delete_connection_profile_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4854,7 +5295,7 @@ def test_delete_connection_profile_flattened(): def test_delete_connection_profile_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4869,7 +5310,7 @@ def test_delete_connection_profile_flattened_error(): @pytest.mark.asyncio async def test_delete_connection_profile_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4900,7 +5341,7 @@ async def test_delete_connection_profile_flattened_async(): @pytest.mark.asyncio async def test_delete_connection_profile_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4921,7 +5362,7 @@ async def test_delete_connection_profile_flattened_error_async(): ) def test_create_private_connection(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4950,7 +5391,7 @@ def test_create_private_connection_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4970,7 +5411,7 @@ async def test_create_private_connection_async( request_type=clouddms.CreatePrivateConnectionRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5004,7 +5445,7 @@ async def test_create_private_connection_async_from_dict(): def test_create_private_connection_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5036,7 +5477,7 @@ def test_create_private_connection_field_headers(): @pytest.mark.asyncio async def test_create_private_connection_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5069,7 +5510,7 @@ async def test_create_private_connection_field_headers_async(): def test_create_private_connection_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5103,7 +5544,7 @@ def test_create_private_connection_flattened(): def test_create_private_connection_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5120,7 +5561,7 @@ def test_create_private_connection_flattened_error(): @pytest.mark.asyncio async def test_create_private_connection_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5159,7 +5600,7 @@ async def test_create_private_connection_flattened_async(): @pytest.mark.asyncio async def test_create_private_connection_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5182,7 +5623,7 @@ async def test_create_private_connection_flattened_error_async(): ) def test_get_private_connection(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5218,7 +5659,7 @@ def test_get_private_connection_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5237,7 +5678,7 @@ async def test_get_private_connection_async( transport: str = "grpc_asyncio", request_type=clouddms.GetPrivateConnectionRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5278,7 +5719,7 @@ async def test_get_private_connection_async_from_dict(): def test_get_private_connection_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5310,7 +5751,7 @@ def test_get_private_connection_field_headers(): @pytest.mark.asyncio async def test_get_private_connection_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5343,7 +5784,7 @@ async def test_get_private_connection_field_headers_async(): def test_get_private_connection_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5369,7 +5810,7 @@ def test_get_private_connection_flattened(): def test_get_private_connection_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5384,7 +5825,7 @@ def test_get_private_connection_flattened_error(): @pytest.mark.asyncio async def test_get_private_connection_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5415,7 +5856,7 @@ async def test_get_private_connection_flattened_async(): @pytest.mark.asyncio async def test_get_private_connection_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5436,7 +5877,7 @@ async def test_get_private_connection_flattened_error_async(): ) def test_list_private_connections(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5470,7 +5911,7 @@ def test_list_private_connections_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5489,7 +5930,7 @@ async def test_list_private_connections_async( transport: str = "grpc_asyncio", request_type=clouddms.ListPrivateConnectionsRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5528,7 +5969,7 @@ async def test_list_private_connections_async_from_dict(): def test_list_private_connections_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5560,7 +6001,7 @@ def test_list_private_connections_field_headers(): @pytest.mark.asyncio async def test_list_private_connections_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5593,7 +6034,7 @@ async def test_list_private_connections_field_headers_async(): def test_list_private_connections_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5619,7 +6060,7 @@ def test_list_private_connections_flattened(): def test_list_private_connections_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5634,7 +6075,7 @@ def test_list_private_connections_flattened_error(): @pytest.mark.asyncio async def test_list_private_connections_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5665,7 +6106,7 @@ async def test_list_private_connections_flattened_async(): @pytest.mark.asyncio async def test_list_private_connections_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5679,7 +6120,7 @@ async def test_list_private_connections_flattened_error_async(): def test_list_private_connections_pager(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -5731,7 +6172,7 @@ def test_list_private_connections_pager(transport_name: str = "grpc"): def test_list_private_connections_pages(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -5775,7 +6216,7 @@ def test_list_private_connections_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_private_connections_async_pager(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5829,7 +6270,7 @@ async def test_list_private_connections_async_pager(): @pytest.mark.asyncio async def test_list_private_connections_async_pages(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5886,7 +6327,7 @@ async def test_list_private_connections_async_pages(): ) def test_delete_private_connection(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5915,7 +6356,7 @@ def test_delete_private_connection_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5935,7 +6376,7 @@ async def test_delete_private_connection_async( request_type=clouddms.DeletePrivateConnectionRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5969,7 +6410,7 @@ async def test_delete_private_connection_async_from_dict(): def test_delete_private_connection_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6001,7 +6442,7 @@ def test_delete_private_connection_field_headers(): @pytest.mark.asyncio async def test_delete_private_connection_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6034,7 +6475,7 @@ async def test_delete_private_connection_field_headers_async(): def test_delete_private_connection_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6060,7 +6501,7 @@ def test_delete_private_connection_flattened(): def test_delete_private_connection_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6075,7 +6516,7 @@ def test_delete_private_connection_flattened_error(): @pytest.mark.asyncio async def test_delete_private_connection_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6106,7 +6547,7 @@ async def test_delete_private_connection_flattened_async(): @pytest.mark.asyncio async def test_delete_private_connection_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6127,7 +6568,7 @@ async def test_delete_private_connection_flattened_error_async(): ) def test_get_conversion_workspace(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6165,7 +6606,7 @@ def test_get_conversion_workspace_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6184,7 +6625,7 @@ async def test_get_conversion_workspace_async( transport: str = "grpc_asyncio", request_type=clouddms.GetConversionWorkspaceRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6227,7 +6668,7 @@ async def test_get_conversion_workspace_async_from_dict(): def test_get_conversion_workspace_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6259,7 +6700,7 @@ def test_get_conversion_workspace_field_headers(): @pytest.mark.asyncio async def test_get_conversion_workspace_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6292,7 +6733,7 @@ async def test_get_conversion_workspace_field_headers_async(): def test_get_conversion_workspace_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6318,7 +6759,7 @@ def test_get_conversion_workspace_flattened(): def test_get_conversion_workspace_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6333,7 +6774,7 @@ def test_get_conversion_workspace_flattened_error(): @pytest.mark.asyncio async def test_get_conversion_workspace_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6364,7 +6805,7 @@ async def test_get_conversion_workspace_flattened_async(): @pytest.mark.asyncio async def test_get_conversion_workspace_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6385,7 +6826,7 @@ async def test_get_conversion_workspace_flattened_error_async(): ) def test_list_conversion_workspaces(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6419,7 +6860,7 @@ def test_list_conversion_workspaces_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6439,7 +6880,7 @@ async def test_list_conversion_workspaces_async( request_type=clouddms.ListConversionWorkspacesRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6478,7 +6919,7 @@ async def test_list_conversion_workspaces_async_from_dict(): def test_list_conversion_workspaces_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6510,7 +6951,7 @@ def test_list_conversion_workspaces_field_headers(): @pytest.mark.asyncio async def test_list_conversion_workspaces_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6543,7 +6984,7 @@ async def test_list_conversion_workspaces_field_headers_async(): def test_list_conversion_workspaces_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6569,7 +7010,7 @@ def test_list_conversion_workspaces_flattened(): def test_list_conversion_workspaces_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6584,7 +7025,7 @@ def test_list_conversion_workspaces_flattened_error(): @pytest.mark.asyncio async def test_list_conversion_workspaces_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6615,7 +7056,7 @@ async def test_list_conversion_workspaces_flattened_async(): @pytest.mark.asyncio async def test_list_conversion_workspaces_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6629,7 +7070,7 @@ async def test_list_conversion_workspaces_flattened_error_async(): def test_list_conversion_workspaces_pager(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6684,7 +7125,7 @@ def test_list_conversion_workspaces_pager(transport_name: str = "grpc"): def test_list_conversion_workspaces_pages(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6728,7 +7169,7 @@ def test_list_conversion_workspaces_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_conversion_workspaces_async_pager(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6783,7 +7224,7 @@ async def test_list_conversion_workspaces_async_pager(): @pytest.mark.asyncio async def test_list_conversion_workspaces_async_pages(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6840,7 +7281,7 @@ async def test_list_conversion_workspaces_async_pages(): ) def test_create_conversion_workspace(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6869,7 +7310,7 @@ def test_create_conversion_workspace_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6889,7 +7330,7 @@ async def test_create_conversion_workspace_async( request_type=clouddms.CreateConversionWorkspaceRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6923,7 +7364,7 @@ async def test_create_conversion_workspace_async_from_dict(): def test_create_conversion_workspace_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6955,7 +7396,7 @@ def test_create_conversion_workspace_field_headers(): @pytest.mark.asyncio async def test_create_conversion_workspace_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6988,7 +7429,7 @@ async def test_create_conversion_workspace_field_headers_async(): def test_create_conversion_workspace_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7024,7 +7465,7 @@ def test_create_conversion_workspace_flattened(): def test_create_conversion_workspace_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7043,7 +7484,7 @@ def test_create_conversion_workspace_flattened_error(): @pytest.mark.asyncio async def test_create_conversion_workspace_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7084,7 +7525,7 @@ async def test_create_conversion_workspace_flattened_async(): @pytest.mark.asyncio async def test_create_conversion_workspace_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7109,7 +7550,7 @@ async def test_create_conversion_workspace_flattened_error_async(): ) def test_update_conversion_workspace(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7138,7 +7579,7 @@ def test_update_conversion_workspace_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7158,7 +7599,7 @@ async def test_update_conversion_workspace_async( request_type=clouddms.UpdateConversionWorkspaceRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7192,7 +7633,7 @@ async def test_update_conversion_workspace_async_from_dict(): def test_update_conversion_workspace_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7224,7 +7665,7 @@ def test_update_conversion_workspace_field_headers(): @pytest.mark.asyncio async def test_update_conversion_workspace_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7257,7 +7698,7 @@ async def test_update_conversion_workspace_field_headers_async(): def test_update_conversion_workspace_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7289,7 +7730,7 @@ def test_update_conversion_workspace_flattened(): def test_update_conversion_workspace_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7307,7 +7748,7 @@ def test_update_conversion_workspace_flattened_error(): @pytest.mark.asyncio async def test_update_conversion_workspace_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7344,7 +7785,7 @@ async def test_update_conversion_workspace_flattened_async(): @pytest.mark.asyncio async def test_update_conversion_workspace_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7368,7 +7809,7 @@ async def test_update_conversion_workspace_flattened_error_async(): ) def test_delete_conversion_workspace(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7397,7 +7838,7 @@ def test_delete_conversion_workspace_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7417,7 +7858,7 @@ async def test_delete_conversion_workspace_async( request_type=clouddms.DeleteConversionWorkspaceRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7451,7 +7892,7 @@ async def test_delete_conversion_workspace_async_from_dict(): def test_delete_conversion_workspace_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7483,7 +7924,7 @@ def test_delete_conversion_workspace_field_headers(): @pytest.mark.asyncio async def test_delete_conversion_workspace_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7516,7 +7957,7 @@ async def test_delete_conversion_workspace_field_headers_async(): def test_delete_conversion_workspace_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7542,7 +7983,7 @@ def test_delete_conversion_workspace_flattened(): def test_delete_conversion_workspace_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7557,7 +7998,7 @@ def test_delete_conversion_workspace_flattened_error(): @pytest.mark.asyncio async def test_delete_conversion_workspace_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7588,7 +8029,7 @@ async def test_delete_conversion_workspace_flattened_async(): @pytest.mark.asyncio async def test_delete_conversion_workspace_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7609,7 +8050,7 @@ async def test_delete_conversion_workspace_flattened_error_async(): ) def test_create_mapping_rule(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7654,7 +8095,7 @@ def test_create_mapping_rule_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7673,7 +8114,7 @@ async def test_create_mapping_rule_async( transport: str = "grpc_asyncio", request_type=clouddms.CreateMappingRuleRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7723,7 +8164,7 @@ async def test_create_mapping_rule_async_from_dict(): def test_create_mapping_rule_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7755,7 +8196,7 @@ def test_create_mapping_rule_field_headers(): @pytest.mark.asyncio async def test_create_mapping_rule_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7788,7 +8229,7 @@ async def test_create_mapping_rule_field_headers_async(): def test_create_mapping_rule_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7822,7 +8263,7 @@ def test_create_mapping_rule_flattened(): def test_create_mapping_rule_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7839,7 +8280,7 @@ def test_create_mapping_rule_flattened_error(): @pytest.mark.asyncio async def test_create_mapping_rule_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7878,7 +8319,7 @@ async def test_create_mapping_rule_flattened_async(): @pytest.mark.asyncio async def test_create_mapping_rule_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7901,7 +8342,7 @@ async def test_create_mapping_rule_flattened_error_async(): ) def test_delete_mapping_rule(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7930,7 +8371,7 @@ def test_delete_mapping_rule_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7949,7 +8390,7 @@ async def test_delete_mapping_rule_async( transport: str = "grpc_asyncio", request_type=clouddms.DeleteMappingRuleRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7981,7 +8422,7 @@ async def test_delete_mapping_rule_async_from_dict(): def test_delete_mapping_rule_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8013,7 +8454,7 @@ def test_delete_mapping_rule_field_headers(): @pytest.mark.asyncio async def test_delete_mapping_rule_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8044,7 +8485,7 @@ async def test_delete_mapping_rule_field_headers_async(): def test_delete_mapping_rule_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8070,7 +8511,7 @@ def test_delete_mapping_rule_flattened(): def test_delete_mapping_rule_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8085,7 +8526,7 @@ def test_delete_mapping_rule_flattened_error(): @pytest.mark.asyncio async def test_delete_mapping_rule_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8114,7 +8555,7 @@ async def test_delete_mapping_rule_flattened_async(): @pytest.mark.asyncio async def test_delete_mapping_rule_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8135,7 +8576,7 @@ async def test_delete_mapping_rule_flattened_error_async(): ) def test_list_mapping_rules(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8167,7 +8608,7 @@ def test_list_mapping_rules_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -8186,7 +8627,7 @@ async def test_list_mapping_rules_async( transport: str = "grpc_asyncio", request_type=clouddms.ListMappingRulesRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8223,7 +8664,7 @@ async def test_list_mapping_rules_async_from_dict(): def test_list_mapping_rules_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8255,7 +8696,7 @@ def test_list_mapping_rules_field_headers(): @pytest.mark.asyncio async def test_list_mapping_rules_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8288,7 +8729,7 @@ async def test_list_mapping_rules_field_headers_async(): def test_list_mapping_rules_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8314,7 +8755,7 @@ def test_list_mapping_rules_flattened(): def test_list_mapping_rules_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8329,7 +8770,7 @@ def test_list_mapping_rules_flattened_error(): @pytest.mark.asyncio async def test_list_mapping_rules_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8360,7 +8801,7 @@ async def test_list_mapping_rules_flattened_async(): @pytest.mark.asyncio async def test_list_mapping_rules_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8374,7 +8815,7 @@ async def test_list_mapping_rules_flattened_error_async(): def test_list_mapping_rules_pager(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -8428,7 +8869,7 @@ def test_list_mapping_rules_pager(transport_name: str = "grpc"): def test_list_mapping_rules_pages(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -8472,7 +8913,7 @@ def test_list_mapping_rules_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_mapping_rules_async_pager(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8526,7 +8967,7 @@ async def test_list_mapping_rules_async_pager(): @pytest.mark.asyncio async def test_list_mapping_rules_async_pages(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8583,7 +9024,7 @@ async def test_list_mapping_rules_async_pages(): ) def test_get_mapping_rule(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8626,7 +9067,7 @@ def test_get_mapping_rule_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -8643,7 +9084,7 @@ async def test_get_mapping_rule_async( transport: str = "grpc_asyncio", request_type=clouddms.GetMappingRuleRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8691,7 +9132,7 @@ async def test_get_mapping_rule_async_from_dict(): def test_get_mapping_rule_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8721,7 +9162,7 @@ def test_get_mapping_rule_field_headers(): @pytest.mark.asyncio async def test_get_mapping_rule_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8752,7 +9193,7 @@ async def test_get_mapping_rule_field_headers_async(): def test_get_mapping_rule_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8776,7 +9217,7 @@ def test_get_mapping_rule_flattened(): def test_get_mapping_rule_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8791,7 +9232,7 @@ def test_get_mapping_rule_flattened_error(): @pytest.mark.asyncio async def test_get_mapping_rule_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8820,7 +9261,7 @@ async def test_get_mapping_rule_flattened_async(): @pytest.mark.asyncio async def test_get_mapping_rule_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8841,7 +9282,7 @@ async def test_get_mapping_rule_flattened_error_async(): ) def test_seed_conversion_workspace(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8870,7 +9311,7 @@ def test_seed_conversion_workspace_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -8890,7 +9331,7 @@ async def test_seed_conversion_workspace_async( request_type=clouddms.SeedConversionWorkspaceRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8924,7 +9365,7 @@ async def test_seed_conversion_workspace_async_from_dict(): def test_seed_conversion_workspace_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8956,7 +9397,7 @@ def test_seed_conversion_workspace_field_headers(): @pytest.mark.asyncio async def test_seed_conversion_workspace_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8996,7 +9437,7 @@ async def test_seed_conversion_workspace_field_headers_async(): ) def test_import_mapping_rules(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9025,7 +9466,7 @@ def test_import_mapping_rules_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9044,7 +9485,7 @@ async def test_import_mapping_rules_async( transport: str = "grpc_asyncio", request_type=clouddms.ImportMappingRulesRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9078,7 +9519,7 @@ async def test_import_mapping_rules_async_from_dict(): def test_import_mapping_rules_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9110,7 +9551,7 @@ def test_import_mapping_rules_field_headers(): @pytest.mark.asyncio async def test_import_mapping_rules_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9150,7 +9591,7 @@ async def test_import_mapping_rules_field_headers_async(): ) def test_convert_conversion_workspace(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9179,7 +9620,7 @@ def test_convert_conversion_workspace_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9199,7 +9640,7 @@ async def test_convert_conversion_workspace_async( request_type=clouddms.ConvertConversionWorkspaceRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9233,7 +9674,7 @@ async def test_convert_conversion_workspace_async_from_dict(): def test_convert_conversion_workspace_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9265,7 +9706,7 @@ def test_convert_conversion_workspace_field_headers(): @pytest.mark.asyncio async def test_convert_conversion_workspace_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9305,7 +9746,7 @@ async def test_convert_conversion_workspace_field_headers_async(): ) def test_commit_conversion_workspace(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9334,7 +9775,7 @@ def test_commit_conversion_workspace_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9354,7 +9795,7 @@ async def test_commit_conversion_workspace_async( request_type=clouddms.CommitConversionWorkspaceRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9388,7 +9829,7 @@ async def test_commit_conversion_workspace_async_from_dict(): def test_commit_conversion_workspace_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9420,7 +9861,7 @@ def test_commit_conversion_workspace_field_headers(): @pytest.mark.asyncio async def test_commit_conversion_workspace_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9460,7 +9901,7 @@ async def test_commit_conversion_workspace_field_headers_async(): ) def test_rollback_conversion_workspace(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9489,7 +9930,7 @@ def test_rollback_conversion_workspace_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9509,7 +9950,7 @@ async def test_rollback_conversion_workspace_async( request_type=clouddms.RollbackConversionWorkspaceRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9543,7 +9984,7 @@ async def test_rollback_conversion_workspace_async_from_dict(): def test_rollback_conversion_workspace_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9575,7 +10016,7 @@ def test_rollback_conversion_workspace_field_headers(): @pytest.mark.asyncio async def test_rollback_conversion_workspace_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9615,7 +10056,7 @@ async def test_rollback_conversion_workspace_field_headers_async(): ) def test_apply_conversion_workspace(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9644,7 +10085,7 @@ def test_apply_conversion_workspace_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9664,7 +10105,7 @@ async def test_apply_conversion_workspace_async( request_type=clouddms.ApplyConversionWorkspaceRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9698,7 +10139,7 @@ async def test_apply_conversion_workspace_async_from_dict(): def test_apply_conversion_workspace_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9730,7 +10171,7 @@ def test_apply_conversion_workspace_field_headers(): @pytest.mark.asyncio async def test_apply_conversion_workspace_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9770,7 +10211,7 @@ async def test_apply_conversion_workspace_field_headers_async(): ) def test_describe_database_entities(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9802,7 +10243,7 @@ def test_describe_database_entities_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -9822,7 +10263,7 @@ async def test_describe_database_entities_async( request_type=clouddms.DescribeDatabaseEntitiesRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9859,7 +10300,7 @@ async def test_describe_database_entities_async_from_dict(): def test_describe_database_entities_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9891,7 +10332,7 @@ def test_describe_database_entities_field_headers(): @pytest.mark.asyncio async def test_describe_database_entities_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -9924,7 +10365,7 @@ async def test_describe_database_entities_field_headers_async(): def test_describe_database_entities_pager(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -9978,7 +10419,7 @@ def test_describe_database_entities_pager(transport_name: str = "grpc"): def test_describe_database_entities_pages(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -10022,7 +10463,7 @@ def test_describe_database_entities_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_describe_database_entities_async_pager(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10077,7 +10518,7 @@ async def test_describe_database_entities_async_pager(): @pytest.mark.asyncio async def test_describe_database_entities_async_pages(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10134,7 +10575,7 @@ async def test_describe_database_entities_async_pages(): ) def test_search_background_jobs(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10163,7 +10604,7 @@ def test_search_background_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -10182,7 +10623,7 @@ async def test_search_background_jobs_async( transport: str = "grpc_asyncio", request_type=clouddms.SearchBackgroundJobsRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10216,7 +10657,7 @@ async def test_search_background_jobs_async_from_dict(): def test_search_background_jobs_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10248,7 +10689,7 @@ def test_search_background_jobs_field_headers(): @pytest.mark.asyncio async def test_search_background_jobs_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10288,7 +10729,7 @@ async def test_search_background_jobs_field_headers_async(): ) def test_describe_conversion_workspace_revisions(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10317,7 +10758,7 @@ def test_describe_conversion_workspace_revisions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -10337,7 +10778,7 @@ async def test_describe_conversion_workspace_revisions_async( request_type=clouddms.DescribeConversionWorkspaceRevisionsRequest, ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10371,7 +10812,7 @@ async def test_describe_conversion_workspace_revisions_async_from_dict(): def test_describe_conversion_workspace_revisions_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10403,7 +10844,7 @@ def test_describe_conversion_workspace_revisions_field_headers(): @pytest.mark.asyncio async def test_describe_conversion_workspace_revisions_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10443,7 +10884,7 @@ async def test_describe_conversion_workspace_revisions_field_headers_async(): ) def test_fetch_static_ips(request_type, transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10475,7 +10916,7 @@ def test_fetch_static_ips_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -10492,7 +10933,7 @@ async def test_fetch_static_ips_async( transport: str = "grpc_asyncio", request_type=clouddms.FetchStaticIpsRequest ): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10529,7 +10970,7 @@ async def test_fetch_static_ips_async_from_dict(): def test_fetch_static_ips_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10559,7 +11000,7 @@ def test_fetch_static_ips_field_headers(): @pytest.mark.asyncio async def test_fetch_static_ips_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10590,7 +11031,7 @@ async def test_fetch_static_ips_field_headers_async(): def test_fetch_static_ips_flattened(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10614,7 +11055,7 @@ def test_fetch_static_ips_flattened(): def test_fetch_static_ips_flattened_error(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -10629,7 +11070,7 @@ def test_fetch_static_ips_flattened_error(): @pytest.mark.asyncio async def test_fetch_static_ips_flattened_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10658,7 +11099,7 @@ async def test_fetch_static_ips_flattened_async(): @pytest.mark.asyncio async def test_fetch_static_ips_flattened_error_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -10672,7 +11113,7 @@ async def test_fetch_static_ips_flattened_error_async(): def test_fetch_static_ips_pager(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -10722,7 +11163,7 @@ def test_fetch_static_ips_pager(transport_name: str = "grpc"): def test_fetch_static_ips_pages(transport_name: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -10764,7 +11205,7 @@ def test_fetch_static_ips_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_fetch_static_ips_async_pager(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10814,7 +11255,7 @@ async def test_fetch_static_ips_async_pager(): @pytest.mark.asyncio async def test_fetch_static_ips_async_pages(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -10863,17 +11304,17 @@ async def test_fetch_static_ips_async_pages(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DataMigrationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DataMigrationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DataMigrationServiceClient( @@ -10883,7 +11324,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DataMigrationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -10894,16 +11335,17 @@ 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 = DataMigrationServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DataMigrationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DataMigrationServiceClient( @@ -10915,7 +11357,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DataMigrationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DataMigrationServiceClient(transport=transport) assert client.transport is transport @@ -10924,13 +11366,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DataMigrationServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DataMigrationServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -10946,7 +11388,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -10959,7 +11401,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DataMigrationServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -10967,7 +11409,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -10979,7 +11421,7 @@ def test_data_migration_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DataMigrationServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -10991,7 +11433,7 @@ def test_data_migration_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DataMigrationServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -11077,7 +11519,7 @@ def test_data_migration_service_base_transport_with_credentials_file(): "google.cloud.clouddms_v1.services.data_migration_service.transports.DataMigrationServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DataMigrationServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -11096,7 +11538,7 @@ def test_data_migration_service_base_transport_with_adc(): "google.cloud.clouddms_v1.services.data_migration_service.transports.DataMigrationServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DataMigrationServiceTransport() adc.assert_called_once() @@ -11104,7 +11546,7 @@ def test_data_migration_service_base_transport_with_adc(): def test_data_migration_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DataMigrationServiceClient() adc.assert_called_once_with( scopes=None, @@ -11124,7 +11566,7 @@ def test_data_migration_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -11170,7 +11612,7 @@ def test_data_migration_service_transport_create_channel(transport_class, grpc_h ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -11200,7 +11642,7 @@ def test_data_migration_service_transport_create_channel(transport_class, grpc_h def test_data_migration_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -11246,7 +11688,7 @@ def test_data_migration_service_grpc_transport_client_cert_source_for_mtls( ) def test_data_migration_service_host_no_port(transport_name): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="datamigration.googleapis.com" ), @@ -11264,7 +11706,7 @@ def test_data_migration_service_host_no_port(transport_name): ) def test_data_migration_service_host_with_port(transport_name): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="datamigration.googleapis.com:8000" ), @@ -11323,7 +11765,7 @@ def test_data_migration_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -11401,7 +11843,7 @@ def test_data_migration_service_transport_channel_mtls_with_adc(transport_class) def test_data_migration_service_grpc_lro_client(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -11418,7 +11860,7 @@ def test_data_migration_service_grpc_lro_client(): def test_data_migration_service_grpc_lro_async_client(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -11711,7 +12153,7 @@ def test_client_with_default_client_info(): transports.DataMigrationServiceTransport, "_prep_wrapped_messages" ) as prep: client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -11721,7 +12163,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DataMigrationServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -11730,7 +12172,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -11743,7 +12185,7 @@ async def test_transport_close_async(): def test_delete_operation(transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11768,7 +12210,7 @@ def test_delete_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_delete_operation_async(transport: str = "grpc_asyncio"): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11792,7 +12234,7 @@ async def test_delete_operation_async(transport: str = "grpc_asyncio"): def test_delete_operation_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11821,7 +12263,7 @@ def test_delete_operation_field_headers(): @pytest.mark.asyncio async def test_delete_operation_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11848,7 +12290,7 @@ async def test_delete_operation_field_headers_async(): def test_delete_operation_from_dict(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -11866,7 +12308,7 @@ def test_delete_operation_from_dict(): @pytest.mark.asyncio async def test_delete_operation_from_dict_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -11882,7 +12324,7 @@ async def test_delete_operation_from_dict_async(): def test_cancel_operation(transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11907,7 +12349,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11931,7 +12373,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11960,7 +12402,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11987,7 +12429,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -12005,7 +12447,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -12021,7 +12463,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12046,7 +12488,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12072,7 +12514,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12101,7 +12543,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12130,7 +12572,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -12148,7 +12590,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -12166,7 +12608,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12191,7 +12633,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12217,7 +12659,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12246,7 +12688,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12275,7 +12717,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -12293,7 +12735,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -12311,7 +12753,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12336,7 +12778,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12362,7 +12804,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12391,7 +12833,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12420,7 +12862,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12438,7 +12880,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12456,7 +12898,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12481,7 +12923,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12507,7 +12949,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12536,7 +12978,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12565,7 +13007,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12583,7 +13025,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12601,7 +13043,7 @@ async def test_get_location_from_dict_async(): def test_set_iam_policy(transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12634,7 +13076,7 @@ def test_set_iam_policy(transport: str = "grpc"): @pytest.mark.asyncio async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12669,7 +13111,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): def test_set_iam_policy_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12699,7 +13141,7 @@ def test_set_iam_policy_field_headers(): @pytest.mark.asyncio async def test_set_iam_policy_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12728,7 +13170,7 @@ async def test_set_iam_policy_field_headers_async(): def test_set_iam_policy_from_dict(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -12747,7 +13189,7 @@ def test_set_iam_policy_from_dict(): @pytest.mark.asyncio async def test_set_iam_policy_from_dict_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -12765,7 +13207,7 @@ async def test_set_iam_policy_from_dict_async(): def test_get_iam_policy(transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12800,7 +13242,7 @@ def test_get_iam_policy(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12836,7 +13278,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): def test_get_iam_policy_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12866,7 +13308,7 @@ def test_get_iam_policy_field_headers(): @pytest.mark.asyncio async def test_get_iam_policy_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12895,7 +13337,7 @@ async def test_get_iam_policy_field_headers_async(): def test_get_iam_policy_from_dict(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -12914,7 +13356,7 @@ def test_get_iam_policy_from_dict(): @pytest.mark.asyncio async def test_get_iam_policy_from_dict_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -12932,7 +13374,7 @@ async def test_get_iam_policy_from_dict_async(): def test_test_iam_permissions(transport: str = "grpc"): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12966,7 +13408,7 @@ def test_test_iam_permissions(transport: str = "grpc"): @pytest.mark.asyncio async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13001,7 +13443,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): def test_test_iam_permissions_field_headers(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13033,7 +13475,7 @@ def test_test_iam_permissions_field_headers(): @pytest.mark.asyncio async def test_test_iam_permissions_field_headers_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13066,7 +13508,7 @@ async def test_test_iam_permissions_field_headers_async(): def test_test_iam_permissions_from_dict(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -13087,7 +13529,7 @@ def test_test_iam_permissions_from_dict(): @pytest.mark.asyncio async def test_test_iam_permissions_from_dict_async(): client = DataMigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -13114,7 +13556,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -13130,7 +13572,7 @@ def test_client_ctx(): ] for transport in transports: client = DataMigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -13164,7 +13606,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, diff --git a/packages/google-cloud-documentai/google/cloud/documentai/gapic_version.py b/packages/google-cloud-documentai/google/cloud/documentai/gapic_version.py index 69ac2116cb35..360a0d13ebdd 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai/gapic_version.py +++ b/packages/google-cloud-documentai/google/cloud/documentai/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.21.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/gapic_version.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/gapic_version.py index 69ac2116cb35..360a0d13ebdd 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/gapic_version.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.21.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py index 12daeb3169e3..0a87c88b0709 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.documentai_v1 import gapic_version as package_version 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.api import launch_stage_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -76,8 +76,14 @@ class DocumentProcessorServiceAsyncClient: _client: DocumentProcessorServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ( + DocumentProcessorServiceClient._DEFAULT_ENDPOINT_TEMPLATE + ) + _DEFAULT_UNIVERSE = DocumentProcessorServiceClient._DEFAULT_UNIVERSE evaluation_path = staticmethod(DocumentProcessorServiceClient.evaluation_path) parse_evaluation_path = staticmethod( @@ -212,6 +218,25 @@ def transport(self) -> DocumentProcessorServiceTransport: """ 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(DocumentProcessorServiceClient).get_transport_class, type(DocumentProcessorServiceClient), @@ -225,7 +250,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the document processor service client. + """Instantiates the document processor service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -236,23 +261,38 @@ def __init__( transport (Union[str, ~.DocumentProcessorServiceTransport]): 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. @@ -382,6 +422,9 @@ async def sample_process_document(): 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, @@ -508,6 +551,9 @@ async def sample_batch_process_documents(): 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, @@ -625,6 +671,9 @@ async def sample_fetch_processor_types(): 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, @@ -736,6 +785,9 @@ async def sample_list_processor_types(): 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, @@ -852,6 +904,9 @@ async def sample_get_processor_type(): 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, @@ -962,6 +1017,9 @@ async def sample_list_processors(): 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, @@ -1078,6 +1136,9 @@ async def sample_get_processor(): 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, @@ -1202,6 +1263,9 @@ async def sample_train_processor_version(): 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, @@ -1321,6 +1385,9 @@ async def sample_get_processor_version(): 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, @@ -1432,6 +1499,9 @@ async def sample_list_processor_versions(): 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, @@ -1561,6 +1631,9 @@ async def sample_delete_processor_version(): 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, @@ -1681,6 +1754,9 @@ async def sample_deploy_processor_version(): 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, @@ -1801,6 +1877,9 @@ async def sample_undeploy_processor_version(): 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, @@ -1936,6 +2015,9 @@ async def sample_create_processor(): 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, @@ -2057,6 +2139,9 @@ async def sample_delete_processor(): 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, @@ -2156,6 +2241,9 @@ async def sample_enable_processor(): 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, @@ -2255,6 +2343,9 @@ async def sample_disable_processor(): 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, @@ -2361,6 +2452,9 @@ async def sample_set_default_processor_version(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2499,6 +2593,9 @@ async def sample_review_document(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2624,6 +2721,9 @@ async def sample_evaluate_processor_version(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2737,6 +2837,9 @@ async def sample_get_evaluation(): 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, @@ -2847,6 +2950,9 @@ async def sample_list_evaluations(): 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, @@ -2910,6 +3016,9 @@ async def list_operations( 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, @@ -2964,6 +3073,9 @@ async def get_operation( 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, @@ -3021,6 +3133,9 @@ async def cancel_operation( 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, @@ -3072,6 +3187,9 @@ async def get_location( 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, @@ -3126,6 +3244,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py index fd239378bcec..a21f10b1ef1c 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.documentai_v1 import gapic_version as package_version 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.api import launch_stage_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -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 = "documentai.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "documentai.{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 @@ -395,7 +400,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 @@ -425,6 +430,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") @@ -458,6 +468,177 @@ 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 + + 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 + + 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 = DocumentProcessorServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + DocumentProcessorServiceClient._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 = DocumentProcessorServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DocumentProcessorServiceClient._DEFAULT_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 DocumentProcessorServiceClient._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, *, @@ -477,22 +658,32 @@ def __init__( transport (Union[str, DocumentProcessorServiceTransport]): 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. @@ -503,17 +694,36 @@ 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) - - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - 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) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = DocumentProcessorServiceClient._read_environment_variables() + self._client_cert_source = ( + DocumentProcessorServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) ) + self._universe_domain = DocumentProcessorServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -522,20 +732,33 @@ 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, DocumentProcessorServiceTransport): + transport_provided = isinstance(transport, DocumentProcessorServiceTransport) + if transport_provided: # transport is a DocumentProcessorServiceTransport 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(DocumentProcessorServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or DocumentProcessorServiceClient._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( @@ -545,17 +768,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 process_document( @@ -666,6 +889,9 @@ def sample_process_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -782,6 +1008,9 @@ def sample_batch_process_documents(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -901,6 +1130,9 @@ def sample_fetch_processor_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1014,6 +1246,9 @@ def sample_list_processor_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1130,6 +1365,9 @@ def sample_get_processor_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1240,6 +1478,9 @@ def sample_list_processors(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1356,6 +1597,9 @@ def sample_get_processor(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1482,6 +1726,9 @@ def sample_train_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1603,6 +1850,9 @@ def sample_get_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1716,6 +1966,9 @@ def sample_list_processor_versions(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1847,6 +2100,9 @@ def sample_delete_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1969,6 +2225,9 @@ def sample_deploy_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2095,6 +2354,9 @@ def sample_undeploy_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2230,6 +2492,9 @@ def sample_create_processor(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2351,6 +2616,9 @@ def sample_delete_processor(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2451,6 +2719,9 @@ def sample_enable_processor(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2551,6 +2822,9 @@ def sample_disable_processor(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2664,6 +2938,9 @@ def sample_set_default_processor_version(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2792,6 +3069,9 @@ def sample_review_document(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2923,6 +3203,9 @@ def sample_evaluate_processor_version(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3036,6 +3319,9 @@ def sample_get_evaluation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3146,6 +3432,9 @@ def sample_list_evaluations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3222,6 +3511,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3276,6 +3568,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3333,6 +3628,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3384,6 +3682,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3438,6 +3739,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py index de7b45508286..71df54826118 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/base.py @@ -61,7 +61,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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 @@ -124,6 +124,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-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py index 77c56a3d480a..2f4d884bf049 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc.py @@ -72,7 +72,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py index e223125f5780..1e655c520c11 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/grpc_asyncio.py @@ -117,7 +117,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py index 1d4250bdf638..d607a4994d43 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1/services/document_processor_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -967,7 +967,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1beta2/gapic_version.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/gapic_version.py index 69ac2116cb35..360a0d13ebdd 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/gapic_version.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.21.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py index 1d456330069c..c32da7245ca3 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.documentai_v1beta2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -63,8 +63,14 @@ class DocumentUnderstandingServiceAsyncClient: _client: DocumentUnderstandingServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DocumentUnderstandingServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DocumentUnderstandingServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ( + DocumentUnderstandingServiceClient._DEFAULT_ENDPOINT_TEMPLATE + ) + _DEFAULT_UNIVERSE = DocumentUnderstandingServiceClient._DEFAULT_UNIVERSE common_billing_account_path = staticmethod( DocumentUnderstandingServiceClient.common_billing_account_path @@ -175,6 +181,25 @@ def transport(self) -> DocumentUnderstandingServiceTransport: """ 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(DocumentUnderstandingServiceClient).get_transport_class, type(DocumentUnderstandingServiceClient), @@ -188,7 +213,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the document understanding service client. + """Instantiates the document understanding service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -199,23 +224,38 @@ def __init__( transport (Union[str, ~.DocumentUnderstandingServiceTransport]): 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. @@ -344,6 +384,9 @@ async def sample_batch_process_documents(): 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, @@ -451,6 +494,9 @@ async def sample_process_document(): 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, @@ -505,6 +551,9 @@ async def list_operations( 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, @@ -559,6 +608,9 @@ async def get_operation( 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, @@ -616,6 +668,9 @@ async def cancel_operation( 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, @@ -667,6 +722,9 @@ async def get_location( 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, @@ -721,6 +779,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py index 29381280e493..2edecfc811a9 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.documentai_v1beta2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -135,11 +136,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 = "documentai.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "documentai.{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 @@ -268,7 +273,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 @@ -298,6 +303,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") @@ -331,6 +341,177 @@ 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 + + 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 + + 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 = DocumentUnderstandingServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DocumentUnderstandingServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + DocumentUnderstandingServiceClient._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 = DocumentUnderstandingServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DocumentUnderstandingServiceClient._DEFAULT_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 DocumentUnderstandingServiceClient._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, *, @@ -350,22 +531,32 @@ def __init__( transport (Union[str, DocumentUnderstandingServiceTransport]): 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. @@ -376,17 +567,36 @@ 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, + ) = DocumentUnderstandingServiceClient._read_environment_variables() + self._client_cert_source = ( + DocumentUnderstandingServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + ) + self._universe_domain = DocumentUnderstandingServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -395,20 +605,35 @@ 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, DocumentUnderstandingServiceTransport): + transport_provided = isinstance( + transport, DocumentUnderstandingServiceTransport + ) + if transport_provided: # transport is a DocumentUnderstandingServiceTransport 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(DocumentUnderstandingServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or DocumentUnderstandingServiceClient._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( @@ -418,17 +643,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 batch_process_documents( @@ -538,6 +763,9 @@ def sample_batch_process_documents(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -636,6 +864,9 @@ def sample_process_document(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -703,6 +934,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -757,6 +991,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -814,6 +1051,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -865,6 +1105,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -919,6 +1162,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py index 814d839e9a49..2a63346d3f19 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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 @@ -121,6 +121,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-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py index 354dc1cb157f..a6d351a917df 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py index fc36c2abff49..33e303b10c3a 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta2/services/document_understanding_service/transports/grpc_asyncio.py @@ -114,7 +114,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1beta3/gapic_version.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/gapic_version.py index 69ac2116cb35..360a0d13ebdd 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/gapic_version.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.21.1" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py index d130c4f36c78..e18ef3672704 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.documentai_v1beta3 import gapic_version as package_version 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.api import launch_stage_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -76,8 +76,14 @@ class DocumentProcessorServiceAsyncClient: _client: DocumentProcessorServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ( + DocumentProcessorServiceClient._DEFAULT_ENDPOINT_TEMPLATE + ) + _DEFAULT_UNIVERSE = DocumentProcessorServiceClient._DEFAULT_UNIVERSE evaluation_path = staticmethod(DocumentProcessorServiceClient.evaluation_path) parse_evaluation_path = staticmethod( @@ -212,6 +218,25 @@ def transport(self) -> DocumentProcessorServiceTransport: """ 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(DocumentProcessorServiceClient).get_transport_class, type(DocumentProcessorServiceClient), @@ -225,7 +250,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the document processor service client. + """Instantiates the document processor service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -236,23 +261,38 @@ def __init__( transport (Union[str, ~.DocumentProcessorServiceTransport]): 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. @@ -383,6 +423,9 @@ async def sample_process_document(): 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, @@ -510,6 +553,9 @@ async def sample_batch_process_documents(): 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, @@ -627,6 +673,9 @@ async def sample_fetch_processor_types(): 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, @@ -738,6 +787,9 @@ async def sample_list_processor_types(): 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, @@ -854,6 +906,9 @@ async def sample_get_processor_type(): 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, @@ -964,6 +1019,9 @@ async def sample_list_processors(): 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, @@ -1080,6 +1138,9 @@ async def sample_get_processor(): 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, @@ -1204,6 +1265,9 @@ async def sample_train_processor_version(): 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, @@ -1323,6 +1387,9 @@ async def sample_get_processor_version(): 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, @@ -1434,6 +1501,9 @@ async def sample_list_processor_versions(): 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, @@ -1563,6 +1633,9 @@ async def sample_delete_processor_version(): 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, @@ -1683,6 +1756,9 @@ async def sample_deploy_processor_version(): 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, @@ -1803,6 +1879,9 @@ async def sample_undeploy_processor_version(): 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, @@ -1938,6 +2017,9 @@ async def sample_create_processor(): 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, @@ -2059,6 +2141,9 @@ async def sample_delete_processor(): 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, @@ -2158,6 +2243,9 @@ async def sample_enable_processor(): 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, @@ -2257,6 +2345,9 @@ async def sample_disable_processor(): 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, @@ -2363,6 +2454,9 @@ async def sample_set_default_processor_version(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2501,6 +2595,9 @@ async def sample_review_document(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2626,6 +2723,9 @@ async def sample_evaluate_processor_version(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2739,6 +2839,9 @@ async def sample_get_evaluation(): 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, @@ -2849,6 +2952,9 @@ async def sample_list_evaluations(): 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, @@ -2987,6 +3093,9 @@ async def sample_import_processor_version(): 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, @@ -3049,6 +3158,9 @@ async def list_operations( 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, @@ -3103,6 +3215,9 @@ async def get_operation( 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, @@ -3160,6 +3275,9 @@ async def cancel_operation( 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, @@ -3211,6 +3329,9 @@ async def get_location( 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, @@ -3265,6 +3386,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py index 17711be9b4a8..b12922747295 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.documentai_v1beta3 import gapic_version as package_version 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.api import launch_stage_pb2 # type: ignore from google.api_core import operation # type: ignore @@ -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 = "documentai.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "documentai.{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 @@ -395,7 +400,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 @@ -425,6 +430,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") @@ -458,6 +468,177 @@ 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 + + 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 + + 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 = DocumentProcessorServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + DocumentProcessorServiceClient._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 = DocumentProcessorServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DocumentProcessorServiceClient._DEFAULT_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 DocumentProcessorServiceClient._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, *, @@ -477,22 +658,32 @@ def __init__( transport (Union[str, DocumentProcessorServiceTransport]): 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. @@ -503,17 +694,36 @@ 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) - - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - 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) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = DocumentProcessorServiceClient._read_environment_variables() + self._client_cert_source = ( + DocumentProcessorServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + ) + self._universe_domain = DocumentProcessorServiceClient._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" @@ -522,20 +732,33 @@ 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, DocumentProcessorServiceTransport): + transport_provided = isinstance(transport, DocumentProcessorServiceTransport) + if transport_provided: # transport is a DocumentProcessorServiceTransport 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(DocumentProcessorServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or DocumentProcessorServiceClient._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( @@ -545,17 +768,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 process_document( @@ -667,6 +890,9 @@ def sample_process_document(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -784,6 +1010,9 @@ def sample_batch_process_documents(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -903,6 +1132,9 @@ def sample_fetch_processor_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1016,6 +1248,9 @@ def sample_list_processor_types(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1132,6 +1367,9 @@ def sample_get_processor_type(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1242,6 +1480,9 @@ def sample_list_processors(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1358,6 +1599,9 @@ def sample_get_processor(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1484,6 +1728,9 @@ def sample_train_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1605,6 +1852,9 @@ def sample_get_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1718,6 +1968,9 @@ def sample_list_processor_versions(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1849,6 +2102,9 @@ def sample_delete_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1971,6 +2227,9 @@ def sample_deploy_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2097,6 +2356,9 @@ def sample_undeploy_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2232,6 +2494,9 @@ def sample_create_processor(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2353,6 +2618,9 @@ def sample_delete_processor(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2453,6 +2721,9 @@ def sample_enable_processor(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2553,6 +2824,9 @@ def sample_disable_processor(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2666,6 +2940,9 @@ def sample_set_default_processor_version(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2794,6 +3071,9 @@ def sample_review_document(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2925,6 +3205,9 @@ def sample_evaluate_processor_version(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3038,6 +3321,9 @@ def sample_get_evaluation(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3148,6 +3434,9 @@ def sample_list_evaluations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3288,6 +3577,9 @@ def sample_import_processor_version(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3363,6 +3655,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3417,6 +3712,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3474,6 +3772,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3525,6 +3826,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3579,6 +3883,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py index b5451b7b281e..b8ee7f97f192 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/base.py @@ -61,7 +61,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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 @@ -124,6 +124,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-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py index 30d5d951d348..bedb02626c10 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc.py @@ -72,7 +72,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py index ceb937f24a87..4c9c0ecc7ea2 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/grpc_asyncio.py @@ -117,7 +117,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py index 39827e7e6c0a..beeb361c4fc8 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_processor_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -1001,7 +1001,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1beta3/services/document_service/async_client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/async_client.py index 6ff22dbf5360..1e31d001ee97 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/async_client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.documentai_v1beta3 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -69,8 +69,12 @@ class DocumentServiceAsyncClient: _client: DocumentServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DocumentServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DocumentServiceClient._DEFAULT_UNIVERSE dataset_path = staticmethod(DocumentServiceClient.dataset_path) parse_dataset_path = staticmethod(DocumentServiceClient.parse_dataset_path) @@ -183,6 +187,25 @@ def transport(self) -> DocumentServiceTransport: """ 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(DocumentServiceClient).get_transport_class, type(DocumentServiceClient) ) @@ -195,7 +218,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the document service client. + """Instantiates the document service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -206,23 +229,38 @@ def __init__( transport (Union[str, ~.DocumentServiceTransport]): 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. @@ -346,6 +384,9 @@ async def sample_update_dataset(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -468,6 +509,9 @@ async def sample_import_documents(): gapic_v1.routing_header.to_grpc_metadata((("dataset", request.dataset),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -583,6 +627,9 @@ async def sample_get_document(): gapic_v1.routing_header.to_grpc_metadata((("dataset", request.dataset),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -688,6 +735,9 @@ async def sample_list_documents(): gapic_v1.routing_header.to_grpc_metadata((("dataset", request.dataset),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -813,6 +863,9 @@ async def sample_batch_delete_documents(): gapic_v1.routing_header.to_grpc_metadata((("dataset", request.dataset),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -922,6 +975,9 @@ async def sample_get_dataset_schema(): 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, @@ -1034,6 +1090,9 @@ async def sample_update_dataset_schema(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1088,6 +1147,9 @@ async def list_operations( 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, @@ -1142,6 +1204,9 @@ async def get_operation( 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, @@ -1199,6 +1264,9 @@ async def cancel_operation( 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, @@ -1250,6 +1318,9 @@ async def get_location( 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, @@ -1304,6 +1375,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/client.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/client.py index 93cd6cd6b57e..847e748cf672 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/client.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.documentai_v1beta3 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -139,11 +140,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 = "documentai.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "documentai.{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 @@ -338,7 +343,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 @@ -368,6 +373,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") @@ -401,6 +411,175 @@ 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 + + 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 + + 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 = DocumentServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DocumentServiceClient._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 = DocumentServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DocumentServiceClient._DEFAULT_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 DocumentServiceClient._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, *, @@ -420,22 +599,32 @@ def __init__( transport (Union[str, DocumentServiceTransport]): 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. @@ -446,17 +635,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = DocumentServiceClient._read_environment_variables() + self._client_cert_source = DocumentServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = DocumentServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -465,20 +671,33 @@ 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, DocumentServiceTransport): + transport_provided = isinstance(transport, DocumentServiceTransport) + if transport_provided: # transport is a DocumentServiceTransport 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(DocumentServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or DocumentServiceClient._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( @@ -488,17 +707,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 update_dataset( @@ -613,6 +832,9 @@ def sample_update_dataset(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -735,6 +957,9 @@ def sample_import_documents(): gapic_v1.routing_header.to_grpc_metadata((("dataset", request.dataset),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -850,6 +1075,9 @@ def sample_get_document(): gapic_v1.routing_header.to_grpc_metadata((("dataset", request.dataset),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -955,6 +1183,9 @@ def sample_list_documents(): gapic_v1.routing_header.to_grpc_metadata((("dataset", request.dataset),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1080,6 +1311,9 @@ def sample_batch_delete_documents(): gapic_v1.routing_header.to_grpc_metadata((("dataset", request.dataset),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1189,6 +1423,9 @@ def sample_get_dataset_schema(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1301,6 +1538,9 @@ def sample_update_dataset_schema(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1368,6 +1608,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1422,6 +1665,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1479,6 +1725,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1530,6 +1779,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1584,6 +1836,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/base.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/base.py index 04e054ff1e7e..e3e38c92f158 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/base.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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 @@ -121,6 +121,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-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc.py index b33bbdc21fe0..45de5e5f4627 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc_asyncio.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc_asyncio.py index 8ecc480bcc64..1d4e0ea0c53b 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/rest.py b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/rest.py index 8bb9182a2dd6..0d9679644ce5 100644 --- a/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/rest.py +++ b/packages/google-cloud-documentai/google/cloud/documentai_v1beta3/services/document_service/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -449,7 +449,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'documentai.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-documentai/noxfile.py b/packages/google-cloud-documentai/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-documentai/noxfile.py +++ b/packages/google-cloud-documentai/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1.json b/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1.json index 3ea560e105da..96d60af285a2 100644 --- a/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1.json +++ b/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-documentai", - "version": "2.21.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta2.json b/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta2.json index a1a261bfb0bc..ef56bd7e3eb3 100644 --- a/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta2.json +++ b/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-documentai", - "version": "2.21.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta3.json b/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta3.json index 8e5787c9fac5..f47545a8ed3e 100644 --- a/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta3.json +++ b/packages/google-cloud-documentai/samples/generated_samples/snippet_metadata_google.cloud.documentai.v1beta3.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-documentai", - "version": "2.21.1" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py index e255f8c7e195..e0d5ce2b529d 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1/test_document_processor_service.py @@ -36,7 +36,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -101,6 +101,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -131,6 +154,291 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DocumentProcessorServiceClient._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 DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentProcessorServiceClient._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 DocumentProcessorServiceClient._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 DocumentProcessorServiceClient._get_client_cert_source(None, False) is None + assert ( + DocumentProcessorServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + DocumentProcessorServiceClient._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 ( + DocumentProcessorServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DocumentProcessorServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DocumentProcessorServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceClient), +) +@mock.patch.object( + DocumentProcessorServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DocumentProcessorServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentProcessorServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentProcessorServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentProcessorServiceClient._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 ( + DocumentProcessorServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DocumentProcessorServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DocumentProcessorServiceClient._get_universe_domain(None, None) + == DocumentProcessorServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DocumentProcessorServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + DocumentProcessorServiceClient, + transports.DocumentProcessorServiceGrpcTransport, + "grpc", + ), + ( + DocumentProcessorServiceClient, + transports.DocumentProcessorServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -142,7 +450,7 @@ def test__get_default_mtls_endpoint(): def test_document_processor_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -196,7 +504,7 @@ def test_document_processor_service_client_service_account_always_use_jwt( def test_document_processor_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -254,13 +562,13 @@ def test_document_processor_service_client_get_transport_class(): ) @mock.patch.object( DocumentProcessorServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentProcessorServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceClient), ) @mock.patch.object( DocumentProcessorServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentProcessorServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceAsyncClient), ) def test_document_processor_service_client_client_options( client_class, transport_class, transport_name @@ -269,7 +577,9 @@ def test_document_processor_service_client_client_options( with mock.patch.object( DocumentProcessorServiceClient, "get_transport_class" ) as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -306,7 +616,9 @@ def test_document_processor_service_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, @@ -336,15 +648,23 @@ def test_document_processor_service_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") @@ -354,7 +674,9 @@ def test_document_processor_service_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", @@ -372,7 +694,9 @@ def test_document_processor_service_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, @@ -425,13 +749,13 @@ def test_document_processor_service_client_client_options( ) @mock.patch.object( DocumentProcessorServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentProcessorServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceClient), ) @mock.patch.object( DocumentProcessorServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentProcessorServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_document_processor_service_client_mtls_env_auto( @@ -454,7 +778,9 @@ def test_document_processor_service_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 @@ -486,7 +812,9 @@ def test_document_processor_service_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 @@ -520,7 +848,9 @@ def test_document_processor_service_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, @@ -613,6 +943,119 @@ def test_document_processor_service_client_get_mtls_endpoint_and_cert_source( 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", + [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient], +) +@mock.patch.object( + DocumentProcessorServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceClient), +) +@mock.patch.object( + DocumentProcessorServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceAsyncClient), +) +def test_document_processor_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DocumentProcessorServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentProcessorServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentProcessorServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -647,7 +1090,9 @@ def test_document_processor_service_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, @@ -692,7 +1137,9 @@ def test_document_processor_service_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, @@ -752,7 +1199,9 @@ def test_document_processor_service_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, @@ -769,8 +1218,8 @@ def test_document_processor_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -799,7 +1248,7 @@ def test_document_processor_service_client_create_channel_credentials_file( ) def test_process_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -826,7 +1275,7 @@ def test_process_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -844,7 +1293,7 @@ async def test_process_document_async( request_type=document_processor_service.ProcessRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -876,7 +1325,7 @@ async def test_process_document_async_from_dict(): def test_process_document_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -906,7 +1355,7 @@ def test_process_document_field_headers(): @pytest.mark.asyncio async def test_process_document_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -937,7 +1386,7 @@ async def test_process_document_field_headers_async(): def test_process_document_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -961,7 +1410,7 @@ def test_process_document_flattened(): def test_process_document_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -976,7 +1425,7 @@ def test_process_document_flattened_error(): @pytest.mark.asyncio async def test_process_document_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1005,7 +1454,7 @@ async def test_process_document_flattened_async(): @pytest.mark.asyncio async def test_process_document_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1026,7 +1475,7 @@ async def test_process_document_flattened_error_async(): ) def test_batch_process_documents(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1055,7 +1504,7 @@ def test_batch_process_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1075,7 +1524,7 @@ async def test_batch_process_documents_async( request_type=document_processor_service.BatchProcessRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1109,7 +1558,7 @@ async def test_batch_process_documents_async_from_dict(): def test_batch_process_documents_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1141,7 +1590,7 @@ def test_batch_process_documents_field_headers(): @pytest.mark.asyncio async def test_batch_process_documents_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1174,7 +1623,7 @@ async def test_batch_process_documents_field_headers_async(): def test_batch_process_documents_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1200,7 +1649,7 @@ def test_batch_process_documents_flattened(): def test_batch_process_documents_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1215,7 +1664,7 @@ def test_batch_process_documents_flattened_error(): @pytest.mark.asyncio async def test_batch_process_documents_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1246,7 +1695,7 @@ async def test_batch_process_documents_flattened_async(): @pytest.mark.asyncio async def test_batch_process_documents_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1267,7 +1716,7 @@ async def test_batch_process_documents_flattened_error_async(): ) def test_fetch_processor_types(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1296,7 +1745,7 @@ def test_fetch_processor_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1316,7 +1765,7 @@ async def test_fetch_processor_types_async( request_type=document_processor_service.FetchProcessorTypesRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1350,7 +1799,7 @@ async def test_fetch_processor_types_async_from_dict(): def test_fetch_processor_types_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1382,7 +1831,7 @@ def test_fetch_processor_types_field_headers(): @pytest.mark.asyncio async def test_fetch_processor_types_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1415,7 +1864,7 @@ async def test_fetch_processor_types_field_headers_async(): def test_fetch_processor_types_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1441,7 +1890,7 @@ def test_fetch_processor_types_flattened(): def test_fetch_processor_types_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1456,7 +1905,7 @@ def test_fetch_processor_types_flattened_error(): @pytest.mark.asyncio async def test_fetch_processor_types_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1487,7 +1936,7 @@ async def test_fetch_processor_types_flattened_async(): @pytest.mark.asyncio async def test_fetch_processor_types_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1508,7 +1957,7 @@ async def test_fetch_processor_types_flattened_error_async(): ) def test_list_processor_types(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1540,7 +1989,7 @@ def test_list_processor_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1560,7 +2009,7 @@ async def test_list_processor_types_async( request_type=document_processor_service.ListProcessorTypesRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1597,7 +2046,7 @@ async def test_list_processor_types_async_from_dict(): def test_list_processor_types_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1629,7 +2078,7 @@ def test_list_processor_types_field_headers(): @pytest.mark.asyncio async def test_list_processor_types_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1662,7 +2111,7 @@ async def test_list_processor_types_field_headers_async(): def test_list_processor_types_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1688,7 +2137,7 @@ def test_list_processor_types_flattened(): def test_list_processor_types_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1703,7 +2152,7 @@ def test_list_processor_types_flattened_error(): @pytest.mark.asyncio async def test_list_processor_types_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1734,7 +2183,7 @@ async def test_list_processor_types_flattened_async(): @pytest.mark.asyncio async def test_list_processor_types_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1748,7 +2197,7 @@ async def test_list_processor_types_flattened_error_async(): def test_list_processor_types_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1800,7 +2249,7 @@ def test_list_processor_types_pager(transport_name: str = "grpc"): def test_list_processor_types_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1844,7 +2293,7 @@ def test_list_processor_types_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_processor_types_async_pager(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1896,7 +2345,7 @@ async def test_list_processor_types_async_pager(): @pytest.mark.asyncio async def test_list_processor_types_async_pages(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1953,7 +2402,7 @@ async def test_list_processor_types_async_pages(): ) def test_get_processor_type(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1995,7 +2444,7 @@ def test_get_processor_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2015,7 +2464,7 @@ async def test_get_processor_type_async( request_type=document_processor_service.GetProcessorTypeRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2062,7 +2511,7 @@ async def test_get_processor_type_async_from_dict(): def test_get_processor_type_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2094,7 +2543,7 @@ def test_get_processor_type_field_headers(): @pytest.mark.asyncio async def test_get_processor_type_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2127,7 +2576,7 @@ async def test_get_processor_type_field_headers_async(): def test_get_processor_type_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2153,7 +2602,7 @@ def test_get_processor_type_flattened(): def test_get_processor_type_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2168,7 +2617,7 @@ def test_get_processor_type_flattened_error(): @pytest.mark.asyncio async def test_get_processor_type_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2199,7 +2648,7 @@ async def test_get_processor_type_flattened_async(): @pytest.mark.asyncio async def test_get_processor_type_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2220,7 +2669,7 @@ async def test_get_processor_type_flattened_error_async(): ) def test_list_processors(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2250,7 +2699,7 @@ def test_list_processors_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2268,7 +2717,7 @@ async def test_list_processors_async( request_type=document_processor_service.ListProcessorsRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2303,7 +2752,7 @@ async def test_list_processors_async_from_dict(): def test_list_processors_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2333,7 +2782,7 @@ def test_list_processors_field_headers(): @pytest.mark.asyncio async def test_list_processors_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2364,7 +2813,7 @@ async def test_list_processors_field_headers_async(): def test_list_processors_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2388,7 +2837,7 @@ def test_list_processors_flattened(): def test_list_processors_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2403,7 +2852,7 @@ def test_list_processors_flattened_error(): @pytest.mark.asyncio async def test_list_processors_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2432,7 +2881,7 @@ async def test_list_processors_flattened_async(): @pytest.mark.asyncio async def test_list_processors_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2446,7 +2895,7 @@ async def test_list_processors_flattened_error_async(): def test_list_processors_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2496,7 +2945,7 @@ def test_list_processors_pager(transport_name: str = "grpc"): def test_list_processors_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2538,7 +2987,7 @@ def test_list_processors_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_processors_async_pager(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2588,7 +3037,7 @@ async def test_list_processors_async_pager(): @pytest.mark.asyncio async def test_list_processors_async_pages(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2643,7 +3092,7 @@ async def test_list_processors_async_pages(): ) def test_get_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2685,7 +3134,7 @@ def test_get_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2703,7 +3152,7 @@ async def test_get_processor_async( request_type=document_processor_service.GetProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2750,7 +3199,7 @@ async def test_get_processor_async_from_dict(): def test_get_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2780,7 +3229,7 @@ def test_get_processor_field_headers(): @pytest.mark.asyncio async def test_get_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2809,7 +3258,7 @@ async def test_get_processor_field_headers_async(): def test_get_processor_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2833,7 +3282,7 @@ def test_get_processor_flattened(): def test_get_processor_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2848,7 +3297,7 @@ def test_get_processor_flattened_error(): @pytest.mark.asyncio async def test_get_processor_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2875,7 +3324,7 @@ async def test_get_processor_flattened_async(): @pytest.mark.asyncio async def test_get_processor_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2896,7 +3345,7 @@ async def test_get_processor_flattened_error_async(): ) def test_train_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2925,7 +3374,7 @@ def test_train_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2945,7 +3394,7 @@ async def test_train_processor_version_async( request_type=document_processor_service.TrainProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2979,7 +3428,7 @@ async def test_train_processor_version_async_from_dict(): def test_train_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3011,7 +3460,7 @@ def test_train_processor_version_field_headers(): @pytest.mark.asyncio async def test_train_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3044,7 +3493,7 @@ async def test_train_processor_version_field_headers_async(): def test_train_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3074,7 +3523,7 @@ def test_train_processor_version_flattened(): def test_train_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3090,7 +3539,7 @@ def test_train_processor_version_flattened_error(): @pytest.mark.asyncio async def test_train_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3125,7 +3574,7 @@ async def test_train_processor_version_flattened_async(): @pytest.mark.asyncio async def test_train_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3147,7 +3596,7 @@ async def test_train_processor_version_flattened_error_async(): ) def test_get_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3189,7 +3638,7 @@ def test_get_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3209,7 +3658,7 @@ async def test_get_processor_version_async( request_type=document_processor_service.GetProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3256,7 +3705,7 @@ async def test_get_processor_version_async_from_dict(): def test_get_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3288,7 +3737,7 @@ def test_get_processor_version_field_headers(): @pytest.mark.asyncio async def test_get_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3321,7 +3770,7 @@ async def test_get_processor_version_field_headers_async(): def test_get_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3347,7 +3796,7 @@ def test_get_processor_version_flattened(): def test_get_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3362,7 +3811,7 @@ def test_get_processor_version_flattened_error(): @pytest.mark.asyncio async def test_get_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3393,7 +3842,7 @@ async def test_get_processor_version_flattened_async(): @pytest.mark.asyncio async def test_get_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3414,7 +3863,7 @@ async def test_get_processor_version_flattened_error_async(): ) def test_list_processor_versions(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3446,7 +3895,7 @@ def test_list_processor_versions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3466,7 +3915,7 @@ async def test_list_processor_versions_async( request_type=document_processor_service.ListProcessorVersionsRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3503,7 +3952,7 @@ async def test_list_processor_versions_async_from_dict(): def test_list_processor_versions_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3535,7 +3984,7 @@ def test_list_processor_versions_field_headers(): @pytest.mark.asyncio async def test_list_processor_versions_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3568,7 +4017,7 @@ async def test_list_processor_versions_field_headers_async(): def test_list_processor_versions_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3594,7 +4043,7 @@ def test_list_processor_versions_flattened(): def test_list_processor_versions_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3609,7 +4058,7 @@ def test_list_processor_versions_flattened_error(): @pytest.mark.asyncio async def test_list_processor_versions_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3640,7 +4089,7 @@ async def test_list_processor_versions_flattened_async(): @pytest.mark.asyncio async def test_list_processor_versions_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3654,7 +4103,7 @@ async def test_list_processor_versions_flattened_error_async(): def test_list_processor_versions_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3706,7 +4155,7 @@ def test_list_processor_versions_pager(transport_name: str = "grpc"): def test_list_processor_versions_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3750,7 +4199,7 @@ def test_list_processor_versions_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_processor_versions_async_pager(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3802,7 +4251,7 @@ async def test_list_processor_versions_async_pager(): @pytest.mark.asyncio async def test_list_processor_versions_async_pages(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3859,7 +4308,7 @@ async def test_list_processor_versions_async_pages(): ) def test_delete_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3888,7 +4337,7 @@ def test_delete_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3908,7 +4357,7 @@ async def test_delete_processor_version_async( request_type=document_processor_service.DeleteProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3942,7 +4391,7 @@ async def test_delete_processor_version_async_from_dict(): def test_delete_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3974,7 +4423,7 @@ def test_delete_processor_version_field_headers(): @pytest.mark.asyncio async def test_delete_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4007,7 +4456,7 @@ async def test_delete_processor_version_field_headers_async(): def test_delete_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4033,7 +4482,7 @@ def test_delete_processor_version_flattened(): def test_delete_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4048,7 +4497,7 @@ def test_delete_processor_version_flattened_error(): @pytest.mark.asyncio async def test_delete_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4079,7 +4528,7 @@ async def test_delete_processor_version_flattened_async(): @pytest.mark.asyncio async def test_delete_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4100,7 +4549,7 @@ async def test_delete_processor_version_flattened_error_async(): ) def test_deploy_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4129,7 +4578,7 @@ def test_deploy_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4149,7 +4598,7 @@ async def test_deploy_processor_version_async( request_type=document_processor_service.DeployProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4183,7 +4632,7 @@ async def test_deploy_processor_version_async_from_dict(): def test_deploy_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4215,7 +4664,7 @@ def test_deploy_processor_version_field_headers(): @pytest.mark.asyncio async def test_deploy_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4248,7 +4697,7 @@ async def test_deploy_processor_version_field_headers_async(): def test_deploy_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4274,7 +4723,7 @@ def test_deploy_processor_version_flattened(): def test_deploy_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4289,7 +4738,7 @@ def test_deploy_processor_version_flattened_error(): @pytest.mark.asyncio async def test_deploy_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4320,7 +4769,7 @@ async def test_deploy_processor_version_flattened_async(): @pytest.mark.asyncio async def test_deploy_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4341,7 +4790,7 @@ async def test_deploy_processor_version_flattened_error_async(): ) def test_undeploy_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4370,7 +4819,7 @@ def test_undeploy_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4390,7 +4839,7 @@ async def test_undeploy_processor_version_async( request_type=document_processor_service.UndeployProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4424,7 +4873,7 @@ async def test_undeploy_processor_version_async_from_dict(): def test_undeploy_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4456,7 +4905,7 @@ def test_undeploy_processor_version_field_headers(): @pytest.mark.asyncio async def test_undeploy_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4489,7 +4938,7 @@ async def test_undeploy_processor_version_field_headers_async(): def test_undeploy_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4515,7 +4964,7 @@ def test_undeploy_processor_version_flattened(): def test_undeploy_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4530,7 +4979,7 @@ def test_undeploy_processor_version_flattened_error(): @pytest.mark.asyncio async def test_undeploy_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4561,7 +5010,7 @@ async def test_undeploy_processor_version_flattened_async(): @pytest.mark.asyncio async def test_undeploy_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4582,7 +5031,7 @@ async def test_undeploy_processor_version_flattened_error_async(): ) def test_create_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4624,7 +5073,7 @@ def test_create_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4642,7 +5091,7 @@ async def test_create_processor_async( request_type=document_processor_service.CreateProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4689,7 +5138,7 @@ async def test_create_processor_async_from_dict(): def test_create_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4719,7 +5168,7 @@ def test_create_processor_field_headers(): @pytest.mark.asyncio async def test_create_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4750,7 +5199,7 @@ async def test_create_processor_field_headers_async(): def test_create_processor_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4778,7 +5227,7 @@ def test_create_processor_flattened(): def test_create_processor_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4794,7 +5243,7 @@ def test_create_processor_flattened_error(): @pytest.mark.asyncio async def test_create_processor_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4827,7 +5276,7 @@ async def test_create_processor_flattened_async(): @pytest.mark.asyncio async def test_create_processor_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4849,7 +5298,7 @@ async def test_create_processor_flattened_error_async(): ) def test_delete_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4876,7 +5325,7 @@ def test_delete_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4894,7 +5343,7 @@ async def test_delete_processor_async( request_type=document_processor_service.DeleteProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4926,7 +5375,7 @@ async def test_delete_processor_async_from_dict(): def test_delete_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4956,7 +5405,7 @@ def test_delete_processor_field_headers(): @pytest.mark.asyncio async def test_delete_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4987,7 +5436,7 @@ async def test_delete_processor_field_headers_async(): def test_delete_processor_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5011,7 +5460,7 @@ def test_delete_processor_flattened(): def test_delete_processor_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5026,7 +5475,7 @@ def test_delete_processor_flattened_error(): @pytest.mark.asyncio async def test_delete_processor_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5055,7 +5504,7 @@ async def test_delete_processor_flattened_async(): @pytest.mark.asyncio async def test_delete_processor_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5076,7 +5525,7 @@ async def test_delete_processor_flattened_error_async(): ) def test_enable_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5103,7 +5552,7 @@ def test_enable_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5121,7 +5570,7 @@ async def test_enable_processor_async( request_type=document_processor_service.EnableProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5153,7 +5602,7 @@ async def test_enable_processor_async_from_dict(): def test_enable_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5183,7 +5632,7 @@ def test_enable_processor_field_headers(): @pytest.mark.asyncio async def test_enable_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5221,7 +5670,7 @@ async def test_enable_processor_field_headers_async(): ) def test_disable_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5250,7 +5699,7 @@ def test_disable_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5270,7 +5719,7 @@ async def test_disable_processor_async( request_type=document_processor_service.DisableProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5304,7 +5753,7 @@ async def test_disable_processor_async_from_dict(): def test_disable_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5336,7 +5785,7 @@ def test_disable_processor_field_headers(): @pytest.mark.asyncio async def test_disable_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5376,7 +5825,7 @@ async def test_disable_processor_field_headers_async(): ) def test_set_default_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5405,7 +5854,7 @@ def test_set_default_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5425,7 +5874,7 @@ async def test_set_default_processor_version_async( request_type=document_processor_service.SetDefaultProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5459,7 +5908,7 @@ async def test_set_default_processor_version_async_from_dict(): def test_set_default_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5491,7 +5940,7 @@ def test_set_default_processor_version_field_headers(): @pytest.mark.asyncio async def test_set_default_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5531,7 +5980,7 @@ async def test_set_default_processor_version_field_headers_async(): ) def test_review_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5558,7 +6007,7 @@ def test_review_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5576,7 +6025,7 @@ async def test_review_document_async( request_type=document_processor_service.ReviewDocumentRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5608,7 +6057,7 @@ async def test_review_document_async_from_dict(): def test_review_document_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5638,7 +6087,7 @@ def test_review_document_field_headers(): @pytest.mark.asyncio async def test_review_document_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5669,7 +6118,7 @@ async def test_review_document_field_headers_async(): def test_review_document_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5693,7 +6142,7 @@ def test_review_document_flattened(): def test_review_document_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5708,7 +6157,7 @@ def test_review_document_flattened_error(): @pytest.mark.asyncio async def test_review_document_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5737,7 +6186,7 @@ async def test_review_document_flattened_async(): @pytest.mark.asyncio async def test_review_document_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5758,7 +6207,7 @@ async def test_review_document_flattened_error_async(): ) def test_evaluate_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5787,7 +6236,7 @@ def test_evaluate_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5807,7 +6256,7 @@ async def test_evaluate_processor_version_async( request_type=document_processor_service.EvaluateProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5841,7 +6290,7 @@ async def test_evaluate_processor_version_async_from_dict(): def test_evaluate_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5873,7 +6322,7 @@ def test_evaluate_processor_version_field_headers(): @pytest.mark.asyncio async def test_evaluate_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5906,7 +6355,7 @@ async def test_evaluate_processor_version_field_headers_async(): def test_evaluate_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5932,7 +6381,7 @@ def test_evaluate_processor_version_flattened(): def test_evaluate_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5947,7 +6396,7 @@ def test_evaluate_processor_version_flattened_error(): @pytest.mark.asyncio async def test_evaluate_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5978,7 +6427,7 @@ async def test_evaluate_processor_version_flattened_async(): @pytest.mark.asyncio async def test_evaluate_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5999,7 +6448,7 @@ async def test_evaluate_processor_version_flattened_error_async(): ) def test_get_evaluation(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6033,7 +6482,7 @@ def test_get_evaluation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6051,7 +6500,7 @@ async def test_get_evaluation_async( request_type=document_processor_service.GetEvaluationRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6090,7 +6539,7 @@ async def test_get_evaluation_async_from_dict(): def test_get_evaluation_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6120,7 +6569,7 @@ def test_get_evaluation_field_headers(): @pytest.mark.asyncio async def test_get_evaluation_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6151,7 +6600,7 @@ async def test_get_evaluation_field_headers_async(): def test_get_evaluation_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6175,7 +6624,7 @@ def test_get_evaluation_flattened(): def test_get_evaluation_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6190,7 +6639,7 @@ def test_get_evaluation_flattened_error(): @pytest.mark.asyncio async def test_get_evaluation_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6219,7 +6668,7 @@ async def test_get_evaluation_flattened_async(): @pytest.mark.asyncio async def test_get_evaluation_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6240,7 +6689,7 @@ async def test_get_evaluation_flattened_error_async(): ) def test_list_evaluations(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6270,7 +6719,7 @@ def test_list_evaluations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6288,7 +6737,7 @@ async def test_list_evaluations_async( request_type=document_processor_service.ListEvaluationsRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6323,7 +6772,7 @@ async def test_list_evaluations_async_from_dict(): def test_list_evaluations_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6353,7 +6802,7 @@ def test_list_evaluations_field_headers(): @pytest.mark.asyncio async def test_list_evaluations_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6384,7 +6833,7 @@ async def test_list_evaluations_field_headers_async(): def test_list_evaluations_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6408,7 +6857,7 @@ def test_list_evaluations_flattened(): def test_list_evaluations_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6423,7 +6872,7 @@ def test_list_evaluations_flattened_error(): @pytest.mark.asyncio async def test_list_evaluations_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6452,7 +6901,7 @@ async def test_list_evaluations_flattened_async(): @pytest.mark.asyncio async def test_list_evaluations_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6466,7 +6915,7 @@ async def test_list_evaluations_flattened_error_async(): def test_list_evaluations_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6516,7 +6965,7 @@ def test_list_evaluations_pager(transport_name: str = "grpc"): def test_list_evaluations_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6558,7 +7007,7 @@ def test_list_evaluations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_evaluations_async_pager(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6608,7 +7057,7 @@ async def test_list_evaluations_async_pager(): @pytest.mark.asyncio async def test_list_evaluations_async_pages(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6663,7 +7112,7 @@ async def test_list_evaluations_async_pages(): ) def test_process_document_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6711,7 +7160,7 @@ def test_process_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).process_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6720,7 +7169,7 @@ def test_process_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).process_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6729,7 +7178,7 @@ def test_process_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6772,7 +7221,7 @@ def test_process_document_rest_required_fields( def test_process_document_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.process_document._get_unset_required_fields({}) @@ -6782,7 +7231,7 @@ def test_process_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_process_document_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -6840,7 +7289,7 @@ def test_process_document_rest_bad_request( transport: str = "rest", request_type=document_processor_service.ProcessRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6862,7 +7311,7 @@ def test_process_document_rest_bad_request( def test_process_document_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6906,7 +7355,7 @@ def test_process_document_rest_flattened(): def test_process_document_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6921,7 +7370,7 @@ def test_process_document_rest_flattened_error(transport: str = "rest"): def test_process_document_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6934,7 +7383,7 @@ def test_process_document_rest_error(): ) def test_batch_process_documents_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6980,7 +7429,7 @@ def test_batch_process_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_process_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6989,7 +7438,7 @@ def test_batch_process_documents_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_process_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6998,7 +7447,7 @@ def test_batch_process_documents_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7038,7 +7487,7 @@ def test_batch_process_documents_rest_required_fields( def test_batch_process_documents_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_process_documents._get_unset_required_fields({}) @@ -7048,7 +7497,7 @@ def test_batch_process_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_process_documents_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -7110,7 +7559,7 @@ def test_batch_process_documents_rest_bad_request( transport: str = "rest", request_type=document_processor_service.BatchProcessRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7132,7 +7581,7 @@ def test_batch_process_documents_rest_bad_request( def test_batch_process_documents_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7174,7 +7623,7 @@ def test_batch_process_documents_rest_flattened(): def test_batch_process_documents_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7189,7 +7638,7 @@ def test_batch_process_documents_rest_flattened_error(transport: str = "rest"): def test_batch_process_documents_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7202,7 +7651,7 @@ def test_batch_process_documents_rest_error(): ) def test_fetch_processor_types_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7252,7 +7701,7 @@ def test_fetch_processor_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).fetch_processor_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7261,7 +7710,7 @@ def test_fetch_processor_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).fetch_processor_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7270,7 +7719,7 @@ def test_fetch_processor_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7314,7 +7763,7 @@ def test_fetch_processor_types_rest_required_fields( def test_fetch_processor_types_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.fetch_processor_types._get_unset_required_fields({}) @@ -7324,7 +7773,7 @@ def test_fetch_processor_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_fetch_processor_types_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -7385,7 +7834,7 @@ def test_fetch_processor_types_rest_bad_request( request_type=document_processor_service.FetchProcessorTypesRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7407,7 +7856,7 @@ def test_fetch_processor_types_rest_bad_request( def test_fetch_processor_types_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7451,7 +7900,7 @@ def test_fetch_processor_types_rest_flattened(): def test_fetch_processor_types_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7466,7 +7915,7 @@ def test_fetch_processor_types_rest_flattened_error(transport: str = "rest"): def test_fetch_processor_types_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7479,7 +7928,7 @@ def test_fetch_processor_types_rest_error(): ) def test_list_processor_types_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7532,7 +7981,7 @@ def test_list_processor_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processor_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7541,7 +7990,7 @@ def test_list_processor_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processor_types._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7557,7 +8006,7 @@ def test_list_processor_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7601,7 +8050,7 @@ def test_list_processor_types_rest_required_fields( def test_list_processor_types_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_processor_types._get_unset_required_fields({}) @@ -7619,7 +8068,7 @@ def test_list_processor_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_processor_types_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -7680,7 +8129,7 @@ def test_list_processor_types_rest_bad_request( request_type=document_processor_service.ListProcessorTypesRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7702,7 +8151,7 @@ def test_list_processor_types_rest_bad_request( def test_list_processor_types_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7746,7 +8195,7 @@ def test_list_processor_types_rest_flattened(): def test_list_processor_types_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7761,7 +8210,7 @@ def test_list_processor_types_rest_flattened_error(transport: str = "rest"): def test_list_processor_types_rest_pager(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7832,7 +8281,7 @@ def test_list_processor_types_rest_pager(transport: str = "rest"): ) def test_get_processor_type_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7893,7 +8342,7 @@ def test_get_processor_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7902,7 +8351,7 @@ def test_get_processor_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7911,7 +8360,7 @@ def test_get_processor_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7953,7 +8402,7 @@ def test_get_processor_type_rest_required_fields( def test_get_processor_type_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_processor_type._get_unset_required_fields({}) @@ -7963,7 +8412,7 @@ def test_get_processor_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_processor_type_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -8022,7 +8471,7 @@ def test_get_processor_type_rest_bad_request( request_type=document_processor_service.GetProcessorTypeRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8044,7 +8493,7 @@ def test_get_processor_type_rest_bad_request( def test_get_processor_type_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8088,7 +8537,7 @@ def test_get_processor_type_rest_flattened(): def test_get_processor_type_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8103,7 +8552,7 @@ def test_get_processor_type_rest_flattened_error(transport: str = "rest"): def test_get_processor_type_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8116,7 +8565,7 @@ def test_get_processor_type_rest_error(): ) def test_list_processors_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8169,7 +8618,7 @@ def test_list_processors_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processors._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8178,7 +8627,7 @@ def test_list_processors_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processors._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8194,7 +8643,7 @@ def test_list_processors_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8238,7 +8687,7 @@ def test_list_processors_rest_required_fields( def test_list_processors_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_processors._get_unset_required_fields({}) @@ -8256,7 +8705,7 @@ def test_list_processors_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_processors_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -8317,7 +8766,7 @@ def test_list_processors_rest_bad_request( request_type=document_processor_service.ListProcessorsRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8339,7 +8788,7 @@ def test_list_processors_rest_bad_request( def test_list_processors_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8382,7 +8831,7 @@ def test_list_processors_rest_flattened(): def test_list_processors_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8397,7 +8846,7 @@ def test_list_processors_rest_flattened_error(transport: str = "rest"): def test_list_processors_rest_pager(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8468,7 +8917,7 @@ def test_list_processors_rest_pager(transport: str = "rest"): ) def test_get_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8531,7 +8980,7 @@ def test_get_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8540,7 +8989,7 @@ def test_get_processor_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8549,7 +8998,7 @@ def test_get_processor_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8591,7 +9040,7 @@ def test_get_processor_rest_required_fields( def test_get_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_processor._get_unset_required_fields({}) @@ -8601,7 +9050,7 @@ def test_get_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -8657,7 +9106,7 @@ def test_get_processor_rest_bad_request( transport: str = "rest", request_type=document_processor_service.GetProcessorRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8679,7 +9128,7 @@ def test_get_processor_rest_bad_request( def test_get_processor_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8722,7 +9171,7 @@ def test_get_processor_rest_flattened(): def test_get_processor_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8737,7 +9186,7 @@ def test_get_processor_rest_flattened_error(transport: str = "rest"): def test_get_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8750,7 +9199,7 @@ def test_get_processor_rest_error(): ) def test_train_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8796,7 +9245,7 @@ def test_train_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8805,7 +9254,7 @@ def test_train_processor_version_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8814,7 +9263,7 @@ def test_train_processor_version_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8854,7 +9303,7 @@ def test_train_processor_version_rest_required_fields( def test_train_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.train_processor_version._get_unset_required_fields({}) @@ -8872,7 +9321,7 @@ def test_train_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_train_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -8935,7 +9384,7 @@ def test_train_processor_version_rest_bad_request( request_type=document_processor_service.TrainProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8957,7 +9406,7 @@ def test_train_processor_version_rest_bad_request( def test_train_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9000,7 +9449,7 @@ def test_train_processor_version_rest_flattened(): def test_train_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9016,7 +9465,7 @@ def test_train_processor_version_rest_flattened_error(transport: str = "rest"): def test_train_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9029,7 +9478,7 @@ def test_train_processor_version_rest_error(): ) def test_get_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9092,7 +9541,7 @@ def test_get_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9101,7 +9550,7 @@ def test_get_processor_version_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9110,7 +9559,7 @@ def test_get_processor_version_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9152,7 +9601,7 @@ def test_get_processor_version_rest_required_fields( def test_get_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_processor_version._get_unset_required_fields({}) @@ -9162,7 +9611,7 @@ def test_get_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -9221,7 +9670,7 @@ def test_get_processor_version_rest_bad_request( request_type=document_processor_service.GetProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9245,7 +9694,7 @@ def test_get_processor_version_rest_bad_request( def test_get_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9289,7 +9738,7 @@ def test_get_processor_version_rest_flattened(): def test_get_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9304,7 +9753,7 @@ def test_get_processor_version_rest_flattened_error(transport: str = "rest"): def test_get_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9317,7 +9766,7 @@ def test_get_processor_version_rest_error(): ) def test_list_processor_versions_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9370,7 +9819,7 @@ def test_list_processor_versions_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processor_versions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9379,7 +9828,7 @@ def test_list_processor_versions_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processor_versions._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -9395,7 +9844,7 @@ def test_list_processor_versions_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9439,7 +9888,7 @@ def test_list_processor_versions_rest_required_fields( def test_list_processor_versions_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_processor_versions._get_unset_required_fields({}) @@ -9457,7 +9906,7 @@ def test_list_processor_versions_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_processor_versions_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -9520,7 +9969,7 @@ def test_list_processor_versions_rest_bad_request( request_type=document_processor_service.ListProcessorVersionsRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9542,7 +9991,7 @@ def test_list_processor_versions_rest_bad_request( def test_list_processor_versions_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9588,7 +10037,7 @@ def test_list_processor_versions_rest_flattened(): def test_list_processor_versions_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9603,7 +10052,7 @@ def test_list_processor_versions_rest_flattened_error(transport: str = "rest"): def test_list_processor_versions_rest_pager(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9676,7 +10125,7 @@ def test_list_processor_versions_rest_pager(transport: str = "rest"): ) def test_delete_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9724,7 +10173,7 @@ def test_delete_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9733,7 +10182,7 @@ def test_delete_processor_version_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9742,7 +10191,7 @@ def test_delete_processor_version_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9781,7 +10230,7 @@ def test_delete_processor_version_rest_required_fields( def test_delete_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_processor_version._get_unset_required_fields({}) @@ -9791,7 +10240,7 @@ def test_delete_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -9854,7 +10303,7 @@ def test_delete_processor_version_rest_bad_request( request_type=document_processor_service.DeleteProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9878,7 +10327,7 @@ def test_delete_processor_version_rest_bad_request( def test_delete_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9920,7 +10369,7 @@ def test_delete_processor_version_rest_flattened(): def test_delete_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9935,7 +10384,7 @@ def test_delete_processor_version_rest_flattened_error(transport: str = "rest"): def test_delete_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9948,7 +10397,7 @@ def test_delete_processor_version_rest_error(): ) def test_deploy_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9996,7 +10445,7 @@ def test_deploy_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).deploy_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10005,7 +10454,7 @@ def test_deploy_processor_version_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).deploy_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10014,7 +10463,7 @@ def test_deploy_processor_version_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10054,7 +10503,7 @@ def test_deploy_processor_version_rest_required_fields( def test_deploy_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.deploy_processor_version._get_unset_required_fields({}) @@ -10064,7 +10513,7 @@ def test_deploy_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_deploy_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -10127,7 +10576,7 @@ def test_deploy_processor_version_rest_bad_request( request_type=document_processor_service.DeployProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10151,7 +10600,7 @@ def test_deploy_processor_version_rest_bad_request( def test_deploy_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10193,7 +10642,7 @@ def test_deploy_processor_version_rest_flattened(): def test_deploy_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10208,7 +10657,7 @@ def test_deploy_processor_version_rest_flattened_error(transport: str = "rest"): def test_deploy_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10221,7 +10670,7 @@ def test_deploy_processor_version_rest_error(): ) def test_undeploy_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10269,7 +10718,7 @@ def test_undeploy_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).undeploy_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10278,7 +10727,7 @@ def test_undeploy_processor_version_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).undeploy_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10287,7 +10736,7 @@ def test_undeploy_processor_version_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10327,7 +10776,7 @@ def test_undeploy_processor_version_rest_required_fields( def test_undeploy_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.undeploy_processor_version._get_unset_required_fields({}) @@ -10337,7 +10786,7 @@ def test_undeploy_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_undeploy_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -10400,7 +10849,7 @@ def test_undeploy_processor_version_rest_bad_request( request_type=document_processor_service.UndeployProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10424,7 +10873,7 @@ def test_undeploy_processor_version_rest_bad_request( def test_undeploy_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10466,7 +10915,7 @@ def test_undeploy_processor_version_rest_flattened(): def test_undeploy_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10481,7 +10930,7 @@ def test_undeploy_processor_version_rest_flattened_error(transport: str = "rest" def test_undeploy_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10494,7 +10943,7 @@ def test_undeploy_processor_version_rest_error(): ) def test_create_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10639,7 +11088,7 @@ def test_create_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10648,7 +11097,7 @@ def test_create_processor_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10657,7 +11106,7 @@ def test_create_processor_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10700,7 +11149,7 @@ def test_create_processor_rest_required_fields( def test_create_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_processor._get_unset_required_fields({}) @@ -10718,7 +11167,7 @@ def test_create_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -10777,7 +11226,7 @@ def test_create_processor_rest_bad_request( request_type=document_processor_service.CreateProcessorRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10799,7 +11248,7 @@ def test_create_processor_rest_bad_request( def test_create_processor_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10841,7 +11290,7 @@ def test_create_processor_rest_flattened(): def test_create_processor_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10857,7 +11306,7 @@ def test_create_processor_rest_flattened_error(transport: str = "rest"): def test_create_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10870,7 +11319,7 @@ def test_create_processor_rest_error(): ) def test_delete_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10916,7 +11365,7 @@ def test_delete_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10925,7 +11374,7 @@ def test_delete_processor_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10934,7 +11383,7 @@ def test_delete_processor_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10973,7 +11422,7 @@ def test_delete_processor_rest_required_fields( def test_delete_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_processor._get_unset_required_fields({}) @@ -10983,7 +11432,7 @@ def test_delete_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -11044,7 +11493,7 @@ def test_delete_processor_rest_bad_request( request_type=document_processor_service.DeleteProcessorRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11066,7 +11515,7 @@ def test_delete_processor_rest_bad_request( def test_delete_processor_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11107,7 +11556,7 @@ def test_delete_processor_rest_flattened(): def test_delete_processor_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11122,7 +11571,7 @@ def test_delete_processor_rest_flattened_error(transport: str = "rest"): def test_delete_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11135,7 +11584,7 @@ def test_delete_processor_rest_error(): ) def test_enable_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11181,7 +11630,7 @@ def test_enable_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).enable_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11190,7 +11639,7 @@ def test_enable_processor_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).enable_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11199,7 +11648,7 @@ def test_enable_processor_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11239,7 +11688,7 @@ def test_enable_processor_rest_required_fields( def test_enable_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.enable_processor._get_unset_required_fields({}) @@ -11249,7 +11698,7 @@ def test_enable_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_enable_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -11310,7 +11759,7 @@ def test_enable_processor_rest_bad_request( request_type=document_processor_service.EnableProcessorRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11332,7 +11781,7 @@ def test_enable_processor_rest_bad_request( def test_enable_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11345,7 +11794,7 @@ def test_enable_processor_rest_error(): ) def test_disable_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11391,7 +11840,7 @@ def test_disable_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).disable_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11400,7 +11849,7 @@ def test_disable_processor_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).disable_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11409,7 +11858,7 @@ def test_disable_processor_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11449,7 +11898,7 @@ def test_disable_processor_rest_required_fields( def test_disable_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.disable_processor._get_unset_required_fields({}) @@ -11459,7 +11908,7 @@ def test_disable_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_disable_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -11520,7 +11969,7 @@ def test_disable_processor_rest_bad_request( request_type=document_processor_service.DisableProcessorRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11542,7 +11991,7 @@ def test_disable_processor_rest_bad_request( def test_disable_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11555,7 +12004,7 @@ def test_disable_processor_rest_error(): ) def test_set_default_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11604,7 +12053,7 @@ def test_set_default_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_default_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11614,7 +12063,7 @@ def test_set_default_processor_version_rest_required_fields( jsonified_request["defaultProcessorVersion"] = "default_processor_version_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_default_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11628,7 +12077,7 @@ def test_set_default_processor_version_rest_required_fields( ) client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11668,7 +12117,7 @@ def test_set_default_processor_version_rest_required_fields( def test_set_default_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.set_default_processor_version._get_unset_required_fields( @@ -11688,7 +12137,7 @@ def test_set_default_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_set_default_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -11751,7 +12200,7 @@ def test_set_default_processor_version_rest_bad_request( request_type=document_processor_service.SetDefaultProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11775,7 +12224,7 @@ def test_set_default_processor_version_rest_bad_request( def test_set_default_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11788,7 +12237,7 @@ def test_set_default_processor_version_rest_error(): ) def test_review_document_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11836,7 +12285,7 @@ def test_review_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).review_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11845,7 +12294,7 @@ def test_review_document_rest_required_fields( jsonified_request["humanReviewConfig"] = "human_review_config_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).review_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11854,7 +12303,7 @@ def test_review_document_rest_required_fields( assert jsonified_request["humanReviewConfig"] == "human_review_config_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11894,7 +12343,7 @@ def test_review_document_rest_required_fields( def test_review_document_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.review_document._get_unset_required_fields({}) @@ -11904,7 +12353,7 @@ def test_review_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_review_document_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -11965,7 +12414,7 @@ def test_review_document_rest_bad_request( request_type=document_processor_service.ReviewDocumentRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11989,7 +12438,7 @@ def test_review_document_rest_bad_request( def test_review_document_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12031,7 +12480,7 @@ def test_review_document_rest_flattened(): def test_review_document_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12046,7 +12495,7 @@ def test_review_document_rest_flattened_error(transport: str = "rest"): def test_review_document_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12059,7 +12508,7 @@ def test_review_document_rest_error(): ) def test_evaluate_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12107,7 +12556,7 @@ def test_evaluate_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).evaluate_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12116,7 +12565,7 @@ def test_evaluate_processor_version_rest_required_fields( jsonified_request["processorVersion"] = "processor_version_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).evaluate_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12125,7 +12574,7 @@ def test_evaluate_processor_version_rest_required_fields( assert jsonified_request["processorVersion"] == "processor_version_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12165,7 +12614,7 @@ def test_evaluate_processor_version_rest_required_fields( def test_evaluate_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.evaluate_processor_version._get_unset_required_fields({}) @@ -12175,7 +12624,7 @@ def test_evaluate_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_evaluate_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -12238,7 +12687,7 @@ def test_evaluate_processor_version_rest_bad_request( request_type=document_processor_service.EvaluateProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12262,7 +12711,7 @@ def test_evaluate_processor_version_rest_bad_request( def test_evaluate_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12304,7 +12753,7 @@ def test_evaluate_processor_version_rest_flattened(): def test_evaluate_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12319,7 +12768,7 @@ def test_evaluate_processor_version_rest_flattened_error(transport: str = "rest" def test_evaluate_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12332,7 +12781,7 @@ def test_evaluate_processor_version_rest_error(): ) def test_get_evaluation_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12389,7 +12838,7 @@ def test_get_evaluation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_evaluation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12398,7 +12847,7 @@ def test_get_evaluation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_evaluation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12407,7 +12856,7 @@ def test_get_evaluation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12449,7 +12898,7 @@ def test_get_evaluation_rest_required_fields( def test_get_evaluation_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_evaluation._get_unset_required_fields({}) @@ -12459,7 +12908,7 @@ def test_get_evaluation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_evaluation_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -12518,7 +12967,7 @@ def test_get_evaluation_rest_bad_request( request_type=document_processor_service.GetEvaluationRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12542,7 +12991,7 @@ def test_get_evaluation_rest_bad_request( def test_get_evaluation_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12586,7 +13035,7 @@ def test_get_evaluation_rest_flattened(): def test_get_evaluation_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12601,7 +13050,7 @@ def test_get_evaluation_rest_flattened_error(transport: str = "rest"): def test_get_evaluation_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12614,7 +13063,7 @@ def test_get_evaluation_rest_error(): ) def test_list_evaluations_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12669,7 +13118,7 @@ def test_list_evaluations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_evaluations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12678,7 +13127,7 @@ def test_list_evaluations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_evaluations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -12694,7 +13143,7 @@ def test_list_evaluations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12738,7 +13187,7 @@ def test_list_evaluations_rest_required_fields( def test_list_evaluations_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_evaluations._get_unset_required_fields({}) @@ -12756,7 +13205,7 @@ def test_list_evaluations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_evaluations_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -12817,7 +13266,7 @@ def test_list_evaluations_rest_bad_request( request_type=document_processor_service.ListEvaluationsRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12841,7 +13290,7 @@ def test_list_evaluations_rest_bad_request( def test_list_evaluations_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12887,7 +13336,7 @@ def test_list_evaluations_rest_flattened(): def test_list_evaluations_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12902,7 +13351,7 @@ def test_list_evaluations_rest_flattened_error(transport: str = "rest"): def test_list_evaluations_rest_pager(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12969,17 +13418,17 @@ def test_list_evaluations_rest_pager(transport: str = "rest"): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( @@ -12989,7 +13438,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -13000,16 +13449,17 @@ 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 = DocumentProcessorServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( @@ -13021,7 +13471,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DocumentProcessorServiceClient(transport=transport) assert client.transport is transport @@ -13030,13 +13480,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -13053,7 +13503,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -13067,7 +13517,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DocumentProcessorServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -13075,7 +13525,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -13087,7 +13537,7 @@ def test_document_processor_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DocumentProcessorServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -13099,7 +13549,7 @@ def test_document_processor_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DocumentProcessorServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -13162,7 +13612,7 @@ def test_document_processor_service_base_transport_with_credentials_file(): "google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentProcessorServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -13181,7 +13631,7 @@ def test_document_processor_service_base_transport_with_adc(): "google.cloud.documentai_v1.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentProcessorServiceTransport() adc.assert_called_once() @@ -13189,7 +13639,7 @@ def test_document_processor_service_base_transport_with_adc(): def test_document_processor_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DocumentProcessorServiceClient() adc.assert_called_once_with( scopes=None, @@ -13209,7 +13659,7 @@ def test_document_processor_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -13258,7 +13708,7 @@ def test_document_processor_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -13288,7 +13738,7 @@ def test_document_processor_service_transport_create_channel( def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -13326,7 +13776,7 @@ def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( def test_document_processor_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -13338,7 +13788,7 @@ def test_document_processor_service_http_transport_client_cert_source_for_mtls() def test_document_processor_service_rest_lro_client(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -13363,7 +13813,7 @@ def test_document_processor_service_rest_lro_client(): ) def test_document_processor_service_host_no_port(transport_name): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com" ), @@ -13386,7 +13836,7 @@ def test_document_processor_service_host_no_port(transport_name): ) def test_document_processor_service_host_with_port(transport_name): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com:8000" ), @@ -13406,8 +13856,8 @@ def test_document_processor_service_host_with_port(transport_name): ], ) def test_document_processor_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DocumentProcessorServiceClient( credentials=creds1, transport=transport_name, @@ -13534,7 +13984,7 @@ def test_document_processor_service_transport_channel_mtls_with_client_cert_sour mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -13612,7 +14062,7 @@ def test_document_processor_service_transport_channel_mtls_with_adc(transport_cl def test_document_processor_service_grpc_lro_client(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -13629,7 +14079,7 @@ def test_document_processor_service_grpc_lro_client(): def test_document_processor_service_grpc_lro_async_client(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -13901,7 +14351,7 @@ def test_client_with_default_client_info(): transports.DocumentProcessorServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -13911,7 +14361,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentProcessorServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -13920,7 +14370,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -13935,7 +14385,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13965,7 +14415,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -13993,7 +14443,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14021,7 +14471,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -14049,7 +14499,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14079,7 +14529,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -14107,7 +14557,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14137,7 +14587,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/operations/sample2"} @@ -14165,7 +14615,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14195,7 +14645,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations"} @@ -14221,7 +14671,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14246,7 +14696,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14270,7 +14720,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14299,7 +14749,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14326,7 +14776,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -14344,7 +14794,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -14360,7 +14810,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14385,7 +14835,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14411,7 +14861,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14440,7 +14890,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14469,7 +14919,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -14487,7 +14937,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -14505,7 +14955,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14530,7 +14980,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14556,7 +15006,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14585,7 +15035,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14614,7 +15064,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -14632,7 +15082,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -14650,7 +15100,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14675,7 +15125,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14701,7 +15151,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14730,7 +15180,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14759,7 +15209,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -14777,7 +15227,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -14795,7 +15245,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14820,7 +15270,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14846,7 +15296,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14875,7 +15325,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14904,7 +15354,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -14922,7 +15372,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -14946,7 +15396,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -14963,7 +15413,7 @@ def test_client_ctx(): ] for transport in transports: client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -15000,7 +15450,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, diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py index a8572ecc92ed..60bc8ecf3c07 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta2/test_document_understanding_service.py @@ -33,7 +33,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -76,6 +76,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -108,6 +131,294 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert DocumentUnderstandingServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DocumentUnderstandingServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DocumentUnderstandingServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DocumentUnderstandingServiceClient._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 DocumentUnderstandingServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DocumentUnderstandingServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DocumentUnderstandingServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentUnderstandingServiceClient._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 DocumentUnderstandingServiceClient._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 ( + DocumentUnderstandingServiceClient._get_client_cert_source(None, False) is None + ) + assert ( + DocumentUnderstandingServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + DocumentUnderstandingServiceClient._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 ( + DocumentUnderstandingServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DocumentUnderstandingServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DocumentUnderstandingServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentUnderstandingServiceClient), +) +@mock.patch.object( + DocumentUnderstandingServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentUnderstandingServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DocumentUnderstandingServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + DocumentUnderstandingServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ( + DocumentUnderstandingServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + ) + + assert ( + DocumentUnderstandingServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DocumentUnderstandingServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DocumentUnderstandingServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentUnderstandingServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + DocumentUnderstandingServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == DocumentUnderstandingServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentUnderstandingServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DocumentUnderstandingServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentUnderstandingServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + DocumentUnderstandingServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentUnderstandingServiceClient._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 ( + DocumentUnderstandingServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DocumentUnderstandingServiceClient._get_universe_domain( + None, universe_domain_env + ) + == universe_domain_env + ) + assert ( + DocumentUnderstandingServiceClient._get_universe_domain(None, None) + == DocumentUnderstandingServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DocumentUnderstandingServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + DocumentUnderstandingServiceClient, + transports.DocumentUnderstandingServiceGrpcTransport, + "grpc", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -118,7 +429,7 @@ def test__get_default_mtls_endpoint(): def test_document_understanding_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -166,7 +477,7 @@ def test_document_understanding_service_client_service_account_always_use_jwt( def test_document_understanding_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -214,13 +525,13 @@ def test_document_understanding_service_client_get_transport_class(): ) @mock.patch.object( DocumentUnderstandingServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentUnderstandingServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentUnderstandingServiceClient), ) @mock.patch.object( DocumentUnderstandingServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentUnderstandingServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentUnderstandingServiceAsyncClient), ) def test_document_understanding_service_client_client_options( client_class, transport_class, transport_name @@ -229,7 +540,9 @@ def test_document_understanding_service_client_client_options( with mock.patch.object( DocumentUnderstandingServiceClient, "get_transport_class" ) as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -266,7 +579,9 @@ def test_document_understanding_service_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, @@ -296,15 +611,23 @@ def test_document_understanding_service_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") @@ -314,7 +637,9 @@ def test_document_understanding_service_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", @@ -332,7 +657,9 @@ def test_document_understanding_service_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, @@ -373,13 +700,13 @@ def test_document_understanding_service_client_client_options( ) @mock.patch.object( DocumentUnderstandingServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentUnderstandingServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentUnderstandingServiceClient), ) @mock.patch.object( DocumentUnderstandingServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentUnderstandingServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentUnderstandingServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_document_understanding_service_client_mtls_env_auto( @@ -402,7 +729,9 @@ def test_document_understanding_service_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 @@ -434,7 +763,9 @@ def test_document_understanding_service_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 @@ -468,7 +799,9 @@ def test_document_understanding_service_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, @@ -561,6 +894,123 @@ def test_document_understanding_service_client_get_mtls_endpoint_and_cert_source 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", + [DocumentUnderstandingServiceClient, DocumentUnderstandingServiceAsyncClient], +) +@mock.patch.object( + DocumentUnderstandingServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentUnderstandingServiceClient), +) +@mock.patch.object( + DocumentUnderstandingServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentUnderstandingServiceAsyncClient), +) +def test_document_understanding_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DocumentUnderstandingServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + DocumentUnderstandingServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ( + DocumentUnderstandingServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -590,7 +1040,9 @@ def test_document_understanding_service_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, @@ -629,7 +1081,9 @@ def test_document_understanding_service_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, @@ -689,7 +1143,9 @@ def test_document_understanding_service_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, @@ -706,8 +1162,8 @@ def test_document_understanding_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -736,7 +1192,7 @@ def test_document_understanding_service_client_create_channel_credentials_file( ) def test_batch_process_documents(request_type, transport: str = "grpc"): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -765,7 +1221,7 @@ def test_batch_process_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -785,7 +1241,7 @@ async def test_batch_process_documents_async( request_type=document_understanding.BatchProcessDocumentsRequest, ): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -819,7 +1275,7 @@ async def test_batch_process_documents_async_from_dict(): def test_batch_process_documents_field_headers(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -851,7 +1307,7 @@ def test_batch_process_documents_field_headers(): @pytest.mark.asyncio async def test_batch_process_documents_field_headers_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -884,7 +1340,7 @@ async def test_batch_process_documents_field_headers_async(): def test_batch_process_documents_flattened(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -914,7 +1370,7 @@ def test_batch_process_documents_flattened(): def test_batch_process_documents_flattened_error(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -931,7 +1387,7 @@ def test_batch_process_documents_flattened_error(): @pytest.mark.asyncio async def test_batch_process_documents_flattened_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -966,7 +1422,7 @@ async def test_batch_process_documents_flattened_async(): @pytest.mark.asyncio async def test_batch_process_documents_flattened_error_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -989,7 +1445,7 @@ async def test_batch_process_documents_flattened_error_async(): ) def test_process_document(request_type, transport: str = "grpc"): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1022,7 +1478,7 @@ def test_process_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1040,7 +1496,7 @@ async def test_process_document_async( request_type=document_understanding.ProcessDocumentRequest, ): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1077,7 +1533,7 @@ async def test_process_document_async_from_dict(): def test_process_document_field_headers(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1107,7 +1563,7 @@ def test_process_document_field_headers(): @pytest.mark.asyncio async def test_process_document_field_headers_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1137,17 +1593,17 @@ async def test_process_document_field_headers_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentUnderstandingServiceClient( @@ -1157,7 +1613,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1168,16 +1624,17 @@ 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 = DocumentUnderstandingServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentUnderstandingServiceClient( @@ -1189,7 +1646,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DocumentUnderstandingServiceClient(transport=transport) assert client.transport is transport @@ -1198,13 +1655,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentUnderstandingServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DocumentUnderstandingServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1220,7 +1677,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1233,7 +1690,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DocumentUnderstandingServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1241,7 +1698,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1253,7 +1710,7 @@ def test_document_understanding_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DocumentUnderstandingServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1265,7 +1722,7 @@ def test_document_understanding_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DocumentUnderstandingServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1308,7 +1765,7 @@ def test_document_understanding_service_base_transport_with_credentials_file(): "google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentUnderstandingServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1327,7 +1784,7 @@ def test_document_understanding_service_base_transport_with_adc(): "google.cloud.documentai_v1beta2.services.document_understanding_service.transports.DocumentUnderstandingServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentUnderstandingServiceTransport() adc.assert_called_once() @@ -1335,7 +1792,7 @@ def test_document_understanding_service_base_transport_with_adc(): def test_document_understanding_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DocumentUnderstandingServiceClient() adc.assert_called_once_with( scopes=None, @@ -1355,7 +1812,7 @@ def test_document_understanding_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1408,7 +1865,7 @@ def test_document_understanding_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1438,7 +1895,7 @@ def test_document_understanding_service_transport_create_channel( def test_document_understanding_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1484,7 +1941,7 @@ def test_document_understanding_service_grpc_transport_client_cert_source_for_mt ) def test_document_understanding_service_host_no_port(transport_name): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com" ), @@ -1502,7 +1959,7 @@ def test_document_understanding_service_host_no_port(transport_name): ) def test_document_understanding_service_host_with_port(transport_name): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com:8000" ), @@ -1561,7 +2018,7 @@ def test_document_understanding_service_transport_channel_mtls_with_client_cert_ mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -1641,7 +2098,7 @@ def test_document_understanding_service_transport_channel_mtls_with_adc( def test_document_understanding_service_grpc_lro_client(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -1658,7 +2115,7 @@ def test_document_understanding_service_grpc_lro_client(): def test_document_understanding_service_grpc_lro_async_client(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -1785,7 +2242,7 @@ def test_client_with_default_client_info(): transports.DocumentUnderstandingServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1795,7 +2252,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentUnderstandingServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1804,7 +2261,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -1817,7 +2274,7 @@ async def test_transport_close_async(): def test_cancel_operation(transport: str = "grpc"): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1842,7 +2299,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1866,7 +2323,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1895,7 +2352,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1922,7 +2379,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -1940,7 +2397,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -1956,7 +2413,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1981,7 +2438,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2007,7 +2464,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2036,7 +2493,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2065,7 +2522,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2083,7 +2540,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2101,7 +2558,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2126,7 +2583,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2152,7 +2609,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2181,7 +2638,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2210,7 +2667,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2228,7 +2685,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -2246,7 +2703,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2271,7 +2728,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2297,7 +2754,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2326,7 +2783,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2355,7 +2812,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -2373,7 +2830,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -2391,7 +2848,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2416,7 +2873,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2442,7 +2899,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2471,7 +2928,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2500,7 +2957,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -2518,7 +2975,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = DocumentUnderstandingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -2541,7 +2998,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2557,7 +3014,7 @@ def test_client_ctx(): ] for transport in transports: client = DocumentUnderstandingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2594,7 +3051,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, diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py index 85d498897910..7363b47d17f1 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_processor_service.py @@ -36,7 +36,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -101,6 +101,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -131,6 +154,291 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DocumentProcessorServiceClient._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 DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DocumentProcessorServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentProcessorServiceClient._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 DocumentProcessorServiceClient._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 DocumentProcessorServiceClient._get_client_cert_source(None, False) is None + assert ( + DocumentProcessorServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + DocumentProcessorServiceClient._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 ( + DocumentProcessorServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DocumentProcessorServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DocumentProcessorServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceClient), +) +@mock.patch.object( + DocumentProcessorServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DocumentProcessorServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentProcessorServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentProcessorServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DocumentProcessorServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + DocumentProcessorServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentProcessorServiceClient._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 ( + DocumentProcessorServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DocumentProcessorServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DocumentProcessorServiceClient._get_universe_domain(None, None) + == DocumentProcessorServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DocumentProcessorServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + DocumentProcessorServiceClient, + transports.DocumentProcessorServiceGrpcTransport, + "grpc", + ), + ( + DocumentProcessorServiceClient, + transports.DocumentProcessorServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -142,7 +450,7 @@ def test__get_default_mtls_endpoint(): def test_document_processor_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -196,7 +504,7 @@ def test_document_processor_service_client_service_account_always_use_jwt( def test_document_processor_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -254,13 +562,13 @@ def test_document_processor_service_client_get_transport_class(): ) @mock.patch.object( DocumentProcessorServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentProcessorServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceClient), ) @mock.patch.object( DocumentProcessorServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentProcessorServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceAsyncClient), ) def test_document_processor_service_client_client_options( client_class, transport_class, transport_name @@ -269,7 +577,9 @@ def test_document_processor_service_client_client_options( with mock.patch.object( DocumentProcessorServiceClient, "get_transport_class" ) as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -306,7 +616,9 @@ def test_document_processor_service_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, @@ -336,15 +648,23 @@ def test_document_processor_service_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") @@ -354,7 +674,9 @@ def test_document_processor_service_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", @@ -372,7 +694,9 @@ def test_document_processor_service_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, @@ -425,13 +749,13 @@ def test_document_processor_service_client_client_options( ) @mock.patch.object( DocumentProcessorServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentProcessorServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceClient), ) @mock.patch.object( DocumentProcessorServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentProcessorServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_document_processor_service_client_mtls_env_auto( @@ -454,7 +778,9 @@ def test_document_processor_service_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 @@ -486,7 +812,9 @@ def test_document_processor_service_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 @@ -520,7 +848,9 @@ def test_document_processor_service_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, @@ -613,6 +943,119 @@ def test_document_processor_service_client_get_mtls_endpoint_and_cert_source( 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", + [DocumentProcessorServiceClient, DocumentProcessorServiceAsyncClient], +) +@mock.patch.object( + DocumentProcessorServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceClient), +) +@mock.patch.object( + DocumentProcessorServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentProcessorServiceAsyncClient), +) +def test_document_processor_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DocumentProcessorServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentProcessorServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentProcessorServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -647,7 +1090,9 @@ def test_document_processor_service_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, @@ -692,7 +1137,9 @@ def test_document_processor_service_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, @@ -752,7 +1199,9 @@ def test_document_processor_service_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, @@ -769,8 +1218,8 @@ def test_document_processor_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -799,7 +1248,7 @@ def test_document_processor_service_client_create_channel_credentials_file( ) def test_process_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -829,7 +1278,7 @@ def test_process_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -847,7 +1296,7 @@ async def test_process_document_async( request_type=document_processor_service.ProcessRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -882,7 +1331,7 @@ async def test_process_document_async_from_dict(): def test_process_document_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -912,7 +1361,7 @@ def test_process_document_field_headers(): @pytest.mark.asyncio async def test_process_document_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -943,7 +1392,7 @@ async def test_process_document_field_headers_async(): def test_process_document_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -967,7 +1416,7 @@ def test_process_document_flattened(): def test_process_document_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -982,7 +1431,7 @@ def test_process_document_flattened_error(): @pytest.mark.asyncio async def test_process_document_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1011,7 +1460,7 @@ async def test_process_document_flattened_async(): @pytest.mark.asyncio async def test_process_document_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1032,7 +1481,7 @@ async def test_process_document_flattened_error_async(): ) def test_batch_process_documents(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1061,7 +1510,7 @@ def test_batch_process_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1081,7 +1530,7 @@ async def test_batch_process_documents_async( request_type=document_processor_service.BatchProcessRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1115,7 +1564,7 @@ async def test_batch_process_documents_async_from_dict(): def test_batch_process_documents_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1147,7 +1596,7 @@ def test_batch_process_documents_field_headers(): @pytest.mark.asyncio async def test_batch_process_documents_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1180,7 +1629,7 @@ async def test_batch_process_documents_field_headers_async(): def test_batch_process_documents_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1206,7 +1655,7 @@ def test_batch_process_documents_flattened(): def test_batch_process_documents_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1221,7 +1670,7 @@ def test_batch_process_documents_flattened_error(): @pytest.mark.asyncio async def test_batch_process_documents_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1252,7 +1701,7 @@ async def test_batch_process_documents_flattened_async(): @pytest.mark.asyncio async def test_batch_process_documents_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1273,7 +1722,7 @@ async def test_batch_process_documents_flattened_error_async(): ) def test_fetch_processor_types(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1302,7 +1751,7 @@ def test_fetch_processor_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1322,7 +1771,7 @@ async def test_fetch_processor_types_async( request_type=document_processor_service.FetchProcessorTypesRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1356,7 +1805,7 @@ async def test_fetch_processor_types_async_from_dict(): def test_fetch_processor_types_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1388,7 +1837,7 @@ def test_fetch_processor_types_field_headers(): @pytest.mark.asyncio async def test_fetch_processor_types_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1421,7 +1870,7 @@ async def test_fetch_processor_types_field_headers_async(): def test_fetch_processor_types_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1447,7 +1896,7 @@ def test_fetch_processor_types_flattened(): def test_fetch_processor_types_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1462,7 +1911,7 @@ def test_fetch_processor_types_flattened_error(): @pytest.mark.asyncio async def test_fetch_processor_types_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1493,7 +1942,7 @@ async def test_fetch_processor_types_flattened_async(): @pytest.mark.asyncio async def test_fetch_processor_types_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1514,7 +1963,7 @@ async def test_fetch_processor_types_flattened_error_async(): ) def test_list_processor_types(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1546,7 +1995,7 @@ def test_list_processor_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1566,7 +2015,7 @@ async def test_list_processor_types_async( request_type=document_processor_service.ListProcessorTypesRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1603,7 +2052,7 @@ async def test_list_processor_types_async_from_dict(): def test_list_processor_types_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1635,7 +2084,7 @@ def test_list_processor_types_field_headers(): @pytest.mark.asyncio async def test_list_processor_types_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1668,7 +2117,7 @@ async def test_list_processor_types_field_headers_async(): def test_list_processor_types_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1694,7 +2143,7 @@ def test_list_processor_types_flattened(): def test_list_processor_types_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1709,7 +2158,7 @@ def test_list_processor_types_flattened_error(): @pytest.mark.asyncio async def test_list_processor_types_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1740,7 +2189,7 @@ async def test_list_processor_types_flattened_async(): @pytest.mark.asyncio async def test_list_processor_types_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1754,7 +2203,7 @@ async def test_list_processor_types_flattened_error_async(): def test_list_processor_types_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1806,7 +2255,7 @@ def test_list_processor_types_pager(transport_name: str = "grpc"): def test_list_processor_types_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1850,7 +2299,7 @@ def test_list_processor_types_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_processor_types_async_pager(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1902,7 +2351,7 @@ async def test_list_processor_types_async_pager(): @pytest.mark.asyncio async def test_list_processor_types_async_pages(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1959,7 +2408,7 @@ async def test_list_processor_types_async_pages(): ) def test_get_processor_type(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2001,7 +2450,7 @@ def test_get_processor_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2021,7 +2470,7 @@ async def test_get_processor_type_async( request_type=document_processor_service.GetProcessorTypeRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2068,7 +2517,7 @@ async def test_get_processor_type_async_from_dict(): def test_get_processor_type_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2100,7 +2549,7 @@ def test_get_processor_type_field_headers(): @pytest.mark.asyncio async def test_get_processor_type_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2133,7 +2582,7 @@ async def test_get_processor_type_field_headers_async(): def test_get_processor_type_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2159,7 +2608,7 @@ def test_get_processor_type_flattened(): def test_get_processor_type_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2174,7 +2623,7 @@ def test_get_processor_type_flattened_error(): @pytest.mark.asyncio async def test_get_processor_type_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2205,7 +2654,7 @@ async def test_get_processor_type_flattened_async(): @pytest.mark.asyncio async def test_get_processor_type_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2226,7 +2675,7 @@ async def test_get_processor_type_flattened_error_async(): ) def test_list_processors(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2256,7 +2705,7 @@ def test_list_processors_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2274,7 +2723,7 @@ async def test_list_processors_async( request_type=document_processor_service.ListProcessorsRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2309,7 +2758,7 @@ async def test_list_processors_async_from_dict(): def test_list_processors_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2339,7 +2788,7 @@ def test_list_processors_field_headers(): @pytest.mark.asyncio async def test_list_processors_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2370,7 +2819,7 @@ async def test_list_processors_field_headers_async(): def test_list_processors_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2394,7 +2843,7 @@ def test_list_processors_flattened(): def test_list_processors_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2409,7 +2858,7 @@ def test_list_processors_flattened_error(): @pytest.mark.asyncio async def test_list_processors_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2438,7 +2887,7 @@ async def test_list_processors_flattened_async(): @pytest.mark.asyncio async def test_list_processors_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2452,7 +2901,7 @@ async def test_list_processors_flattened_error_async(): def test_list_processors_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2502,7 +2951,7 @@ def test_list_processors_pager(transport_name: str = "grpc"): def test_list_processors_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2544,7 +2993,7 @@ def test_list_processors_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_processors_async_pager(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2594,7 +3043,7 @@ async def test_list_processors_async_pager(): @pytest.mark.asyncio async def test_list_processors_async_pages(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2649,7 +3098,7 @@ async def test_list_processors_async_pages(): ) def test_get_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2691,7 +3140,7 @@ def test_get_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2709,7 +3158,7 @@ async def test_get_processor_async( request_type=document_processor_service.GetProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2756,7 +3205,7 @@ async def test_get_processor_async_from_dict(): def test_get_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2786,7 +3235,7 @@ def test_get_processor_field_headers(): @pytest.mark.asyncio async def test_get_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2815,7 +3264,7 @@ async def test_get_processor_field_headers_async(): def test_get_processor_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2839,7 +3288,7 @@ def test_get_processor_flattened(): def test_get_processor_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2854,7 +3303,7 @@ def test_get_processor_flattened_error(): @pytest.mark.asyncio async def test_get_processor_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2881,7 +3330,7 @@ async def test_get_processor_flattened_async(): @pytest.mark.asyncio async def test_get_processor_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2902,7 +3351,7 @@ async def test_get_processor_flattened_error_async(): ) def test_train_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2931,7 +3380,7 @@ def test_train_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2951,7 +3400,7 @@ async def test_train_processor_version_async( request_type=document_processor_service.TrainProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2985,7 +3434,7 @@ async def test_train_processor_version_async_from_dict(): def test_train_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3017,7 +3466,7 @@ def test_train_processor_version_field_headers(): @pytest.mark.asyncio async def test_train_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3050,7 +3499,7 @@ async def test_train_processor_version_field_headers_async(): def test_train_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3080,7 +3529,7 @@ def test_train_processor_version_flattened(): def test_train_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3096,7 +3545,7 @@ def test_train_processor_version_flattened_error(): @pytest.mark.asyncio async def test_train_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3131,7 +3580,7 @@ async def test_train_processor_version_flattened_async(): @pytest.mark.asyncio async def test_train_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3153,7 +3602,7 @@ async def test_train_processor_version_flattened_error_async(): ) def test_get_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3195,7 +3644,7 @@ def test_get_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3215,7 +3664,7 @@ async def test_get_processor_version_async( request_type=document_processor_service.GetProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3262,7 +3711,7 @@ async def test_get_processor_version_async_from_dict(): def test_get_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3294,7 +3743,7 @@ def test_get_processor_version_field_headers(): @pytest.mark.asyncio async def test_get_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3327,7 +3776,7 @@ async def test_get_processor_version_field_headers_async(): def test_get_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3353,7 +3802,7 @@ def test_get_processor_version_flattened(): def test_get_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3368,7 +3817,7 @@ def test_get_processor_version_flattened_error(): @pytest.mark.asyncio async def test_get_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3399,7 +3848,7 @@ async def test_get_processor_version_flattened_async(): @pytest.mark.asyncio async def test_get_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3420,7 +3869,7 @@ async def test_get_processor_version_flattened_error_async(): ) def test_list_processor_versions(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3452,7 +3901,7 @@ def test_list_processor_versions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3472,7 +3921,7 @@ async def test_list_processor_versions_async( request_type=document_processor_service.ListProcessorVersionsRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3509,7 +3958,7 @@ async def test_list_processor_versions_async_from_dict(): def test_list_processor_versions_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3541,7 +3990,7 @@ def test_list_processor_versions_field_headers(): @pytest.mark.asyncio async def test_list_processor_versions_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3574,7 +4023,7 @@ async def test_list_processor_versions_field_headers_async(): def test_list_processor_versions_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3600,7 +4049,7 @@ def test_list_processor_versions_flattened(): def test_list_processor_versions_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3615,7 +4064,7 @@ def test_list_processor_versions_flattened_error(): @pytest.mark.asyncio async def test_list_processor_versions_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3646,7 +4095,7 @@ async def test_list_processor_versions_flattened_async(): @pytest.mark.asyncio async def test_list_processor_versions_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3660,7 +4109,7 @@ async def test_list_processor_versions_flattened_error_async(): def test_list_processor_versions_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3712,7 +4161,7 @@ def test_list_processor_versions_pager(transport_name: str = "grpc"): def test_list_processor_versions_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3756,7 +4205,7 @@ def test_list_processor_versions_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_processor_versions_async_pager(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3808,7 +4257,7 @@ async def test_list_processor_versions_async_pager(): @pytest.mark.asyncio async def test_list_processor_versions_async_pages(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3865,7 +4314,7 @@ async def test_list_processor_versions_async_pages(): ) def test_delete_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3894,7 +4343,7 @@ def test_delete_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3914,7 +4363,7 @@ async def test_delete_processor_version_async( request_type=document_processor_service.DeleteProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3948,7 +4397,7 @@ async def test_delete_processor_version_async_from_dict(): def test_delete_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3980,7 +4429,7 @@ def test_delete_processor_version_field_headers(): @pytest.mark.asyncio async def test_delete_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4013,7 +4462,7 @@ async def test_delete_processor_version_field_headers_async(): def test_delete_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4039,7 +4488,7 @@ def test_delete_processor_version_flattened(): def test_delete_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4054,7 +4503,7 @@ def test_delete_processor_version_flattened_error(): @pytest.mark.asyncio async def test_delete_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4085,7 +4534,7 @@ async def test_delete_processor_version_flattened_async(): @pytest.mark.asyncio async def test_delete_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4106,7 +4555,7 @@ async def test_delete_processor_version_flattened_error_async(): ) def test_deploy_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4135,7 +4584,7 @@ def test_deploy_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4155,7 +4604,7 @@ async def test_deploy_processor_version_async( request_type=document_processor_service.DeployProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4189,7 +4638,7 @@ async def test_deploy_processor_version_async_from_dict(): def test_deploy_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4221,7 +4670,7 @@ def test_deploy_processor_version_field_headers(): @pytest.mark.asyncio async def test_deploy_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4254,7 +4703,7 @@ async def test_deploy_processor_version_field_headers_async(): def test_deploy_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4280,7 +4729,7 @@ def test_deploy_processor_version_flattened(): def test_deploy_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4295,7 +4744,7 @@ def test_deploy_processor_version_flattened_error(): @pytest.mark.asyncio async def test_deploy_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4326,7 +4775,7 @@ async def test_deploy_processor_version_flattened_async(): @pytest.mark.asyncio async def test_deploy_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4347,7 +4796,7 @@ async def test_deploy_processor_version_flattened_error_async(): ) def test_undeploy_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4376,7 +4825,7 @@ def test_undeploy_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4396,7 +4845,7 @@ async def test_undeploy_processor_version_async( request_type=document_processor_service.UndeployProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4430,7 +4879,7 @@ async def test_undeploy_processor_version_async_from_dict(): def test_undeploy_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4462,7 +4911,7 @@ def test_undeploy_processor_version_field_headers(): @pytest.mark.asyncio async def test_undeploy_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4495,7 +4944,7 @@ async def test_undeploy_processor_version_field_headers_async(): def test_undeploy_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4521,7 +4970,7 @@ def test_undeploy_processor_version_flattened(): def test_undeploy_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4536,7 +4985,7 @@ def test_undeploy_processor_version_flattened_error(): @pytest.mark.asyncio async def test_undeploy_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4567,7 +5016,7 @@ async def test_undeploy_processor_version_flattened_async(): @pytest.mark.asyncio async def test_undeploy_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4588,7 +5037,7 @@ async def test_undeploy_processor_version_flattened_error_async(): ) def test_create_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4630,7 +5079,7 @@ def test_create_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4648,7 +5097,7 @@ async def test_create_processor_async( request_type=document_processor_service.CreateProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4695,7 +5144,7 @@ async def test_create_processor_async_from_dict(): def test_create_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4725,7 +5174,7 @@ def test_create_processor_field_headers(): @pytest.mark.asyncio async def test_create_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4756,7 +5205,7 @@ async def test_create_processor_field_headers_async(): def test_create_processor_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4784,7 +5233,7 @@ def test_create_processor_flattened(): def test_create_processor_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4800,7 +5249,7 @@ def test_create_processor_flattened_error(): @pytest.mark.asyncio async def test_create_processor_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4833,7 +5282,7 @@ async def test_create_processor_flattened_async(): @pytest.mark.asyncio async def test_create_processor_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4855,7 +5304,7 @@ async def test_create_processor_flattened_error_async(): ) def test_delete_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4882,7 +5331,7 @@ def test_delete_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4900,7 +5349,7 @@ async def test_delete_processor_async( request_type=document_processor_service.DeleteProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4932,7 +5381,7 @@ async def test_delete_processor_async_from_dict(): def test_delete_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4962,7 +5411,7 @@ def test_delete_processor_field_headers(): @pytest.mark.asyncio async def test_delete_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4993,7 +5442,7 @@ async def test_delete_processor_field_headers_async(): def test_delete_processor_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5017,7 +5466,7 @@ def test_delete_processor_flattened(): def test_delete_processor_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5032,7 +5481,7 @@ def test_delete_processor_flattened_error(): @pytest.mark.asyncio async def test_delete_processor_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5061,7 +5510,7 @@ async def test_delete_processor_flattened_async(): @pytest.mark.asyncio async def test_delete_processor_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5082,7 +5531,7 @@ async def test_delete_processor_flattened_error_async(): ) def test_enable_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5109,7 +5558,7 @@ def test_enable_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5127,7 +5576,7 @@ async def test_enable_processor_async( request_type=document_processor_service.EnableProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5159,7 +5608,7 @@ async def test_enable_processor_async_from_dict(): def test_enable_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5189,7 +5638,7 @@ def test_enable_processor_field_headers(): @pytest.mark.asyncio async def test_enable_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5227,7 +5676,7 @@ async def test_enable_processor_field_headers_async(): ) def test_disable_processor(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5256,7 +5705,7 @@ def test_disable_processor_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5276,7 +5725,7 @@ async def test_disable_processor_async( request_type=document_processor_service.DisableProcessorRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5310,7 +5759,7 @@ async def test_disable_processor_async_from_dict(): def test_disable_processor_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5342,7 +5791,7 @@ def test_disable_processor_field_headers(): @pytest.mark.asyncio async def test_disable_processor_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5382,7 +5831,7 @@ async def test_disable_processor_field_headers_async(): ) def test_set_default_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5411,7 +5860,7 @@ def test_set_default_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5431,7 +5880,7 @@ async def test_set_default_processor_version_async( request_type=document_processor_service.SetDefaultProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5465,7 +5914,7 @@ async def test_set_default_processor_version_async_from_dict(): def test_set_default_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5497,7 +5946,7 @@ def test_set_default_processor_version_field_headers(): @pytest.mark.asyncio async def test_set_default_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5537,7 +5986,7 @@ async def test_set_default_processor_version_field_headers_async(): ) def test_review_document(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5564,7 +6013,7 @@ def test_review_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5582,7 +6031,7 @@ async def test_review_document_async( request_type=document_processor_service.ReviewDocumentRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5614,7 +6063,7 @@ async def test_review_document_async_from_dict(): def test_review_document_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5644,7 +6093,7 @@ def test_review_document_field_headers(): @pytest.mark.asyncio async def test_review_document_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5675,7 +6124,7 @@ async def test_review_document_field_headers_async(): def test_review_document_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5699,7 +6148,7 @@ def test_review_document_flattened(): def test_review_document_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5714,7 +6163,7 @@ def test_review_document_flattened_error(): @pytest.mark.asyncio async def test_review_document_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5743,7 +6192,7 @@ async def test_review_document_flattened_async(): @pytest.mark.asyncio async def test_review_document_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5764,7 +6213,7 @@ async def test_review_document_flattened_error_async(): ) def test_evaluate_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5793,7 +6242,7 @@ def test_evaluate_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5813,7 +6262,7 @@ async def test_evaluate_processor_version_async( request_type=document_processor_service.EvaluateProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5847,7 +6296,7 @@ async def test_evaluate_processor_version_async_from_dict(): def test_evaluate_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5879,7 +6328,7 @@ def test_evaluate_processor_version_field_headers(): @pytest.mark.asyncio async def test_evaluate_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5912,7 +6361,7 @@ async def test_evaluate_processor_version_field_headers_async(): def test_evaluate_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5938,7 +6387,7 @@ def test_evaluate_processor_version_flattened(): def test_evaluate_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5953,7 +6402,7 @@ def test_evaluate_processor_version_flattened_error(): @pytest.mark.asyncio async def test_evaluate_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5984,7 +6433,7 @@ async def test_evaluate_processor_version_flattened_async(): @pytest.mark.asyncio async def test_evaluate_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6005,7 +6454,7 @@ async def test_evaluate_processor_version_flattened_error_async(): ) def test_get_evaluation(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6039,7 +6488,7 @@ def test_get_evaluation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6057,7 +6506,7 @@ async def test_get_evaluation_async( request_type=document_processor_service.GetEvaluationRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6096,7 +6545,7 @@ async def test_get_evaluation_async_from_dict(): def test_get_evaluation_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6126,7 +6575,7 @@ def test_get_evaluation_field_headers(): @pytest.mark.asyncio async def test_get_evaluation_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6157,7 +6606,7 @@ async def test_get_evaluation_field_headers_async(): def test_get_evaluation_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6181,7 +6630,7 @@ def test_get_evaluation_flattened(): def test_get_evaluation_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6196,7 +6645,7 @@ def test_get_evaluation_flattened_error(): @pytest.mark.asyncio async def test_get_evaluation_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6225,7 +6674,7 @@ async def test_get_evaluation_flattened_async(): @pytest.mark.asyncio async def test_get_evaluation_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6246,7 +6695,7 @@ async def test_get_evaluation_flattened_error_async(): ) def test_list_evaluations(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6276,7 +6725,7 @@ def test_list_evaluations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6294,7 +6743,7 @@ async def test_list_evaluations_async( request_type=document_processor_service.ListEvaluationsRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6329,7 +6778,7 @@ async def test_list_evaluations_async_from_dict(): def test_list_evaluations_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6359,7 +6808,7 @@ def test_list_evaluations_field_headers(): @pytest.mark.asyncio async def test_list_evaluations_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6390,7 +6839,7 @@ async def test_list_evaluations_field_headers_async(): def test_list_evaluations_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6414,7 +6863,7 @@ def test_list_evaluations_flattened(): def test_list_evaluations_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6429,7 +6878,7 @@ def test_list_evaluations_flattened_error(): @pytest.mark.asyncio async def test_list_evaluations_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6458,7 +6907,7 @@ async def test_list_evaluations_flattened_async(): @pytest.mark.asyncio async def test_list_evaluations_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6472,7 +6921,7 @@ async def test_list_evaluations_flattened_error_async(): def test_list_evaluations_pager(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6522,7 +6971,7 @@ def test_list_evaluations_pager(transport_name: str = "grpc"): def test_list_evaluations_pages(transport_name: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6564,7 +7013,7 @@ def test_list_evaluations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_evaluations_async_pager(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6614,7 +7063,7 @@ async def test_list_evaluations_async_pager(): @pytest.mark.asyncio async def test_list_evaluations_async_pages(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6669,7 +7118,7 @@ async def test_list_evaluations_async_pages(): ) def test_import_processor_version(request_type, transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6698,7 +7147,7 @@ def test_import_processor_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6718,7 +7167,7 @@ async def test_import_processor_version_async( request_type=document_processor_service.ImportProcessorVersionRequest, ): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6752,7 +7201,7 @@ async def test_import_processor_version_async_from_dict(): def test_import_processor_version_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6784,7 +7233,7 @@ def test_import_processor_version_field_headers(): @pytest.mark.asyncio async def test_import_processor_version_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6817,7 +7266,7 @@ async def test_import_processor_version_field_headers_async(): def test_import_processor_version_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6843,7 +7292,7 @@ def test_import_processor_version_flattened(): def test_import_processor_version_flattened_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6858,7 +7307,7 @@ def test_import_processor_version_flattened_error(): @pytest.mark.asyncio async def test_import_processor_version_flattened_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6889,7 +7338,7 @@ async def test_import_processor_version_flattened_async(): @pytest.mark.asyncio async def test_import_processor_version_flattened_error_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6910,7 +7359,7 @@ async def test_import_processor_version_flattened_error_async(): ) def test_process_document_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6961,7 +7410,7 @@ def test_process_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).process_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6970,7 +7419,7 @@ def test_process_document_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).process_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6979,7 +7428,7 @@ def test_process_document_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7022,7 +7471,7 @@ def test_process_document_rest_required_fields( def test_process_document_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.process_document._get_unset_required_fields({}) @@ -7032,7 +7481,7 @@ def test_process_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_process_document_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -7090,7 +7539,7 @@ def test_process_document_rest_bad_request( transport: str = "rest", request_type=document_processor_service.ProcessRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7112,7 +7561,7 @@ def test_process_document_rest_bad_request( def test_process_document_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7156,7 +7605,7 @@ def test_process_document_rest_flattened(): def test_process_document_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7171,7 +7620,7 @@ def test_process_document_rest_flattened_error(transport: str = "rest"): def test_process_document_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7184,7 +7633,7 @@ def test_process_document_rest_error(): ) def test_batch_process_documents_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7230,7 +7679,7 @@ def test_batch_process_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_process_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7239,7 +7688,7 @@ def test_batch_process_documents_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_process_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7248,7 +7697,7 @@ def test_batch_process_documents_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7288,7 +7737,7 @@ def test_batch_process_documents_rest_required_fields( def test_batch_process_documents_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_process_documents._get_unset_required_fields({}) @@ -7298,7 +7747,7 @@ def test_batch_process_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_process_documents_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -7360,7 +7809,7 @@ def test_batch_process_documents_rest_bad_request( transport: str = "rest", request_type=document_processor_service.BatchProcessRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7382,7 +7831,7 @@ def test_batch_process_documents_rest_bad_request( def test_batch_process_documents_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7424,7 +7873,7 @@ def test_batch_process_documents_rest_flattened(): def test_batch_process_documents_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7439,7 +7888,7 @@ def test_batch_process_documents_rest_flattened_error(transport: str = "rest"): def test_batch_process_documents_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7452,7 +7901,7 @@ def test_batch_process_documents_rest_error(): ) def test_fetch_processor_types_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7502,7 +7951,7 @@ def test_fetch_processor_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).fetch_processor_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7511,7 +7960,7 @@ def test_fetch_processor_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).fetch_processor_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7520,7 +7969,7 @@ def test_fetch_processor_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7564,7 +8013,7 @@ def test_fetch_processor_types_rest_required_fields( def test_fetch_processor_types_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.fetch_processor_types._get_unset_required_fields({}) @@ -7574,7 +8023,7 @@ def test_fetch_processor_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_fetch_processor_types_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -7635,7 +8084,7 @@ def test_fetch_processor_types_rest_bad_request( request_type=document_processor_service.FetchProcessorTypesRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7657,7 +8106,7 @@ def test_fetch_processor_types_rest_bad_request( def test_fetch_processor_types_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7701,7 +8150,7 @@ def test_fetch_processor_types_rest_flattened(): def test_fetch_processor_types_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7716,7 +8165,7 @@ def test_fetch_processor_types_rest_flattened_error(transport: str = "rest"): def test_fetch_processor_types_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7729,7 +8178,7 @@ def test_fetch_processor_types_rest_error(): ) def test_list_processor_types_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7782,7 +8231,7 @@ def test_list_processor_types_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processor_types._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7791,7 +8240,7 @@ def test_list_processor_types_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processor_types._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7807,7 +8256,7 @@ def test_list_processor_types_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7851,7 +8300,7 @@ def test_list_processor_types_rest_required_fields( def test_list_processor_types_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_processor_types._get_unset_required_fields({}) @@ -7869,7 +8318,7 @@ def test_list_processor_types_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_processor_types_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -7930,7 +8379,7 @@ def test_list_processor_types_rest_bad_request( request_type=document_processor_service.ListProcessorTypesRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7952,7 +8401,7 @@ def test_list_processor_types_rest_bad_request( def test_list_processor_types_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7996,7 +8445,7 @@ def test_list_processor_types_rest_flattened(): def test_list_processor_types_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8011,7 +8460,7 @@ def test_list_processor_types_rest_flattened_error(transport: str = "rest"): def test_list_processor_types_rest_pager(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8082,7 +8531,7 @@ def test_list_processor_types_rest_pager(transport: str = "rest"): ) def test_get_processor_type_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8143,7 +8592,7 @@ def test_get_processor_type_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8152,7 +8601,7 @@ def test_get_processor_type_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor_type._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8161,7 +8610,7 @@ def test_get_processor_type_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8203,7 +8652,7 @@ def test_get_processor_type_rest_required_fields( def test_get_processor_type_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_processor_type._get_unset_required_fields({}) @@ -8213,7 +8662,7 @@ def test_get_processor_type_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_processor_type_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -8272,7 +8721,7 @@ def test_get_processor_type_rest_bad_request( request_type=document_processor_service.GetProcessorTypeRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8294,7 +8743,7 @@ def test_get_processor_type_rest_bad_request( def test_get_processor_type_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8338,7 +8787,7 @@ def test_get_processor_type_rest_flattened(): def test_get_processor_type_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8353,7 +8802,7 @@ def test_get_processor_type_rest_flattened_error(transport: str = "rest"): def test_get_processor_type_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8366,7 +8815,7 @@ def test_get_processor_type_rest_error(): ) def test_list_processors_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8419,7 +8868,7 @@ def test_list_processors_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processors._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8428,7 +8877,7 @@ def test_list_processors_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processors._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8444,7 +8893,7 @@ def test_list_processors_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8488,7 +8937,7 @@ def test_list_processors_rest_required_fields( def test_list_processors_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_processors._get_unset_required_fields({}) @@ -8506,7 +8955,7 @@ def test_list_processors_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_processors_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -8567,7 +9016,7 @@ def test_list_processors_rest_bad_request( request_type=document_processor_service.ListProcessorsRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8589,7 +9038,7 @@ def test_list_processors_rest_bad_request( def test_list_processors_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8633,7 +9082,7 @@ def test_list_processors_rest_flattened(): def test_list_processors_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8648,7 +9097,7 @@ def test_list_processors_rest_flattened_error(transport: str = "rest"): def test_list_processors_rest_pager(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8719,7 +9168,7 @@ def test_list_processors_rest_pager(transport: str = "rest"): ) def test_get_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8782,7 +9231,7 @@ def test_get_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8791,7 +9240,7 @@ def test_get_processor_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8800,7 +9249,7 @@ def test_get_processor_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8842,7 +9291,7 @@ def test_get_processor_rest_required_fields( def test_get_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_processor._get_unset_required_fields({}) @@ -8852,7 +9301,7 @@ def test_get_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -8908,7 +9357,7 @@ def test_get_processor_rest_bad_request( transport: str = "rest", request_type=document_processor_service.GetProcessorRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8930,7 +9379,7 @@ def test_get_processor_rest_bad_request( def test_get_processor_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8974,7 +9423,7 @@ def test_get_processor_rest_flattened(): def test_get_processor_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8989,7 +9438,7 @@ def test_get_processor_rest_flattened_error(transport: str = "rest"): def test_get_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9002,7 +9451,7 @@ def test_get_processor_rest_error(): ) def test_train_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9048,7 +9497,7 @@ def test_train_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9057,7 +9506,7 @@ def test_train_processor_version_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).train_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9066,7 +9515,7 @@ def test_train_processor_version_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9106,7 +9555,7 @@ def test_train_processor_version_rest_required_fields( def test_train_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.train_processor_version._get_unset_required_fields({}) @@ -9124,7 +9573,7 @@ def test_train_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_train_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -9187,7 +9636,7 @@ def test_train_processor_version_rest_bad_request( request_type=document_processor_service.TrainProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9209,7 +9658,7 @@ def test_train_processor_version_rest_bad_request( def test_train_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9252,7 +9701,7 @@ def test_train_processor_version_rest_flattened(): def test_train_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9268,7 +9717,7 @@ def test_train_processor_version_rest_flattened_error(transport: str = "rest"): def test_train_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9281,7 +9730,7 @@ def test_train_processor_version_rest_error(): ) def test_get_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9344,7 +9793,7 @@ def test_get_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9353,7 +9802,7 @@ def test_get_processor_version_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9362,7 +9811,7 @@ def test_get_processor_version_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9404,7 +9853,7 @@ def test_get_processor_version_rest_required_fields( def test_get_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_processor_version._get_unset_required_fields({}) @@ -9414,7 +9863,7 @@ def test_get_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -9473,7 +9922,7 @@ def test_get_processor_version_rest_bad_request( request_type=document_processor_service.GetProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9497,7 +9946,7 @@ def test_get_processor_version_rest_bad_request( def test_get_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9541,7 +9990,7 @@ def test_get_processor_version_rest_flattened(): def test_get_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9556,7 +10005,7 @@ def test_get_processor_version_rest_flattened_error(transport: str = "rest"): def test_get_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9569,7 +10018,7 @@ def test_get_processor_version_rest_error(): ) def test_list_processor_versions_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9622,7 +10071,7 @@ def test_list_processor_versions_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processor_versions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9631,7 +10080,7 @@ def test_list_processor_versions_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_processor_versions._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -9647,7 +10096,7 @@ def test_list_processor_versions_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9691,7 +10140,7 @@ def test_list_processor_versions_rest_required_fields( def test_list_processor_versions_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_processor_versions._get_unset_required_fields({}) @@ -9709,7 +10158,7 @@ def test_list_processor_versions_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_processor_versions_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -9772,7 +10221,7 @@ def test_list_processor_versions_rest_bad_request( request_type=document_processor_service.ListProcessorVersionsRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9794,7 +10243,7 @@ def test_list_processor_versions_rest_bad_request( def test_list_processor_versions_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9840,7 +10289,7 @@ def test_list_processor_versions_rest_flattened(): def test_list_processor_versions_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9855,7 +10304,7 @@ def test_list_processor_versions_rest_flattened_error(transport: str = "rest"): def test_list_processor_versions_rest_pager(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9928,7 +10377,7 @@ def test_list_processor_versions_rest_pager(transport: str = "rest"): ) def test_delete_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9976,7 +10425,7 @@ def test_delete_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9985,7 +10434,7 @@ def test_delete_processor_version_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9994,7 +10443,7 @@ def test_delete_processor_version_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10033,7 +10482,7 @@ def test_delete_processor_version_rest_required_fields( def test_delete_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_processor_version._get_unset_required_fields({}) @@ -10043,7 +10492,7 @@ def test_delete_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -10106,7 +10555,7 @@ def test_delete_processor_version_rest_bad_request( request_type=document_processor_service.DeleteProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10130,7 +10579,7 @@ def test_delete_processor_version_rest_bad_request( def test_delete_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10172,7 +10621,7 @@ def test_delete_processor_version_rest_flattened(): def test_delete_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10187,7 +10636,7 @@ def test_delete_processor_version_rest_flattened_error(transport: str = "rest"): def test_delete_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10200,7 +10649,7 @@ def test_delete_processor_version_rest_error(): ) def test_deploy_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10248,7 +10697,7 @@ def test_deploy_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).deploy_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10257,7 +10706,7 @@ def test_deploy_processor_version_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).deploy_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10266,7 +10715,7 @@ def test_deploy_processor_version_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10306,7 +10755,7 @@ def test_deploy_processor_version_rest_required_fields( def test_deploy_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.deploy_processor_version._get_unset_required_fields({}) @@ -10316,7 +10765,7 @@ def test_deploy_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_deploy_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -10379,7 +10828,7 @@ def test_deploy_processor_version_rest_bad_request( request_type=document_processor_service.DeployProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10403,7 +10852,7 @@ def test_deploy_processor_version_rest_bad_request( def test_deploy_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10445,7 +10894,7 @@ def test_deploy_processor_version_rest_flattened(): def test_deploy_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10460,7 +10909,7 @@ def test_deploy_processor_version_rest_flattened_error(transport: str = "rest"): def test_deploy_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10473,7 +10922,7 @@ def test_deploy_processor_version_rest_error(): ) def test_undeploy_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10521,7 +10970,7 @@ def test_undeploy_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).undeploy_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10530,7 +10979,7 @@ def test_undeploy_processor_version_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).undeploy_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10539,7 +10988,7 @@ def test_undeploy_processor_version_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10579,7 +11028,7 @@ def test_undeploy_processor_version_rest_required_fields( def test_undeploy_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.undeploy_processor_version._get_unset_required_fields({}) @@ -10589,7 +11038,7 @@ def test_undeploy_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_undeploy_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -10652,7 +11101,7 @@ def test_undeploy_processor_version_rest_bad_request( request_type=document_processor_service.UndeployProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10676,7 +11125,7 @@ def test_undeploy_processor_version_rest_bad_request( def test_undeploy_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10718,7 +11167,7 @@ def test_undeploy_processor_version_rest_flattened(): def test_undeploy_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10733,7 +11182,7 @@ def test_undeploy_processor_version_rest_flattened_error(transport: str = "rest" def test_undeploy_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10746,7 +11195,7 @@ def test_undeploy_processor_version_rest_error(): ) def test_create_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10891,7 +11340,7 @@ def test_create_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10900,7 +11349,7 @@ def test_create_processor_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10909,7 +11358,7 @@ def test_create_processor_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10952,7 +11401,7 @@ def test_create_processor_rest_required_fields( def test_create_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_processor._get_unset_required_fields({}) @@ -10970,7 +11419,7 @@ def test_create_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -11029,7 +11478,7 @@ def test_create_processor_rest_bad_request( request_type=document_processor_service.CreateProcessorRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11051,7 +11500,7 @@ def test_create_processor_rest_bad_request( def test_create_processor_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11094,7 +11543,7 @@ def test_create_processor_rest_flattened(): def test_create_processor_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11110,7 +11559,7 @@ def test_create_processor_rest_flattened_error(transport: str = "rest"): def test_create_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11123,7 +11572,7 @@ def test_create_processor_rest_error(): ) def test_delete_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11169,7 +11618,7 @@ def test_delete_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11178,7 +11627,7 @@ def test_delete_processor_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11187,7 +11636,7 @@ def test_delete_processor_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11226,7 +11675,7 @@ def test_delete_processor_rest_required_fields( def test_delete_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_processor._get_unset_required_fields({}) @@ -11236,7 +11685,7 @@ def test_delete_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -11297,7 +11746,7 @@ def test_delete_processor_rest_bad_request( request_type=document_processor_service.DeleteProcessorRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11319,7 +11768,7 @@ def test_delete_processor_rest_bad_request( def test_delete_processor_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11361,7 +11810,7 @@ def test_delete_processor_rest_flattened(): def test_delete_processor_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11376,7 +11825,7 @@ def test_delete_processor_rest_flattened_error(transport: str = "rest"): def test_delete_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11389,7 +11838,7 @@ def test_delete_processor_rest_error(): ) def test_enable_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11435,7 +11884,7 @@ def test_enable_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).enable_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11444,7 +11893,7 @@ def test_enable_processor_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).enable_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11453,7 +11902,7 @@ def test_enable_processor_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11493,7 +11942,7 @@ def test_enable_processor_rest_required_fields( def test_enable_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.enable_processor._get_unset_required_fields({}) @@ -11503,7 +11952,7 @@ def test_enable_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_enable_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -11564,7 +12013,7 @@ def test_enable_processor_rest_bad_request( request_type=document_processor_service.EnableProcessorRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11586,7 +12035,7 @@ def test_enable_processor_rest_bad_request( def test_enable_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11599,7 +12048,7 @@ def test_enable_processor_rest_error(): ) def test_disable_processor_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11645,7 +12094,7 @@ def test_disable_processor_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).disable_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11654,7 +12103,7 @@ def test_disable_processor_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).disable_processor._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11663,7 +12112,7 @@ def test_disable_processor_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11703,7 +12152,7 @@ def test_disable_processor_rest_required_fields( def test_disable_processor_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.disable_processor._get_unset_required_fields({}) @@ -11713,7 +12162,7 @@ def test_disable_processor_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_disable_processor_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -11774,7 +12223,7 @@ def test_disable_processor_rest_bad_request( request_type=document_processor_service.DisableProcessorRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11796,7 +12245,7 @@ def test_disable_processor_rest_bad_request( def test_disable_processor_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11809,7 +12258,7 @@ def test_disable_processor_rest_error(): ) def test_set_default_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11858,7 +12307,7 @@ def test_set_default_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_default_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11868,7 +12317,7 @@ def test_set_default_processor_version_rest_required_fields( jsonified_request["defaultProcessorVersion"] = "default_processor_version_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_default_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11882,7 +12331,7 @@ def test_set_default_processor_version_rest_required_fields( ) client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11922,7 +12371,7 @@ def test_set_default_processor_version_rest_required_fields( def test_set_default_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.set_default_processor_version._get_unset_required_fields( @@ -11942,7 +12391,7 @@ def test_set_default_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_set_default_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -12005,7 +12454,7 @@ def test_set_default_processor_version_rest_bad_request( request_type=document_processor_service.SetDefaultProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12029,7 +12478,7 @@ def test_set_default_processor_version_rest_bad_request( def test_set_default_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12042,7 +12491,7 @@ def test_set_default_processor_version_rest_error(): ) def test_review_document_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12090,7 +12539,7 @@ def test_review_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).review_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12099,7 +12548,7 @@ def test_review_document_rest_required_fields( jsonified_request["humanReviewConfig"] = "human_review_config_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).review_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12108,7 +12557,7 @@ def test_review_document_rest_required_fields( assert jsonified_request["humanReviewConfig"] == "human_review_config_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12148,7 +12597,7 @@ def test_review_document_rest_required_fields( def test_review_document_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.review_document._get_unset_required_fields({}) @@ -12158,7 +12607,7 @@ def test_review_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_review_document_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -12219,7 +12668,7 @@ def test_review_document_rest_bad_request( request_type=document_processor_service.ReviewDocumentRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12243,7 +12692,7 @@ def test_review_document_rest_bad_request( def test_review_document_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12285,7 +12734,7 @@ def test_review_document_rest_flattened(): def test_review_document_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12300,7 +12749,7 @@ def test_review_document_rest_flattened_error(transport: str = "rest"): def test_review_document_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12313,7 +12762,7 @@ def test_review_document_rest_error(): ) def test_evaluate_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12361,7 +12810,7 @@ def test_evaluate_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).evaluate_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12370,7 +12819,7 @@ def test_evaluate_processor_version_rest_required_fields( jsonified_request["processorVersion"] = "processor_version_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).evaluate_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12379,7 +12828,7 @@ def test_evaluate_processor_version_rest_required_fields( assert jsonified_request["processorVersion"] == "processor_version_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12419,7 +12868,7 @@ def test_evaluate_processor_version_rest_required_fields( def test_evaluate_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.evaluate_processor_version._get_unset_required_fields({}) @@ -12429,7 +12878,7 @@ def test_evaluate_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_evaluate_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -12492,7 +12941,7 @@ def test_evaluate_processor_version_rest_bad_request( request_type=document_processor_service.EvaluateProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12516,7 +12965,7 @@ def test_evaluate_processor_version_rest_bad_request( def test_evaluate_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12558,7 +13007,7 @@ def test_evaluate_processor_version_rest_flattened(): def test_evaluate_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12573,7 +13022,7 @@ def test_evaluate_processor_version_rest_flattened_error(transport: str = "rest" def test_evaluate_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12586,7 +13035,7 @@ def test_evaluate_processor_version_rest_error(): ) def test_get_evaluation_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12643,7 +13092,7 @@ def test_get_evaluation_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_evaluation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12652,7 +13101,7 @@ def test_get_evaluation_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_evaluation._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12661,7 +13110,7 @@ def test_get_evaluation_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12703,7 +13152,7 @@ def test_get_evaluation_rest_required_fields( def test_get_evaluation_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_evaluation._get_unset_required_fields({}) @@ -12713,7 +13162,7 @@ def test_get_evaluation_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_evaluation_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -12772,7 +13221,7 @@ def test_get_evaluation_rest_bad_request( request_type=document_processor_service.GetEvaluationRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12796,7 +13245,7 @@ def test_get_evaluation_rest_bad_request( def test_get_evaluation_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12840,7 +13289,7 @@ def test_get_evaluation_rest_flattened(): def test_get_evaluation_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12855,7 +13304,7 @@ def test_get_evaluation_rest_flattened_error(transport: str = "rest"): def test_get_evaluation_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12868,7 +13317,7 @@ def test_get_evaluation_rest_error(): ) def test_list_evaluations_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12923,7 +13372,7 @@ def test_list_evaluations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_evaluations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12932,7 +13381,7 @@ def test_list_evaluations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_evaluations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -12948,7 +13397,7 @@ def test_list_evaluations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12992,7 +13441,7 @@ def test_list_evaluations_rest_required_fields( def test_list_evaluations_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_evaluations._get_unset_required_fields({}) @@ -13010,7 +13459,7 @@ def test_list_evaluations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_evaluations_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -13071,7 +13520,7 @@ def test_list_evaluations_rest_bad_request( request_type=document_processor_service.ListEvaluationsRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13095,7 +13544,7 @@ def test_list_evaluations_rest_bad_request( def test_list_evaluations_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13141,7 +13590,7 @@ def test_list_evaluations_rest_flattened(): def test_list_evaluations_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13156,7 +13605,7 @@ def test_list_evaluations_rest_flattened_error(transport: str = "rest"): def test_list_evaluations_rest_pager(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13229,7 +13678,7 @@ def test_list_evaluations_rest_pager(transport: str = "rest"): ) def test_import_processor_version_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13275,7 +13724,7 @@ def test_import_processor_version_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13284,7 +13733,7 @@ def test_import_processor_version_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_processor_version._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13293,7 +13742,7 @@ def test_import_processor_version_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13333,7 +13782,7 @@ def test_import_processor_version_rest_required_fields( def test_import_processor_version_rest_unset_required_fields(): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_processor_version._get_unset_required_fields({}) @@ -13343,7 +13792,7 @@ def test_import_processor_version_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_processor_version_rest_interceptors(null_interceptor): transport = transports.DocumentProcessorServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentProcessorServiceRestInterceptor(), @@ -13406,7 +13855,7 @@ def test_import_processor_version_rest_bad_request( request_type=document_processor_service.ImportProcessorVersionRequest, ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13428,7 +13877,7 @@ def test_import_processor_version_rest_bad_request( def test_import_processor_version_rest_flattened(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13470,7 +13919,7 @@ def test_import_processor_version_rest_flattened(): def test_import_processor_version_rest_flattened_error(transport: str = "rest"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13485,24 +13934,24 @@ def test_import_processor_version_rest_flattened_error(transport: str = "rest"): def test_import_processor_version_rest_error(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( @@ -13512,7 +13961,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -13523,16 +13972,17 @@ 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 = DocumentProcessorServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentProcessorServiceClient( @@ -13544,7 +13994,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DocumentProcessorServiceClient(transport=transport) assert client.transport is transport @@ -13553,13 +14003,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentProcessorServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DocumentProcessorServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -13576,7 +14026,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -13590,7 +14040,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DocumentProcessorServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -13598,7 +14048,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -13610,7 +14060,7 @@ def test_document_processor_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DocumentProcessorServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -13622,7 +14072,7 @@ def test_document_processor_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DocumentProcessorServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -13686,7 +14136,7 @@ def test_document_processor_service_base_transport_with_credentials_file(): "google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentProcessorServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -13705,7 +14155,7 @@ def test_document_processor_service_base_transport_with_adc(): "google.cloud.documentai_v1beta3.services.document_processor_service.transports.DocumentProcessorServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentProcessorServiceTransport() adc.assert_called_once() @@ -13713,7 +14163,7 @@ def test_document_processor_service_base_transport_with_adc(): def test_document_processor_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DocumentProcessorServiceClient() adc.assert_called_once_with( scopes=None, @@ -13733,7 +14183,7 @@ def test_document_processor_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -13782,7 +14232,7 @@ def test_document_processor_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -13812,7 +14262,7 @@ def test_document_processor_service_transport_create_channel( def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -13850,7 +14300,7 @@ def test_document_processor_service_grpc_transport_client_cert_source_for_mtls( def test_document_processor_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -13862,7 +14312,7 @@ def test_document_processor_service_http_transport_client_cert_source_for_mtls() def test_document_processor_service_rest_lro_client(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -13887,7 +14337,7 @@ def test_document_processor_service_rest_lro_client(): ) def test_document_processor_service_host_no_port(transport_name): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com" ), @@ -13910,7 +14360,7 @@ def test_document_processor_service_host_no_port(transport_name): ) def test_document_processor_service_host_with_port(transport_name): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com:8000" ), @@ -13930,8 +14380,8 @@ def test_document_processor_service_host_with_port(transport_name): ], ) def test_document_processor_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DocumentProcessorServiceClient( credentials=creds1, transport=transport_name, @@ -14061,7 +14511,7 @@ def test_document_processor_service_transport_channel_mtls_with_client_cert_sour mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -14139,7 +14589,7 @@ def test_document_processor_service_transport_channel_mtls_with_adc(transport_cl def test_document_processor_service_grpc_lro_client(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -14156,7 +14606,7 @@ def test_document_processor_service_grpc_lro_client(): def test_document_processor_service_grpc_lro_async_client(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -14428,7 +14878,7 @@ def test_client_with_default_client_info(): transports.DocumentProcessorServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -14438,7 +14888,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentProcessorServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -14447,7 +14897,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -14462,7 +14912,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14492,7 +14942,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -14520,7 +14970,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14548,7 +14998,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -14576,7 +15026,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14606,7 +15056,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -14634,7 +15084,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14664,7 +15114,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -14692,7 +15142,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14722,7 +15172,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations"} @@ -14748,7 +15198,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14773,7 +15223,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14797,7 +15247,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14826,7 +15276,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14853,7 +15303,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -14871,7 +15321,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -14887,7 +15337,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14912,7 +15362,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14938,7 +15388,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14967,7 +15417,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14996,7 +15446,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -15014,7 +15464,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -15032,7 +15482,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15057,7 +15507,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15083,7 +15533,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -15112,7 +15562,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -15141,7 +15591,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -15159,7 +15609,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -15177,7 +15627,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15202,7 +15652,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15228,7 +15678,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -15257,7 +15707,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -15286,7 +15736,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -15304,7 +15754,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -15322,7 +15772,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15347,7 +15797,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15373,7 +15823,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -15402,7 +15852,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -15431,7 +15881,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -15449,7 +15899,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = DocumentProcessorServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -15473,7 +15923,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -15490,7 +15940,7 @@ def test_client_ctx(): ] for transport in transports: client = DocumentProcessorServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -15527,7 +15977,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, diff --git a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_service.py b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_service.py index 0a591d80fac9..08adf897c4a2 100644 --- a/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_service.py +++ b/packages/google-cloud-documentai/tests/unit/gapic/documentai_v1beta3/test_document_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -85,6 +85,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -114,6 +137,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert DocumentServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DocumentServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DocumentServiceClient._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 DocumentServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DocumentServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentServiceClient._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 DocumentServiceClient._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 DocumentServiceClient._get_client_cert_source(None, False) is None + assert ( + DocumentServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + DocumentServiceClient._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 ( + DocumentServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DocumentServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + DocumentServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), +) +@mock.patch.object( + DocumentServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DocumentServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DocumentServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DocumentServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "always") + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DocumentServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DocumentServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DocumentServiceClient._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 ( + DocumentServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + DocumentServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DocumentServiceClient._get_universe_domain(None, None) + == DocumentServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DocumentServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DocumentServiceClient, transports.DocumentServiceGrpcTransport, "grpc"), + (DocumentServiceClient, transports.DocumentServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -125,7 +409,7 @@ def test__get_default_mtls_endpoint(): def test_document_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -179,7 +463,7 @@ def test_document_service_client_service_account_always_use_jwt( def test_document_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -229,20 +513,22 @@ def test_document_service_client_get_transport_class(): ) @mock.patch.object( DocumentServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), ) @mock.patch.object( DocumentServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), ) def test_document_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(DocumentServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -277,7 +563,9 @@ def test_document_service_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, @@ -307,15 +595,23 @@ def test_document_service_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") @@ -325,7 +621,9 @@ def test_document_service_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", @@ -343,7 +641,9 @@ def test_document_service_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, @@ -396,13 +696,13 @@ def test_document_service_client_client_options( ) @mock.patch.object( DocumentServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), ) @mock.patch.object( DocumentServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(DocumentServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_document_service_client_mtls_env_auto( @@ -425,7 +725,9 @@ def test_document_service_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 @@ -457,7 +759,9 @@ def test_document_service_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 @@ -491,7 +795,9 @@ def test_document_service_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, @@ -581,6 +887,118 @@ def test_document_service_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", [DocumentServiceClient, DocumentServiceAsyncClient] +) +@mock.patch.object( + DocumentServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceClient), +) +@mock.patch.object( + DocumentServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DocumentServiceAsyncClient), +) +def test_document_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DocumentServiceClient._DEFAULT_UNIVERSE + default_endpoint = DocumentServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DocumentServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -607,7 +1025,9 @@ def test_document_service_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, @@ -647,7 +1067,9 @@ def test_document_service_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, @@ -707,7 +1129,9 @@ def test_document_service_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, @@ -724,8 +1148,8 @@ def test_document_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -754,7 +1178,7 @@ def test_document_service_client_create_channel_credentials_file( ) def test_update_dataset(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -781,7 +1205,7 @@ def test_update_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -798,7 +1222,7 @@ async def test_update_dataset_async( transport: str = "grpc_asyncio", request_type=document_service.UpdateDatasetRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -830,7 +1254,7 @@ async def test_update_dataset_async_from_dict(): def test_update_dataset_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -860,7 +1284,7 @@ def test_update_dataset_field_headers(): @pytest.mark.asyncio async def test_update_dataset_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -891,7 +1315,7 @@ async def test_update_dataset_field_headers_async(): def test_update_dataset_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -929,7 +1353,7 @@ def test_update_dataset_flattened(): def test_update_dataset_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -951,7 +1375,7 @@ def test_update_dataset_flattened_error(): @pytest.mark.asyncio async def test_update_dataset_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -994,7 +1418,7 @@ async def test_update_dataset_flattened_async(): @pytest.mark.asyncio async def test_update_dataset_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1022,7 +1446,7 @@ async def test_update_dataset_flattened_error_async(): ) def test_import_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1049,7 +1473,7 @@ def test_import_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1067,7 +1491,7 @@ async def test_import_documents_async( request_type=document_service.ImportDocumentsRequest, ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1099,7 +1523,7 @@ async def test_import_documents_async_from_dict(): def test_import_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1129,7 +1553,7 @@ def test_import_documents_field_headers(): @pytest.mark.asyncio async def test_import_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1160,7 +1584,7 @@ async def test_import_documents_field_headers_async(): def test_import_documents_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1184,7 +1608,7 @@ def test_import_documents_flattened(): def test_import_documents_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1199,7 +1623,7 @@ def test_import_documents_flattened_error(): @pytest.mark.asyncio async def test_import_documents_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1228,7 +1652,7 @@ async def test_import_documents_flattened_async(): @pytest.mark.asyncio async def test_import_documents_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1249,7 +1673,7 @@ async def test_import_documents_flattened_error_async(): ) def test_get_document(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1276,7 +1700,7 @@ def test_get_document_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1293,7 +1717,7 @@ async def test_get_document_async( transport: str = "grpc_asyncio", request_type=document_service.GetDocumentRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1325,7 +1749,7 @@ async def test_get_document_async_from_dict(): def test_get_document_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1355,7 +1779,7 @@ def test_get_document_field_headers(): @pytest.mark.asyncio async def test_get_document_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1386,7 +1810,7 @@ async def test_get_document_field_headers_async(): def test_get_document_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1410,7 +1834,7 @@ def test_get_document_flattened(): def test_get_document_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1425,7 +1849,7 @@ def test_get_document_flattened_error(): @pytest.mark.asyncio async def test_get_document_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1454,7 +1878,7 @@ async def test_get_document_flattened_async(): @pytest.mark.asyncio async def test_get_document_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1475,7 +1899,7 @@ async def test_get_document_flattened_error_async(): ) def test_list_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1507,7 +1931,7 @@ def test_list_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1524,7 +1948,7 @@ async def test_list_documents_async( transport: str = "grpc_asyncio", request_type=document_service.ListDocumentsRequest ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1561,7 +1985,7 @@ async def test_list_documents_async_from_dict(): def test_list_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1591,7 +2015,7 @@ def test_list_documents_field_headers(): @pytest.mark.asyncio async def test_list_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1622,7 +2046,7 @@ async def test_list_documents_field_headers_async(): def test_list_documents_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1646,7 +2070,7 @@ def test_list_documents_flattened(): def test_list_documents_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1661,7 +2085,7 @@ def test_list_documents_flattened_error(): @pytest.mark.asyncio async def test_list_documents_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1690,7 +2114,7 @@ async def test_list_documents_flattened_async(): @pytest.mark.asyncio async def test_list_documents_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1704,7 +2128,7 @@ async def test_list_documents_flattened_error_async(): def test_list_documents_pager(transport_name: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1754,7 +2178,7 @@ def test_list_documents_pager(transport_name: str = "grpc"): def test_list_documents_pages(transport_name: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1796,7 +2220,7 @@ def test_list_documents_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_documents_async_pager(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1846,7 +2270,7 @@ async def test_list_documents_async_pager(): @pytest.mark.asyncio async def test_list_documents_async_pages(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1901,7 +2325,7 @@ async def test_list_documents_async_pages(): ) def test_batch_delete_documents(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1930,7 +2354,7 @@ def test_batch_delete_documents_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1950,7 +2374,7 @@ async def test_batch_delete_documents_async( request_type=document_service.BatchDeleteDocumentsRequest, ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1984,7 +2408,7 @@ async def test_batch_delete_documents_async_from_dict(): def test_batch_delete_documents_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2016,7 +2440,7 @@ def test_batch_delete_documents_field_headers(): @pytest.mark.asyncio async def test_batch_delete_documents_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2049,7 +2473,7 @@ async def test_batch_delete_documents_field_headers_async(): def test_batch_delete_documents_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2075,7 +2499,7 @@ def test_batch_delete_documents_flattened(): def test_batch_delete_documents_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2090,7 +2514,7 @@ def test_batch_delete_documents_flattened_error(): @pytest.mark.asyncio async def test_batch_delete_documents_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2121,7 +2545,7 @@ async def test_batch_delete_documents_flattened_async(): @pytest.mark.asyncio async def test_batch_delete_documents_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2142,7 +2566,7 @@ async def test_batch_delete_documents_flattened_error_async(): ) def test_get_dataset_schema(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2174,7 +2598,7 @@ def test_get_dataset_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2194,7 +2618,7 @@ async def test_get_dataset_schema_async( request_type=document_service.GetDatasetSchemaRequest, ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2231,7 +2655,7 @@ async def test_get_dataset_schema_async_from_dict(): def test_get_dataset_schema_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2263,7 +2687,7 @@ def test_get_dataset_schema_field_headers(): @pytest.mark.asyncio async def test_get_dataset_schema_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2296,7 +2720,7 @@ async def test_get_dataset_schema_field_headers_async(): def test_get_dataset_schema_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2322,7 +2746,7 @@ def test_get_dataset_schema_flattened(): def test_get_dataset_schema_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2337,7 +2761,7 @@ def test_get_dataset_schema_flattened_error(): @pytest.mark.asyncio async def test_get_dataset_schema_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2368,7 +2792,7 @@ async def test_get_dataset_schema_flattened_async(): @pytest.mark.asyncio async def test_get_dataset_schema_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2389,7 +2813,7 @@ async def test_get_dataset_schema_flattened_error_async(): ) def test_update_dataset_schema(request_type, transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2421,7 +2845,7 @@ def test_update_dataset_schema_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2441,7 +2865,7 @@ async def test_update_dataset_schema_async( request_type=document_service.UpdateDatasetSchemaRequest, ): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2478,7 +2902,7 @@ async def test_update_dataset_schema_async_from_dict(): def test_update_dataset_schema_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2510,7 +2934,7 @@ def test_update_dataset_schema_field_headers(): @pytest.mark.asyncio async def test_update_dataset_schema_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2543,7 +2967,7 @@ async def test_update_dataset_schema_field_headers_async(): def test_update_dataset_schema_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2573,7 +2997,7 @@ def test_update_dataset_schema_flattened(): def test_update_dataset_schema_flattened_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2589,7 +3013,7 @@ def test_update_dataset_schema_flattened_error(): @pytest.mark.asyncio async def test_update_dataset_schema_flattened_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2624,7 +3048,7 @@ async def test_update_dataset_schema_flattened_async(): @pytest.mark.asyncio async def test_update_dataset_schema_flattened_error_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2646,7 +3070,7 @@ async def test_update_dataset_schema_flattened_error_async(): ) def test_update_dataset_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2775,14 +3199,14 @@ def test_update_dataset_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_dataset._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_dataset._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -2791,7 +3215,7 @@ def test_update_dataset_rest_required_fields( # verify required fields with non-default values are left alone client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2831,7 +3255,7 @@ def test_update_dataset_rest_required_fields( def test_update_dataset_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_dataset._get_unset_required_fields({}) @@ -2841,7 +3265,7 @@ def test_update_dataset_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_dataset_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -2901,7 +3325,7 @@ def test_update_dataset_rest_bad_request( transport: str = "rest", request_type=document_service.UpdateDatasetRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2927,7 +3351,7 @@ def test_update_dataset_rest_bad_request( def test_update_dataset_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2978,7 +3402,7 @@ def test_update_dataset_rest_flattened(): def test_update_dataset_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3000,7 +3424,7 @@ def test_update_dataset_rest_flattened_error(transport: str = "rest"): def test_update_dataset_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3013,7 +3437,7 @@ def test_update_dataset_rest_error(): ) def test_import_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3061,7 +3485,7 @@ def test_import_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3070,7 +3494,7 @@ def test_import_documents_rest_required_fields( jsonified_request["dataset"] = "dataset_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3079,7 +3503,7 @@ def test_import_documents_rest_required_fields( assert jsonified_request["dataset"] == "dataset_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3119,7 +3543,7 @@ def test_import_documents_rest_required_fields( def test_import_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_documents._get_unset_required_fields({}) @@ -3137,7 +3561,7 @@ def test_import_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3197,7 +3621,7 @@ def test_import_documents_rest_bad_request( transport: str = "rest", request_type=document_service.ImportDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3221,7 +3645,7 @@ def test_import_documents_rest_bad_request( def test_import_documents_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3263,7 +3687,7 @@ def test_import_documents_rest_flattened(): def test_import_documents_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3278,7 +3702,7 @@ def test_import_documents_rest_flattened_error(transport: str = "rest"): def test_import_documents_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3291,7 +3715,7 @@ def test_import_documents_rest_error(): ) def test_get_document_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3341,7 +3765,7 @@ def test_get_document_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3350,7 +3774,7 @@ def test_get_document_rest_required_fields( jsonified_request["dataset"] = "dataset_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_document._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3367,7 +3791,7 @@ def test_get_document_rest_required_fields( assert jsonified_request["dataset"] == "dataset_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3409,7 +3833,7 @@ def test_get_document_rest_required_fields( def test_get_document_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_document._get_unset_required_fields({}) @@ -3433,7 +3857,7 @@ def test_get_document_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_document_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3491,7 +3915,7 @@ def test_get_document_rest_bad_request( transport: str = "rest", request_type=document_service.GetDocumentRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3515,7 +3939,7 @@ def test_get_document_rest_bad_request( def test_get_document_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3559,7 +3983,7 @@ def test_get_document_rest_flattened(): def test_get_document_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3574,7 +3998,7 @@ def test_get_document_rest_flattened_error(transport: str = "rest"): def test_get_document_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3587,7 +4011,7 @@ def test_get_document_rest_error(): ) def test_list_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3642,7 +4066,7 @@ def test_list_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3651,7 +4075,7 @@ def test_list_documents_rest_required_fields( jsonified_request["dataset"] = "dataset_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3660,7 +4084,7 @@ def test_list_documents_rest_required_fields( assert jsonified_request["dataset"] == "dataset_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3703,7 +4127,7 @@ def test_list_documents_rest_required_fields( def test_list_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_documents._get_unset_required_fields({}) @@ -3713,7 +4137,7 @@ def test_list_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -3771,7 +4195,7 @@ def test_list_documents_rest_bad_request( transport: str = "rest", request_type=document_service.ListDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3795,7 +4219,7 @@ def test_list_documents_rest_bad_request( def test_list_documents_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3839,7 +4263,7 @@ def test_list_documents_rest_flattened(): def test_list_documents_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3854,7 +4278,7 @@ def test_list_documents_rest_flattened_error(transport: str = "rest"): def test_list_documents_rest_pager(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3926,7 +4350,7 @@ def test_list_documents_rest_pager(transport: str = "rest"): ) def test_batch_delete_documents_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3974,7 +4398,7 @@ def test_batch_delete_documents_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3983,7 +4407,7 @@ def test_batch_delete_documents_rest_required_fields( jsonified_request["dataset"] = "dataset_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).batch_delete_documents._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3992,7 +4416,7 @@ def test_batch_delete_documents_rest_required_fields( assert jsonified_request["dataset"] == "dataset_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4032,7 +4456,7 @@ def test_batch_delete_documents_rest_required_fields( def test_batch_delete_documents_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.batch_delete_documents._get_unset_required_fields({}) @@ -4050,7 +4474,7 @@ def test_batch_delete_documents_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_batch_delete_documents_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -4110,7 +4534,7 @@ def test_batch_delete_documents_rest_bad_request( transport: str = "rest", request_type=document_service.BatchDeleteDocumentsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4134,7 +4558,7 @@ def test_batch_delete_documents_rest_bad_request( def test_batch_delete_documents_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4176,7 +4600,7 @@ def test_batch_delete_documents_rest_flattened(): def test_batch_delete_documents_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4191,7 +4615,7 @@ def test_batch_delete_documents_rest_flattened_error(transport: str = "rest"): def test_batch_delete_documents_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4204,7 +4628,7 @@ def test_batch_delete_documents_rest_error(): ) def test_get_dataset_schema_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4257,7 +4681,7 @@ def test_get_dataset_schema_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_dataset_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4266,7 +4690,7 @@ def test_get_dataset_schema_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_dataset_schema._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("visible_fields_only",)) @@ -4277,7 +4701,7 @@ def test_get_dataset_schema_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4319,7 +4743,7 @@ def test_get_dataset_schema_rest_required_fields( def test_get_dataset_schema_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_dataset_schema._get_unset_required_fields({}) @@ -4329,7 +4753,7 @@ def test_get_dataset_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_dataset_schema_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -4387,7 +4811,7 @@ def test_get_dataset_schema_rest_bad_request( transport: str = "rest", request_type=document_service.GetDatasetSchemaRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4411,7 +4835,7 @@ def test_get_dataset_schema_rest_bad_request( def test_get_dataset_schema_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4455,7 +4879,7 @@ def test_get_dataset_schema_rest_flattened(): def test_get_dataset_schema_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4470,7 +4894,7 @@ def test_get_dataset_schema_rest_flattened_error(transport: str = "rest"): def test_get_dataset_schema_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4483,7 +4907,7 @@ def test_get_dataset_schema_rest_error(): ) def test_update_dataset_schema_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4641,14 +5065,14 @@ def test_update_dataset_schema_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_dataset_schema._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_dataset_schema._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -4657,7 +5081,7 @@ def test_update_dataset_schema_rest_required_fields( # verify required fields with non-default values are left alone client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4700,7 +5124,7 @@ def test_update_dataset_schema_rest_required_fields( def test_update_dataset_schema_rest_unset_required_fields(): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_dataset_schema._get_unset_required_fields({}) @@ -4710,7 +5134,7 @@ def test_update_dataset_schema_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_dataset_schema_rest_interceptors(null_interceptor): transport = transports.DocumentServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DocumentServiceRestInterceptor(), @@ -4768,7 +5192,7 @@ def test_update_dataset_schema_rest_bad_request( transport: str = "rest", request_type=document_service.UpdateDatasetSchemaRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4794,7 +5218,7 @@ def test_update_dataset_schema_rest_bad_request( def test_update_dataset_schema_rest_flattened(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4841,7 +5265,7 @@ def test_update_dataset_schema_rest_flattened(): def test_update_dataset_schema_rest_flattened_error(transport: str = "rest"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4857,24 +5281,24 @@ def test_update_dataset_schema_rest_flattened_error(transport: str = "rest"): def test_update_dataset_schema_rest_error(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( @@ -4884,7 +5308,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4895,16 +5319,17 @@ 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 = DocumentServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DocumentServiceClient( @@ -4916,7 +5341,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DocumentServiceClient(transport=transport) assert client.transport is transport @@ -4925,13 +5350,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DocumentServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DocumentServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4948,7 +5373,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4962,7 +5387,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DocumentServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4970,7 +5395,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4982,7 +5407,7 @@ def test_document_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DocumentServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4994,7 +5419,7 @@ def test_document_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DocumentServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5042,7 +5467,7 @@ def test_document_service_base_transport_with_credentials_file(): "google.cloud.documentai_v1beta3.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5061,7 +5486,7 @@ def test_document_service_base_transport_with_adc(): "google.cloud.documentai_v1beta3.services.document_service.transports.DocumentServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DocumentServiceTransport() adc.assert_called_once() @@ -5069,7 +5494,7 @@ def test_document_service_base_transport_with_adc(): def test_document_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DocumentServiceClient() adc.assert_called_once_with( scopes=None, @@ -5089,7 +5514,7 @@ def test_document_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5136,7 +5561,7 @@ def test_document_service_transport_create_channel(transport_class, grpc_helpers ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5164,7 +5589,7 @@ def test_document_service_transport_create_channel(transport_class, grpc_helpers ], ) def test_document_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5202,7 +5627,7 @@ def test_document_service_grpc_transport_client_cert_source_for_mtls(transport_c def test_document_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5214,7 +5639,7 @@ def test_document_service_http_transport_client_cert_source_for_mtls(): def test_document_service_rest_lro_client(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5239,7 +5664,7 @@ def test_document_service_rest_lro_client(): ) def test_document_service_host_no_port(transport_name): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com" ), @@ -5262,7 +5687,7 @@ def test_document_service_host_no_port(transport_name): ) def test_document_service_host_with_port(transport_name): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="documentai.googleapis.com:8000" ), @@ -5282,8 +5707,8 @@ def test_document_service_host_with_port(transport_name): ], ) def test_document_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DocumentServiceClient( credentials=creds1, transport=transport_name, @@ -5365,7 +5790,7 @@ def test_document_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5443,7 +5868,7 @@ def test_document_service_transport_channel_mtls_with_adc(transport_class): def test_document_service_grpc_lro_client(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5460,7 +5885,7 @@ def test_document_service_grpc_lro_client(): def test_document_service_grpc_lro_async_client(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -5665,7 +6090,7 @@ def test_client_with_default_client_info(): transports.DocumentServiceTransport, "_prep_wrapped_messages" ) as prep: client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5675,7 +6100,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DocumentServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5684,7 +6109,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5699,7 +6124,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5729,7 +6154,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -5757,7 +6182,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5785,7 +6210,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -5813,7 +6238,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5843,7 +6268,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -5871,7 +6296,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5901,7 +6326,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -5929,7 +6354,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5959,7 +6384,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations"} @@ -5985,7 +6410,7 @@ def test_list_operations_rest(request_type): def test_cancel_operation(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6010,7 +6435,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6034,7 +6459,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6063,7 +6488,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6090,7 +6515,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6108,7 +6533,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -6124,7 +6549,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6149,7 +6574,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6175,7 +6600,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6204,7 +6629,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6233,7 +6658,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6251,7 +6676,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6269,7 +6694,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6294,7 +6719,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6320,7 +6745,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6349,7 +6774,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6378,7 +6803,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6396,7 +6821,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6414,7 +6839,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6439,7 +6864,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6465,7 +6890,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6494,7 +6919,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6523,7 +6948,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6541,7 +6966,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6559,7 +6984,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6584,7 +7009,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6609,7 +7034,9 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = DocumentServiceClient(credentials=ga_credentials.AnonymousCredentials()) + client = DocumentServiceClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -6637,7 +7064,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6666,7 +7093,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6684,7 +7111,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = DocumentServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6708,7 +7135,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -6725,7 +7152,7 @@ def test_client_ctx(): ] for transport in transports: client = DocumentServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -6756,7 +7183,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, diff --git a/packages/google-cloud-domains/google/cloud/domains/gapic_version.py b/packages/google-cloud-domains/google/cloud/domains/gapic_version.py index 1aa1253ea3ab..360a0d13ebdd 100644 --- a/packages/google-cloud-domains/google/cloud/domains/gapic_version.py +++ b/packages/google-cloud-domains/google/cloud/domains/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.6.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/gapic_version.py b/packages/google-cloud-domains/google/cloud/domains_v1/gapic_version.py index 1aa1253ea3ab..360a0d13ebdd 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/gapic_version.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.6.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/async_client.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/async_client.py index 5c70b6c5017f..383f242e7234 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/async_client.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/async_client.py @@ -38,9 +38,9 @@ from google.cloud.domains_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -64,8 +64,12 @@ class DomainsAsyncClient: _client: DomainsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DomainsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DomainsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DomainsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DomainsClient._DEFAULT_UNIVERSE registration_path = staticmethod(DomainsClient.registration_path) parse_registration_path = staticmethod(DomainsClient.parse_registration_path) @@ -164,6 +168,25 @@ def transport(self) -> DomainsTransport: """ 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(DomainsClient).get_transport_class, type(DomainsClient) ) @@ -176,7 +199,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the domains client. + """Instantiates the domains async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -187,23 +210,38 @@ def __init__( transport (Union[str, ~.DomainsTransport]): 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. @@ -319,6 +357,9 @@ async def sample_search_domains(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -434,6 +475,9 @@ async def sample_retrieve_register_parameters(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -608,6 +652,9 @@ async def sample_register_domain(): 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, @@ -733,6 +780,9 @@ async def sample_retrieve_transfer_parameters(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -936,6 +986,9 @@ async def sample_transfer_domain(): 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, @@ -1049,6 +1102,9 @@ async def sample_list_registrations(): 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, @@ -1179,6 +1235,9 @@ async def sample_get_registration(): 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, @@ -1325,6 +1384,9 @@ async def sample_update_registration(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1485,6 +1547,9 @@ async def sample_configure_management_settings(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1650,6 +1715,9 @@ async def sample_configure_dns_settings(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1809,6 +1877,9 @@ async def sample_configure_contact_settings(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1953,6 +2024,9 @@ async def sample_export_registration(): 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, @@ -2097,6 +2171,9 @@ async def sample_delete_registration(): 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, @@ -2211,6 +2288,9 @@ async def sample_retrieve_authorization_code(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2317,6 +2397,9 @@ async def sample_reset_authorization_code(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/client.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/client.py index 5a92c7a78c89..c7860c715210 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/client.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.domains_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -132,11 +133,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 = "domains.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "domains.{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 @@ -287,7 +292,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 @@ -317,6 +322,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") @@ -350,6 +360,175 @@ 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 + + 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 + + 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 = DomainsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DomainsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DomainsClient._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 = DomainsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DomainsClient._DEFAULT_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 DomainsClient._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, *, @@ -369,22 +548,32 @@ def __init__( transport (Union[str, DomainsTransport]): 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. @@ -395,17 +584,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, + ) = DomainsClient._read_environment_variables() + self._client_cert_source = DomainsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = DomainsClient._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" @@ -414,20 +620,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, DomainsTransport): + transport_provided = isinstance(transport, DomainsTransport) + if transport_provided: # transport is a DomainsTransport 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(DomainsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or DomainsClient._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( @@ -437,17 +653,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 search_domains( @@ -554,6 +770,9 @@ def sample_search_domains(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -671,6 +890,9 @@ def sample_retrieve_register_parameters(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -845,6 +1067,9 @@ def sample_register_domain(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -972,6 +1197,9 @@ def sample_retrieve_transfer_parameters(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1175,6 +1403,9 @@ def sample_transfer_domain(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1288,6 +1519,9 @@ def sample_list_registrations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1418,6 +1652,9 @@ def sample_get_registration(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1564,6 +1801,9 @@ def sample_update_registration(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1726,6 +1966,9 @@ def sample_configure_management_settings(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1891,6 +2134,9 @@ def sample_configure_dns_settings(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2052,6 +2298,9 @@ def sample_configure_contact_settings(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2196,6 +2445,9 @@ def sample_export_registration(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2340,6 +2592,9 @@ def sample_delete_registration(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2456,6 +2711,9 @@ def sample_retrieve_authorization_code(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2562,6 +2820,9 @@ def sample_reset_authorization_code(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/base.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/base.py index a294185e030c..069cc510c961 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/base.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/base.py @@ -57,7 +57,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'domains.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 @@ -120,6 +120,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-domains/google/cloud/domains_v1/services/domains/transports/grpc.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc.py index 4b3805671605..ea08494c6803 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'domains.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-domains/google/cloud/domains_v1/services/domains/transports/grpc_asyncio.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc_asyncio.py index d709c6235fb9..cf188b17f091 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc_asyncio.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'domains.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-domains/google/cloud/domains_v1/services/domains/transports/rest.py b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/rest.py index 7d0e6c7275d4..8d75b1432a2e 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/rest.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1/services/domains/transports/rest.py @@ -37,9 +37,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -581,7 +581,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'domains.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-domains/google/cloud/domains_v1beta1/gapic_version.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/gapic_version.py index 1aa1253ea3ab..360a0d13ebdd 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/gapic_version.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.6.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/async_client.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/async_client.py index 9c82e35570b4..e9ce1f59c75d 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/async_client.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/async_client.py @@ -38,9 +38,9 @@ from google.cloud.domains_v1beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -64,8 +64,12 @@ class DomainsAsyncClient: _client: DomainsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = DomainsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = DomainsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = DomainsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = DomainsClient._DEFAULT_UNIVERSE registration_path = staticmethod(DomainsClient.registration_path) parse_registration_path = staticmethod(DomainsClient.parse_registration_path) @@ -164,6 +168,25 @@ def transport(self) -> DomainsTransport: """ 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(DomainsClient).get_transport_class, type(DomainsClient) ) @@ -176,7 +199,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the domains client. + """Instantiates the domains async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -187,23 +210,38 @@ def __init__( transport (Union[str, ~.DomainsTransport]): 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. @@ -319,6 +357,9 @@ async def sample_search_domains(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -434,6 +475,9 @@ async def sample_retrieve_register_parameters(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -608,6 +652,9 @@ async def sample_register_domain(): 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, @@ -733,6 +780,9 @@ async def sample_retrieve_transfer_parameters(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -936,6 +986,9 @@ async def sample_transfer_domain(): 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, @@ -1049,6 +1102,9 @@ async def sample_list_registrations(): 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, @@ -1179,6 +1235,9 @@ async def sample_get_registration(): 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, @@ -1325,6 +1384,9 @@ async def sample_update_registration(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1485,6 +1547,9 @@ async def sample_configure_management_settings(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1650,6 +1715,9 @@ async def sample_configure_dns_settings(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1809,6 +1877,9 @@ async def sample_configure_contact_settings(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1953,6 +2024,9 @@ async def sample_export_registration(): 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, @@ -2097,6 +2171,9 @@ async def sample_delete_registration(): 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, @@ -2211,6 +2288,9 @@ async def sample_retrieve_authorization_code(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2317,6 +2397,9 @@ async def sample_reset_authorization_code(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/client.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/client.py index b56d10b1761b..07c6e9bc7f85 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/client.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.domains_v1beta1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -132,11 +133,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 = "domains.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "domains.{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 @@ -287,7 +292,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 @@ -317,6 +322,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") @@ -350,6 +360,175 @@ 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 + + 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 + + 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 = DomainsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = DomainsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = DomainsClient._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 = DomainsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = DomainsClient._DEFAULT_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 DomainsClient._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, *, @@ -369,22 +548,32 @@ def __init__( transport (Union[str, DomainsTransport]): 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. @@ -395,17 +584,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, + ) = DomainsClient._read_environment_variables() + self._client_cert_source = DomainsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = DomainsClient._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" @@ -414,20 +620,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, DomainsTransport): + transport_provided = isinstance(transport, DomainsTransport) + if transport_provided: # transport is a DomainsTransport 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(DomainsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or DomainsClient._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( @@ -437,17 +653,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 search_domains( @@ -554,6 +770,9 @@ def sample_search_domains(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -671,6 +890,9 @@ def sample_retrieve_register_parameters(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -845,6 +1067,9 @@ def sample_register_domain(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -972,6 +1197,9 @@ def sample_retrieve_transfer_parameters(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1175,6 +1403,9 @@ def sample_transfer_domain(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1288,6 +1519,9 @@ def sample_list_registrations(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1418,6 +1652,9 @@ def sample_get_registration(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1564,6 +1801,9 @@ def sample_update_registration(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1726,6 +1966,9 @@ def sample_configure_management_settings(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1891,6 +2134,9 @@ def sample_configure_dns_settings(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2052,6 +2298,9 @@ def sample_configure_contact_settings(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2196,6 +2445,9 @@ def sample_export_registration(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2340,6 +2592,9 @@ def sample_delete_registration(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2456,6 +2711,9 @@ def sample_retrieve_authorization_code(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2562,6 +2820,9 @@ def sample_reset_authorization_code(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/base.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/base.py index 2403dfde25e8..0ac1b69c21fa 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/base.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/base.py @@ -57,7 +57,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'domains.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 @@ -120,6 +120,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-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc.py index 7b7a4a204c72..c07fbab243a2 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc.py @@ -65,7 +65,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'domains.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-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc_asyncio.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc_asyncio.py index 777f9d251380..a0ff9d4356b1 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc_asyncio.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/grpc_asyncio.py @@ -110,7 +110,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'domains.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-domains/google/cloud/domains_v1beta1/services/domains/transports/rest.py b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/rest.py index b48a753d1dba..338f67bf610c 100644 --- a/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/rest.py +++ b/packages/google-cloud-domains/google/cloud/domains_v1beta1/services/domains/transports/rest.py @@ -37,9 +37,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -581,7 +581,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'domains.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-domains/noxfile.py b/packages/google-cloud-domains/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-domains/noxfile.py +++ b/packages/google-cloud-domains/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-domains/samples/generated_samples/snippet_metadata_google.cloud.domains.v1.json b/packages/google-cloud-domains/samples/generated_samples/snippet_metadata_google.cloud.domains.v1.json index b0172dd4c8ff..5384077f78bd 100644 --- a/packages/google-cloud-domains/samples/generated_samples/snippet_metadata_google.cloud.domains.v1.json +++ b/packages/google-cloud-domains/samples/generated_samples/snippet_metadata_google.cloud.domains.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-domains", - "version": "1.6.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-domains/samples/generated_samples/snippet_metadata_google.cloud.domains.v1beta1.json b/packages/google-cloud-domains/samples/generated_samples/snippet_metadata_google.cloud.domains.v1beta1.json index a7fd331c71e3..7634af9e4008 100644 --- a/packages/google-cloud-domains/samples/generated_samples/snippet_metadata_google.cloud.domains.v1beta1.json +++ b/packages/google-cloud-domains/samples/generated_samples/snippet_metadata_google.cloud.domains.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-domains", - "version": "1.6.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-domains/tests/unit/gapic/domains_v1/test_domains.py b/packages/google-cloud-domains/tests/unit/gapic/domains_v1/test_domains.py index a904b0a8f8f4..7111ee7091b5 100644 --- a/packages/google-cloud-domains/tests/unit/gapic/domains_v1/test_domains.py +++ b/packages/google-cloud-domains/tests/unit/gapic/domains_v1/test_domains.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -81,6 +81,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -104,6 +127,238 @@ def test__get_default_mtls_endpoint(): assert DomainsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert DomainsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DomainsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DomainsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DomainsClient._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 DomainsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DomainsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DomainsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DomainsClient._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 DomainsClient._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 DomainsClient._get_client_cert_source(None, False) is None + assert ( + DomainsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + DomainsClient._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 ( + DomainsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DomainsClient._get_client_cert_source(mock_provided_cert_source, "true") + is mock_provided_cert_source + ) + + +@mock.patch.object( + DomainsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsClient), +) +@mock.patch.object( + DomainsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DomainsClient._DEFAULT_UNIVERSE + default_endpoint = DomainsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DomainsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DomainsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DomainsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DomainsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DomainsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DomainsClient._get_api_endpoint(None, None, default_universe, "always") + == DomainsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DomainsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DomainsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DomainsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DomainsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DomainsClient._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 ( + DomainsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + DomainsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DomainsClient._get_universe_domain(None, None) + == DomainsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DomainsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DomainsClient, transports.DomainsGrpcTransport, "grpc"), + (DomainsClient, transports.DomainsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -113,7 +368,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_domains_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -163,7 +418,7 @@ def test_domains_client_service_account_always_use_jwt(transport_class, transpor ], ) def test_domains_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -208,15 +463,21 @@ def test_domains_client_get_transport_class(): ], ) @mock.patch.object( - DomainsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DomainsClient) + DomainsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsClient), ) @mock.patch.object( - DomainsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DomainsAsyncClient) + DomainsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsAsyncClient), ) def test_domains_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(DomainsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -251,7 +512,9 @@ def test_domains_client_client_options(client_class, transport_class, transport_ 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, @@ -281,15 +544,23 @@ def test_domains_client_client_options(client_class, transport_class, transport_ # 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") @@ -299,7 +570,9 @@ def test_domains_client_client_options(client_class, transport_class, transport_ 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", @@ -317,7 +590,9 @@ def test_domains_client_client_options(client_class, transport_class, transport_ 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, @@ -349,10 +624,14 @@ def test_domains_client_client_options(client_class, transport_class, transport_ ], ) @mock.patch.object( - DomainsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DomainsClient) + DomainsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsClient), ) @mock.patch.object( - DomainsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DomainsAsyncClient) + DomainsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_domains_client_mtls_env_auto( @@ -375,7 +654,9 @@ def test_domains_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 @@ -407,7 +688,9 @@ def test_domains_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 @@ -441,7 +724,9 @@ def test_domains_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, @@ -525,6 +810,116 @@ def test_domains_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", [DomainsClient, DomainsAsyncClient]) +@mock.patch.object( + DomainsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsClient), +) +@mock.patch.object( + DomainsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsAsyncClient), +) +def test_domains_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DomainsClient._DEFAULT_UNIVERSE + default_endpoint = DomainsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DomainsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -547,7 +942,9 @@ def test_domains_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, @@ -582,7 +979,9 @@ def test_domains_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, @@ -635,7 +1034,9 @@ def test_domains_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, @@ -652,8 +1053,8 @@ def test_domains_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -682,7 +1083,7 @@ def test_domains_client_create_channel_credentials_file( ) def test_search_domains(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -709,7 +1110,7 @@ def test_search_domains_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -726,7 +1127,7 @@ async def test_search_domains_async( transport: str = "grpc_asyncio", request_type=domains.SearchDomainsRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -758,7 +1159,7 @@ async def test_search_domains_async_from_dict(): def test_search_domains_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -788,7 +1189,7 @@ def test_search_domains_field_headers(): @pytest.mark.asyncio async def test_search_domains_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -819,7 +1220,7 @@ async def test_search_domains_field_headers_async(): def test_search_domains_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -847,7 +1248,7 @@ def test_search_domains_flattened(): def test_search_domains_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -863,7 +1264,7 @@ def test_search_domains_flattened_error(): @pytest.mark.asyncio async def test_search_domains_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -896,7 +1297,7 @@ async def test_search_domains_flattened_async(): @pytest.mark.asyncio async def test_search_domains_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -918,7 +1319,7 @@ async def test_search_domains_flattened_error_async(): ) def test_retrieve_register_parameters(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -947,7 +1348,7 @@ def test_retrieve_register_parameters_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -967,7 +1368,7 @@ async def test_retrieve_register_parameters_async( request_type=domains.RetrieveRegisterParametersRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1001,7 +1402,7 @@ async def test_retrieve_register_parameters_async_from_dict(): def test_retrieve_register_parameters_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1033,7 +1434,7 @@ def test_retrieve_register_parameters_field_headers(): @pytest.mark.asyncio async def test_retrieve_register_parameters_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1066,7 +1467,7 @@ async def test_retrieve_register_parameters_field_headers_async(): def test_retrieve_register_parameters_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1096,7 +1497,7 @@ def test_retrieve_register_parameters_flattened(): def test_retrieve_register_parameters_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1112,7 +1513,7 @@ def test_retrieve_register_parameters_flattened_error(): @pytest.mark.asyncio async def test_retrieve_register_parameters_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1147,7 +1548,7 @@ async def test_retrieve_register_parameters_flattened_async(): @pytest.mark.asyncio async def test_retrieve_register_parameters_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1169,7 +1570,7 @@ async def test_retrieve_register_parameters_flattened_error_async(): ) def test_register_domain(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1196,7 +1597,7 @@ def test_register_domain_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1213,7 +1614,7 @@ async def test_register_domain_async( transport: str = "grpc_asyncio", request_type=domains.RegisterDomainRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1245,7 +1646,7 @@ async def test_register_domain_async_from_dict(): def test_register_domain_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1275,7 +1676,7 @@ def test_register_domain_field_headers(): @pytest.mark.asyncio async def test_register_domain_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1306,7 +1707,7 @@ async def test_register_domain_field_headers_async(): def test_register_domain_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1338,7 +1739,7 @@ def test_register_domain_flattened(): def test_register_domain_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1355,7 +1756,7 @@ def test_register_domain_flattened_error(): @pytest.mark.asyncio async def test_register_domain_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1392,7 +1793,7 @@ async def test_register_domain_flattened_async(): @pytest.mark.asyncio async def test_register_domain_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1415,7 +1816,7 @@ async def test_register_domain_flattened_error_async(): ) def test_retrieve_transfer_parameters(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1444,7 +1845,7 @@ def test_retrieve_transfer_parameters_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1464,7 +1865,7 @@ async def test_retrieve_transfer_parameters_async( request_type=domains.RetrieveTransferParametersRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1498,7 +1899,7 @@ async def test_retrieve_transfer_parameters_async_from_dict(): def test_retrieve_transfer_parameters_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1530,7 +1931,7 @@ def test_retrieve_transfer_parameters_field_headers(): @pytest.mark.asyncio async def test_retrieve_transfer_parameters_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1563,7 +1964,7 @@ async def test_retrieve_transfer_parameters_field_headers_async(): def test_retrieve_transfer_parameters_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1593,7 +1994,7 @@ def test_retrieve_transfer_parameters_flattened(): def test_retrieve_transfer_parameters_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1609,7 +2010,7 @@ def test_retrieve_transfer_parameters_flattened_error(): @pytest.mark.asyncio async def test_retrieve_transfer_parameters_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1644,7 +2045,7 @@ async def test_retrieve_transfer_parameters_flattened_async(): @pytest.mark.asyncio async def test_retrieve_transfer_parameters_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1666,7 +2067,7 @@ async def test_retrieve_transfer_parameters_flattened_error_async(): ) def test_transfer_domain(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1693,7 +2094,7 @@ def test_transfer_domain_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1710,7 +2111,7 @@ async def test_transfer_domain_async( transport: str = "grpc_asyncio", request_type=domains.TransferDomainRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1742,7 +2143,7 @@ async def test_transfer_domain_async_from_dict(): def test_transfer_domain_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1772,7 +2173,7 @@ def test_transfer_domain_field_headers(): @pytest.mark.asyncio async def test_transfer_domain_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1803,7 +2204,7 @@ async def test_transfer_domain_field_headers_async(): def test_transfer_domain_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1839,7 +2240,7 @@ def test_transfer_domain_flattened(): def test_transfer_domain_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1857,7 +2258,7 @@ def test_transfer_domain_flattened_error(): @pytest.mark.asyncio async def test_transfer_domain_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1898,7 +2299,7 @@ async def test_transfer_domain_flattened_async(): @pytest.mark.asyncio async def test_transfer_domain_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1922,7 +2323,7 @@ async def test_transfer_domain_flattened_error_async(): ) def test_list_registrations(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1954,7 +2355,7 @@ def test_list_registrations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1973,7 +2374,7 @@ async def test_list_registrations_async( transport: str = "grpc_asyncio", request_type=domains.ListRegistrationsRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2010,7 +2411,7 @@ async def test_list_registrations_async_from_dict(): def test_list_registrations_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2042,7 +2443,7 @@ def test_list_registrations_field_headers(): @pytest.mark.asyncio async def test_list_registrations_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2075,7 +2476,7 @@ async def test_list_registrations_field_headers_async(): def test_list_registrations_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2101,7 +2502,7 @@ def test_list_registrations_flattened(): def test_list_registrations_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2116,7 +2517,7 @@ def test_list_registrations_flattened_error(): @pytest.mark.asyncio async def test_list_registrations_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2147,7 +2548,7 @@ async def test_list_registrations_flattened_async(): @pytest.mark.asyncio async def test_list_registrations_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2161,7 +2562,7 @@ async def test_list_registrations_flattened_error_async(): def test_list_registrations_pager(transport_name: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2213,7 +2614,7 @@ def test_list_registrations_pager(transport_name: str = "grpc"): def test_list_registrations_pages(transport_name: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2257,7 +2658,7 @@ def test_list_registrations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_registrations_async_pager(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2309,7 +2710,7 @@ async def test_list_registrations_async_pager(): @pytest.mark.asyncio async def test_list_registrations_async_pages(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2366,7 +2767,7 @@ async def test_list_registrations_async_pages(): ) def test_get_registration(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2404,7 +2805,7 @@ def test_get_registration_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2421,7 +2822,7 @@ async def test_get_registration_async( transport: str = "grpc_asyncio", request_type=domains.GetRegistrationRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2464,7 +2865,7 @@ async def test_get_registration_async_from_dict(): def test_get_registration_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2494,7 +2895,7 @@ def test_get_registration_field_headers(): @pytest.mark.asyncio async def test_get_registration_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2525,7 +2926,7 @@ async def test_get_registration_field_headers_async(): def test_get_registration_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2549,7 +2950,7 @@ def test_get_registration_flattened(): def test_get_registration_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2564,7 +2965,7 @@ def test_get_registration_flattened_error(): @pytest.mark.asyncio async def test_get_registration_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2593,7 +2994,7 @@ async def test_get_registration_flattened_async(): @pytest.mark.asyncio async def test_get_registration_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2614,7 +3015,7 @@ async def test_get_registration_flattened_error_async(): ) def test_update_registration(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2643,7 +3044,7 @@ def test_update_registration_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2662,7 +3063,7 @@ async def test_update_registration_async( transport: str = "grpc_asyncio", request_type=domains.UpdateRegistrationRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2696,7 +3097,7 @@ async def test_update_registration_async_from_dict(): def test_update_registration_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2728,7 +3129,7 @@ def test_update_registration_field_headers(): @pytest.mark.asyncio async def test_update_registration_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2761,7 +3162,7 @@ async def test_update_registration_field_headers_async(): def test_update_registration_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2791,7 +3192,7 @@ def test_update_registration_flattened(): def test_update_registration_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2807,7 +3208,7 @@ def test_update_registration_flattened_error(): @pytest.mark.asyncio async def test_update_registration_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2842,7 +3243,7 @@ async def test_update_registration_flattened_async(): @pytest.mark.asyncio async def test_update_registration_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2864,7 +3265,7 @@ async def test_update_registration_flattened_error_async(): ) def test_configure_management_settings(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2893,7 +3294,7 @@ def test_configure_management_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2913,7 +3314,7 @@ async def test_configure_management_settings_async( request_type=domains.ConfigureManagementSettingsRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2947,7 +3348,7 @@ async def test_configure_management_settings_async_from_dict(): def test_configure_management_settings_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2979,7 +3380,7 @@ def test_configure_management_settings_field_headers(): @pytest.mark.asyncio async def test_configure_management_settings_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3012,7 +3413,7 @@ async def test_configure_management_settings_field_headers_async(): def test_configure_management_settings_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3050,7 +3451,7 @@ def test_configure_management_settings_flattened(): def test_configure_management_settings_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3069,7 +3470,7 @@ def test_configure_management_settings_flattened_error(): @pytest.mark.asyncio async def test_configure_management_settings_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3112,7 +3513,7 @@ async def test_configure_management_settings_flattened_async(): @pytest.mark.asyncio async def test_configure_management_settings_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3137,7 +3538,7 @@ async def test_configure_management_settings_flattened_error_async(): ) def test_configure_dns_settings(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3166,7 +3567,7 @@ def test_configure_dns_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3185,7 +3586,7 @@ async def test_configure_dns_settings_async( transport: str = "grpc_asyncio", request_type=domains.ConfigureDnsSettingsRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3219,7 +3620,7 @@ async def test_configure_dns_settings_async_from_dict(): def test_configure_dns_settings_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3251,7 +3652,7 @@ def test_configure_dns_settings_field_headers(): @pytest.mark.asyncio async def test_configure_dns_settings_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3284,7 +3685,7 @@ async def test_configure_dns_settings_field_headers_async(): def test_configure_dns_settings_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3326,7 +3727,7 @@ def test_configure_dns_settings_flattened(): def test_configure_dns_settings_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3347,7 +3748,7 @@ def test_configure_dns_settings_flattened_error(): @pytest.mark.asyncio async def test_configure_dns_settings_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3394,7 +3795,7 @@ async def test_configure_dns_settings_flattened_async(): @pytest.mark.asyncio async def test_configure_dns_settings_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3421,7 +3822,7 @@ async def test_configure_dns_settings_flattened_error_async(): ) def test_configure_contact_settings(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3450,7 +3851,7 @@ def test_configure_contact_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3470,7 +3871,7 @@ async def test_configure_contact_settings_async( request_type=domains.ConfigureContactSettingsRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3504,7 +3905,7 @@ async def test_configure_contact_settings_async_from_dict(): def test_configure_contact_settings_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3536,7 +3937,7 @@ def test_configure_contact_settings_field_headers(): @pytest.mark.asyncio async def test_configure_contact_settings_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3569,7 +3970,7 @@ async def test_configure_contact_settings_field_headers_async(): def test_configure_contact_settings_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3607,7 +4008,7 @@ def test_configure_contact_settings_flattened(): def test_configure_contact_settings_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3626,7 +4027,7 @@ def test_configure_contact_settings_flattened_error(): @pytest.mark.asyncio async def test_configure_contact_settings_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3669,7 +4070,7 @@ async def test_configure_contact_settings_flattened_async(): @pytest.mark.asyncio async def test_configure_contact_settings_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3694,7 +4095,7 @@ async def test_configure_contact_settings_flattened_error_async(): ) def test_export_registration(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3723,7 +4124,7 @@ def test_export_registration_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3742,7 +4143,7 @@ async def test_export_registration_async( transport: str = "grpc_asyncio", request_type=domains.ExportRegistrationRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3776,7 +4177,7 @@ async def test_export_registration_async_from_dict(): def test_export_registration_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3808,7 +4209,7 @@ def test_export_registration_field_headers(): @pytest.mark.asyncio async def test_export_registration_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3841,7 +4242,7 @@ async def test_export_registration_field_headers_async(): def test_export_registration_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3867,7 +4268,7 @@ def test_export_registration_flattened(): def test_export_registration_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3882,7 +4283,7 @@ def test_export_registration_flattened_error(): @pytest.mark.asyncio async def test_export_registration_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3913,7 +4314,7 @@ async def test_export_registration_flattened_async(): @pytest.mark.asyncio async def test_export_registration_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3934,7 +4335,7 @@ async def test_export_registration_flattened_error_async(): ) def test_delete_registration(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3963,7 +4364,7 @@ def test_delete_registration_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3982,7 +4383,7 @@ async def test_delete_registration_async( transport: str = "grpc_asyncio", request_type=domains.DeleteRegistrationRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4016,7 +4417,7 @@ async def test_delete_registration_async_from_dict(): def test_delete_registration_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4048,7 +4449,7 @@ def test_delete_registration_field_headers(): @pytest.mark.asyncio async def test_delete_registration_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4081,7 +4482,7 @@ async def test_delete_registration_field_headers_async(): def test_delete_registration_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4107,7 +4508,7 @@ def test_delete_registration_flattened(): def test_delete_registration_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4122,7 +4523,7 @@ def test_delete_registration_flattened_error(): @pytest.mark.asyncio async def test_delete_registration_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4153,7 +4554,7 @@ async def test_delete_registration_flattened_async(): @pytest.mark.asyncio async def test_delete_registration_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4174,7 +4575,7 @@ async def test_delete_registration_flattened_error_async(): ) def test_retrieve_authorization_code(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4206,7 +4607,7 @@ def test_retrieve_authorization_code_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4226,7 +4627,7 @@ async def test_retrieve_authorization_code_async( request_type=domains.RetrieveAuthorizationCodeRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4263,7 +4664,7 @@ async def test_retrieve_authorization_code_async_from_dict(): def test_retrieve_authorization_code_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4295,7 +4696,7 @@ def test_retrieve_authorization_code_field_headers(): @pytest.mark.asyncio async def test_retrieve_authorization_code_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4328,7 +4729,7 @@ async def test_retrieve_authorization_code_field_headers_async(): def test_retrieve_authorization_code_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4354,7 +4755,7 @@ def test_retrieve_authorization_code_flattened(): def test_retrieve_authorization_code_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4369,7 +4770,7 @@ def test_retrieve_authorization_code_flattened_error(): @pytest.mark.asyncio async def test_retrieve_authorization_code_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4400,7 +4801,7 @@ async def test_retrieve_authorization_code_flattened_async(): @pytest.mark.asyncio async def test_retrieve_authorization_code_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4421,7 +4822,7 @@ async def test_retrieve_authorization_code_flattened_error_async(): ) def test_reset_authorization_code(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4453,7 +4854,7 @@ def test_reset_authorization_code_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4472,7 +4873,7 @@ async def test_reset_authorization_code_async( transport: str = "grpc_asyncio", request_type=domains.ResetAuthorizationCodeRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4509,7 +4910,7 @@ async def test_reset_authorization_code_async_from_dict(): def test_reset_authorization_code_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4541,7 +4942,7 @@ def test_reset_authorization_code_field_headers(): @pytest.mark.asyncio async def test_reset_authorization_code_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4574,7 +4975,7 @@ async def test_reset_authorization_code_field_headers_async(): def test_reset_authorization_code_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4600,7 +5001,7 @@ def test_reset_authorization_code_flattened(): def test_reset_authorization_code_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4615,7 +5016,7 @@ def test_reset_authorization_code_flattened_error(): @pytest.mark.asyncio async def test_reset_authorization_code_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4646,7 +5047,7 @@ async def test_reset_authorization_code_flattened_async(): @pytest.mark.asyncio async def test_reset_authorization_code_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4667,7 +5068,7 @@ async def test_reset_authorization_code_flattened_error_async(): ) def test_search_domains_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4715,7 +5116,7 @@ def test_search_domains_rest_required_fields(request_type=domains.SearchDomainsR assert "query" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_domains._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4727,7 +5128,7 @@ def test_search_domains_rest_required_fields(request_type=domains.SearchDomainsR jsonified_request["location"] = "location_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_domains._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("query",)) @@ -4740,7 +5141,7 @@ def test_search_domains_rest_required_fields(request_type=domains.SearchDomainsR assert jsonified_request["location"] == "location_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4788,7 +5189,7 @@ def test_search_domains_rest_required_fields(request_type=domains.SearchDomainsR def test_search_domains_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search_domains._get_unset_required_fields({}) @@ -4806,7 +5207,7 @@ def test_search_domains_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_domains_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -4860,7 +5261,7 @@ def test_search_domains_rest_bad_request( transport: str = "rest", request_type=domains.SearchDomainsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4882,7 +5283,7 @@ def test_search_domains_rest_bad_request( def test_search_domains_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4925,7 +5326,7 @@ def test_search_domains_rest_flattened(): def test_search_domains_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4941,7 +5342,7 @@ def test_search_domains_rest_flattened_error(transport: str = "rest"): def test_search_domains_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4954,7 +5355,7 @@ def test_search_domains_rest_error(): ) def test_retrieve_register_parameters_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5004,7 +5405,7 @@ def test_retrieve_register_parameters_rest_required_fields( assert "domainName" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_register_parameters._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5016,7 +5417,7 @@ def test_retrieve_register_parameters_rest_required_fields( jsonified_request["location"] = "location_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_register_parameters._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("domain_name",)) @@ -5029,7 +5430,7 @@ def test_retrieve_register_parameters_rest_required_fields( assert jsonified_request["location"] == "location_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5077,7 +5478,7 @@ def test_retrieve_register_parameters_rest_required_fields( def test_retrieve_register_parameters_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.retrieve_register_parameters._get_unset_required_fields({}) @@ -5095,7 +5496,7 @@ def test_retrieve_register_parameters_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_retrieve_register_parameters_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -5151,7 +5552,7 @@ def test_retrieve_register_parameters_rest_bad_request( transport: str = "rest", request_type=domains.RetrieveRegisterParametersRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5173,7 +5574,7 @@ def test_retrieve_register_parameters_rest_bad_request( def test_retrieve_register_parameters_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5216,7 +5617,7 @@ def test_retrieve_register_parameters_rest_flattened(): def test_retrieve_register_parameters_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5232,7 +5633,7 @@ def test_retrieve_register_parameters_rest_flattened_error(transport: str = "res def test_retrieve_register_parameters_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5245,7 +5646,7 @@ def test_retrieve_register_parameters_rest_error(): ) def test_register_domain_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5291,7 +5692,7 @@ def test_register_domain_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).register_domain._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5300,7 +5701,7 @@ def test_register_domain_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).register_domain._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5309,7 +5710,7 @@ def test_register_domain_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5349,7 +5750,7 @@ def test_register_domain_rest_required_fields( def test_register_domain_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.register_domain._get_unset_required_fields({}) @@ -5368,7 +5769,7 @@ def test_register_domain_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_register_domain_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -5424,7 +5825,7 @@ def test_register_domain_rest_bad_request( transport: str = "rest", request_type=domains.RegisterDomainRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5446,7 +5847,7 @@ def test_register_domain_rest_bad_request( def test_register_domain_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5488,7 +5889,7 @@ def test_register_domain_rest_flattened(): def test_register_domain_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5505,7 +5906,7 @@ def test_register_domain_rest_flattened_error(transport: str = "rest"): def test_register_domain_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5518,7 +5919,7 @@ def test_register_domain_rest_error(): ) def test_retrieve_transfer_parameters_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5568,7 +5969,7 @@ def test_retrieve_transfer_parameters_rest_required_fields( assert "domainName" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_transfer_parameters._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5580,7 +5981,7 @@ def test_retrieve_transfer_parameters_rest_required_fields( jsonified_request["location"] = "location_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_transfer_parameters._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("domain_name",)) @@ -5593,7 +5994,7 @@ def test_retrieve_transfer_parameters_rest_required_fields( assert jsonified_request["location"] == "location_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5641,7 +6042,7 @@ def test_retrieve_transfer_parameters_rest_required_fields( def test_retrieve_transfer_parameters_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.retrieve_transfer_parameters._get_unset_required_fields({}) @@ -5659,7 +6060,7 @@ def test_retrieve_transfer_parameters_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_retrieve_transfer_parameters_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -5715,7 +6116,7 @@ def test_retrieve_transfer_parameters_rest_bad_request( transport: str = "rest", request_type=domains.RetrieveTransferParametersRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5737,7 +6138,7 @@ def test_retrieve_transfer_parameters_rest_bad_request( def test_retrieve_transfer_parameters_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5780,7 +6181,7 @@ def test_retrieve_transfer_parameters_rest_flattened(): def test_retrieve_transfer_parameters_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5796,7 +6197,7 @@ def test_retrieve_transfer_parameters_rest_flattened_error(transport: str = "res def test_retrieve_transfer_parameters_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5809,7 +6210,7 @@ def test_retrieve_transfer_parameters_rest_error(): ) def test_transfer_domain_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5855,7 +6256,7 @@ def test_transfer_domain_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).transfer_domain._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5864,7 +6265,7 @@ def test_transfer_domain_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).transfer_domain._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5873,7 +6274,7 @@ def test_transfer_domain_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5913,7 +6314,7 @@ def test_transfer_domain_rest_required_fields( def test_transfer_domain_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.transfer_domain._get_unset_required_fields({}) @@ -5932,7 +6333,7 @@ def test_transfer_domain_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_transfer_domain_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -5988,7 +6389,7 @@ def test_transfer_domain_rest_bad_request( transport: str = "rest", request_type=domains.TransferDomainRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6010,7 +6411,7 @@ def test_transfer_domain_rest_bad_request( def test_transfer_domain_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6053,7 +6454,7 @@ def test_transfer_domain_rest_flattened(): def test_transfer_domain_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6071,7 +6472,7 @@ def test_transfer_domain_rest_flattened_error(transport: str = "rest"): def test_transfer_domain_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6084,7 +6485,7 @@ def test_transfer_domain_rest_error(): ) def test_list_registrations_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6135,7 +6536,7 @@ def test_list_registrations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_registrations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6144,7 +6545,7 @@ def test_list_registrations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_registrations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6161,7 +6562,7 @@ def test_list_registrations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6203,7 +6604,7 @@ def test_list_registrations_rest_required_fields( def test_list_registrations_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_registrations._get_unset_required_fields({}) @@ -6222,7 +6623,7 @@ def test_list_registrations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_registrations_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -6278,7 +6679,7 @@ def test_list_registrations_rest_bad_request( transport: str = "rest", request_type=domains.ListRegistrationsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6300,7 +6701,7 @@ def test_list_registrations_rest_bad_request( def test_list_registrations_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6342,7 +6743,7 @@ def test_list_registrations_rest_flattened(): def test_list_registrations_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6357,7 +6758,7 @@ def test_list_registrations_rest_flattened_error(transport: str = "rest"): def test_list_registrations_rest_pager(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6425,7 +6826,7 @@ def test_list_registrations_rest_pager(transport: str = "rest"): ) def test_get_registration_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6484,7 +6885,7 @@ def test_get_registration_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6493,7 +6894,7 @@ def test_get_registration_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6502,7 +6903,7 @@ def test_get_registration_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6544,7 +6945,7 @@ def test_get_registration_rest_required_fields( def test_get_registration_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_registration._get_unset_required_fields({}) @@ -6554,7 +6955,7 @@ def test_get_registration_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_registration_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -6606,7 +7007,7 @@ def test_get_registration_rest_bad_request( transport: str = "rest", request_type=domains.GetRegistrationRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6628,7 +7029,7 @@ def test_get_registration_rest_bad_request( def test_get_registration_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6672,7 +7073,7 @@ def test_get_registration_rest_flattened(): def test_get_registration_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6687,7 +7088,7 @@ def test_get_registration_rest_flattened_error(transport: str = "rest"): def test_get_registration_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6700,7 +7101,7 @@ def test_get_registration_rest_error(): ) def test_update_registration_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6882,14 +7283,14 @@ def test_update_registration_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_registration._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -6898,7 +7299,7 @@ def test_update_registration_rest_required_fields( # verify required fields with non-default values are left alone client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6938,7 +7339,7 @@ def test_update_registration_rest_required_fields( def test_update_registration_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_registration._get_unset_required_fields({}) @@ -6948,7 +7349,7 @@ def test_update_registration_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_registration_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -7006,7 +7407,7 @@ def test_update_registration_rest_bad_request( transport: str = "rest", request_type=domains.UpdateRegistrationRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7032,7 +7433,7 @@ def test_update_registration_rest_bad_request( def test_update_registration_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7077,7 +7478,7 @@ def test_update_registration_rest_flattened(): def test_update_registration_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7093,7 +7494,7 @@ def test_update_registration_rest_flattened_error(transport: str = "rest"): def test_update_registration_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7106,7 +7507,7 @@ def test_update_registration_rest_error(): ) def test_configure_management_settings_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7154,7 +7555,7 @@ def test_configure_management_settings_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_management_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7163,7 +7564,7 @@ def test_configure_management_settings_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_management_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7172,7 +7573,7 @@ def test_configure_management_settings_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7212,7 +7613,7 @@ def test_configure_management_settings_rest_required_fields( def test_configure_management_settings_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.configure_management_settings._get_unset_required_fields( @@ -7232,7 +7633,7 @@ def test_configure_management_settings_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_configure_management_settings_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -7290,7 +7691,7 @@ def test_configure_management_settings_rest_bad_request( transport: str = "rest", request_type=domains.ConfigureManagementSettingsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7314,7 +7715,7 @@ def test_configure_management_settings_rest_bad_request( def test_configure_management_settings_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7360,7 +7761,7 @@ def test_configure_management_settings_rest_flattened(): def test_configure_management_settings_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7379,7 +7780,7 @@ def test_configure_management_settings_rest_flattened_error(transport: str = "re def test_configure_management_settings_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7392,7 +7793,7 @@ def test_configure_management_settings_rest_error(): ) def test_configure_dns_settings_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7440,7 +7841,7 @@ def test_configure_dns_settings_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_dns_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7449,7 +7850,7 @@ def test_configure_dns_settings_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_dns_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7458,7 +7859,7 @@ def test_configure_dns_settings_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7498,7 +7899,7 @@ def test_configure_dns_settings_rest_required_fields( def test_configure_dns_settings_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.configure_dns_settings._get_unset_required_fields({}) @@ -7516,7 +7917,7 @@ def test_configure_dns_settings_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_configure_dns_settings_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -7574,7 +7975,7 @@ def test_configure_dns_settings_rest_bad_request( transport: str = "rest", request_type=domains.ConfigureDnsSettingsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7598,7 +7999,7 @@ def test_configure_dns_settings_rest_bad_request( def test_configure_dns_settings_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7646,7 +8047,7 @@ def test_configure_dns_settings_rest_flattened(): def test_configure_dns_settings_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7667,7 +8068,7 @@ def test_configure_dns_settings_rest_flattened_error(transport: str = "rest"): def test_configure_dns_settings_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7680,7 +8081,7 @@ def test_configure_dns_settings_rest_error(): ) def test_configure_contact_settings_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7728,7 +8129,7 @@ def test_configure_contact_settings_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_contact_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7737,7 +8138,7 @@ def test_configure_contact_settings_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_contact_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7746,7 +8147,7 @@ def test_configure_contact_settings_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7786,7 +8187,7 @@ def test_configure_contact_settings_rest_required_fields( def test_configure_contact_settings_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.configure_contact_settings._get_unset_required_fields({}) @@ -7804,7 +8205,7 @@ def test_configure_contact_settings_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_configure_contact_settings_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -7862,7 +8263,7 @@ def test_configure_contact_settings_rest_bad_request( transport: str = "rest", request_type=domains.ConfigureContactSettingsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7886,7 +8287,7 @@ def test_configure_contact_settings_rest_bad_request( def test_configure_contact_settings_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7932,7 +8333,7 @@ def test_configure_contact_settings_rest_flattened(): def test_configure_contact_settings_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7951,7 +8352,7 @@ def test_configure_contact_settings_rest_flattened_error(transport: str = "rest" def test_configure_contact_settings_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7964,7 +8365,7 @@ def test_configure_contact_settings_rest_error(): ) def test_export_registration_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8010,7 +8411,7 @@ def test_export_registration_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8019,7 +8420,7 @@ def test_export_registration_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8028,7 +8429,7 @@ def test_export_registration_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8068,7 +8469,7 @@ def test_export_registration_rest_required_fields( def test_export_registration_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.export_registration._get_unset_required_fields({}) @@ -8078,7 +8479,7 @@ def test_export_registration_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_export_registration_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -8136,7 +8537,7 @@ def test_export_registration_rest_bad_request( transport: str = "rest", request_type=domains.ExportRegistrationRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8158,7 +8559,7 @@ def test_export_registration_rest_bad_request( def test_export_registration_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8200,7 +8601,7 @@ def test_export_registration_rest_flattened(): def test_export_registration_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8215,7 +8616,7 @@ def test_export_registration_rest_flattened_error(transport: str = "rest"): def test_export_registration_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8228,7 +8629,7 @@ def test_export_registration_rest_error(): ) def test_delete_registration_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8274,7 +8675,7 @@ def test_delete_registration_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8283,7 +8684,7 @@ def test_delete_registration_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8292,7 +8693,7 @@ def test_delete_registration_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8331,7 +8732,7 @@ def test_delete_registration_rest_required_fields( def test_delete_registration_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_registration._get_unset_required_fields({}) @@ -8341,7 +8742,7 @@ def test_delete_registration_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_registration_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -8399,7 +8800,7 @@ def test_delete_registration_rest_bad_request( transport: str = "rest", request_type=domains.DeleteRegistrationRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8421,7 +8822,7 @@ def test_delete_registration_rest_bad_request( def test_delete_registration_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8463,7 +8864,7 @@ def test_delete_registration_rest_flattened(): def test_delete_registration_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8478,7 +8879,7 @@ def test_delete_registration_rest_flattened_error(transport: str = "rest"): def test_delete_registration_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8491,7 +8892,7 @@ def test_delete_registration_rest_error(): ) def test_retrieve_authorization_code_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8544,7 +8945,7 @@ def test_retrieve_authorization_code_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_authorization_code._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8553,7 +8954,7 @@ def test_retrieve_authorization_code_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_authorization_code._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8562,7 +8963,7 @@ def test_retrieve_authorization_code_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8604,7 +9005,7 @@ def test_retrieve_authorization_code_rest_required_fields( def test_retrieve_authorization_code_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.retrieve_authorization_code._get_unset_required_fields({}) @@ -8614,7 +9015,7 @@ def test_retrieve_authorization_code_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_retrieve_authorization_code_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -8670,7 +9071,7 @@ def test_retrieve_authorization_code_rest_bad_request( transport: str = "rest", request_type=domains.RetrieveAuthorizationCodeRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8694,7 +9095,7 @@ def test_retrieve_authorization_code_rest_bad_request( def test_retrieve_authorization_code_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8738,7 +9139,7 @@ def test_retrieve_authorization_code_rest_flattened(): def test_retrieve_authorization_code_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8753,7 +9154,7 @@ def test_retrieve_authorization_code_rest_flattened_error(transport: str = "rest def test_retrieve_authorization_code_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8766,7 +9167,7 @@ def test_retrieve_authorization_code_rest_error(): ) def test_reset_authorization_code_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8819,7 +9220,7 @@ def test_reset_authorization_code_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reset_authorization_code._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8828,7 +9229,7 @@ def test_reset_authorization_code_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reset_authorization_code._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8837,7 +9238,7 @@ def test_reset_authorization_code_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8880,7 +9281,7 @@ def test_reset_authorization_code_rest_required_fields( def test_reset_authorization_code_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.reset_authorization_code._get_unset_required_fields({}) @@ -8890,7 +9291,7 @@ def test_reset_authorization_code_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_reset_authorization_code_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -8946,7 +9347,7 @@ def test_reset_authorization_code_rest_bad_request( transport: str = "rest", request_type=domains.ResetAuthorizationCodeRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8970,7 +9371,7 @@ def test_reset_authorization_code_rest_bad_request( def test_reset_authorization_code_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9014,7 +9415,7 @@ def test_reset_authorization_code_rest_flattened(): def test_reset_authorization_code_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9029,24 +9430,24 @@ def test_reset_authorization_code_rest_flattened_error(transport: str = "rest"): def test_reset_authorization_code_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DomainsClient( @@ -9056,7 +9457,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -9067,16 +9468,17 @@ 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 = DomainsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DomainsClient( @@ -9088,7 +9490,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DomainsClient(transport=transport) assert client.transport is transport @@ -9097,13 +9499,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DomainsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -9120,7 +9522,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -9134,7 +9536,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DomainsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -9142,7 +9544,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -9154,7 +9556,7 @@ def test_domains_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DomainsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -9166,7 +9568,7 @@ def test_domains_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DomainsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -9217,7 +9619,7 @@ def test_domains_base_transport_with_credentials_file(): "google.cloud.domains_v1.services.domains.transports.DomainsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DomainsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -9236,7 +9638,7 @@ def test_domains_base_transport_with_adc(): "google.cloud.domains_v1.services.domains.transports.DomainsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DomainsTransport() adc.assert_called_once() @@ -9244,7 +9646,7 @@ def test_domains_base_transport_with_adc(): def test_domains_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DomainsClient() adc.assert_called_once_with( scopes=None, @@ -9264,7 +9666,7 @@ def test_domains_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -9311,7 +9713,7 @@ def test_domains_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9336,7 +9738,7 @@ def test_domains_transport_create_channel(transport_class, grpc_helpers): [transports.DomainsGrpcTransport, transports.DomainsGrpcAsyncIOTransport], ) def test_domains_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -9374,7 +9776,7 @@ def test_domains_grpc_transport_client_cert_source_for_mtls(transport_class): def test_domains_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -9386,7 +9788,7 @@ def test_domains_http_transport_client_cert_source_for_mtls(): def test_domains_rest_lro_client(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -9411,7 +9813,7 @@ def test_domains_rest_lro_client(): ) def test_domains_host_no_port(transport_name): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="domains.googleapis.com" ), @@ -9434,7 +9836,7 @@ def test_domains_host_no_port(transport_name): ) def test_domains_host_with_port(transport_name): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="domains.googleapis.com:8000" ), @@ -9454,8 +9856,8 @@ def test_domains_host_with_port(transport_name): ], ) def test_domains_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DomainsClient( credentials=creds1, transport=transport_name, @@ -9556,7 +9958,7 @@ def test_domains_transport_channel_mtls_with_client_cert_source(transport_class) mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -9631,7 +10033,7 @@ def test_domains_transport_channel_mtls_with_adc(transport_class): def test_domains_grpc_lro_client(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -9648,7 +10050,7 @@ def test_domains_grpc_lro_client(): def test_domains_grpc_lro_async_client(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -9801,7 +10203,7 @@ def test_client_with_default_client_info(): transports.DomainsTransport, "_prep_wrapped_messages" ) as prep: client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -9811,7 +10213,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DomainsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -9820,7 +10222,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -9839,7 +10241,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -9856,7 +10258,7 @@ def test_client_ctx(): ] for transport in transports: client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -9887,7 +10289,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, diff --git a/packages/google-cloud-domains/tests/unit/gapic/domains_v1beta1/test_domains.py b/packages/google-cloud-domains/tests/unit/gapic/domains_v1beta1/test_domains.py index c03155c8f6cf..2246a70ed724 100644 --- a/packages/google-cloud-domains/tests/unit/gapic/domains_v1beta1/test_domains.py +++ b/packages/google-cloud-domains/tests/unit/gapic/domains_v1beta1/test_domains.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -81,6 +81,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -104,6 +127,238 @@ def test__get_default_mtls_endpoint(): assert DomainsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert DomainsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert DomainsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert DomainsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + DomainsClient._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 DomainsClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert DomainsClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert DomainsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + DomainsClient._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 DomainsClient._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 DomainsClient._get_client_cert_source(None, False) is None + assert ( + DomainsClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + DomainsClient._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 ( + DomainsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + DomainsClient._get_client_cert_source(mock_provided_cert_source, "true") + is mock_provided_cert_source + ) + + +@mock.patch.object( + DomainsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsClient), +) +@mock.patch.object( + DomainsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = DomainsClient._DEFAULT_UNIVERSE + default_endpoint = DomainsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DomainsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + DomainsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + DomainsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == DomainsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DomainsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + DomainsClient._get_api_endpoint(None, None, default_universe, "always") + == DomainsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DomainsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == DomainsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + DomainsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + DomainsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + DomainsClient._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 ( + DomainsClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + DomainsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + DomainsClient._get_universe_domain(None, None) + == DomainsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + DomainsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (DomainsClient, transports.DomainsGrpcTransport, "grpc"), + (DomainsClient, transports.DomainsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -113,7 +368,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_domains_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -163,7 +418,7 @@ def test_domains_client_service_account_always_use_jwt(transport_class, transpor ], ) def test_domains_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -208,15 +463,21 @@ def test_domains_client_get_transport_class(): ], ) @mock.patch.object( - DomainsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DomainsClient) + DomainsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsClient), ) @mock.patch.object( - DomainsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DomainsAsyncClient) + DomainsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsAsyncClient), ) def test_domains_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(DomainsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -251,7 +512,9 @@ def test_domains_client_client_options(client_class, transport_class, transport_ 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, @@ -281,15 +544,23 @@ def test_domains_client_client_options(client_class, transport_class, transport_ # 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") @@ -299,7 +570,9 @@ def test_domains_client_client_options(client_class, transport_class, transport_ 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", @@ -317,7 +590,9 @@ def test_domains_client_client_options(client_class, transport_class, transport_ 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, @@ -349,10 +624,14 @@ def test_domains_client_client_options(client_class, transport_class, transport_ ], ) @mock.patch.object( - DomainsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DomainsClient) + DomainsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsClient), ) @mock.patch.object( - DomainsAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(DomainsAsyncClient) + DomainsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_domains_client_mtls_env_auto( @@ -375,7 +654,9 @@ def test_domains_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 @@ -407,7 +688,9 @@ def test_domains_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 @@ -441,7 +724,9 @@ def test_domains_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, @@ -525,6 +810,116 @@ def test_domains_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", [DomainsClient, DomainsAsyncClient]) +@mock.patch.object( + DomainsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsClient), +) +@mock.patch.object( + DomainsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(DomainsAsyncClient), +) +def test_domains_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = DomainsClient._DEFAULT_UNIVERSE + default_endpoint = DomainsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = DomainsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -547,7 +942,9 @@ def test_domains_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, @@ -582,7 +979,9 @@ def test_domains_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, @@ -635,7 +1034,9 @@ def test_domains_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, @@ -652,8 +1053,8 @@ def test_domains_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -682,7 +1083,7 @@ def test_domains_client_create_channel_credentials_file( ) def test_search_domains(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -709,7 +1110,7 @@ def test_search_domains_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -726,7 +1127,7 @@ async def test_search_domains_async( transport: str = "grpc_asyncio", request_type=domains.SearchDomainsRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -758,7 +1159,7 @@ async def test_search_domains_async_from_dict(): def test_search_domains_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -788,7 +1189,7 @@ def test_search_domains_field_headers(): @pytest.mark.asyncio async def test_search_domains_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -819,7 +1220,7 @@ async def test_search_domains_field_headers_async(): def test_search_domains_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -847,7 +1248,7 @@ def test_search_domains_flattened(): def test_search_domains_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -863,7 +1264,7 @@ def test_search_domains_flattened_error(): @pytest.mark.asyncio async def test_search_domains_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -896,7 +1297,7 @@ async def test_search_domains_flattened_async(): @pytest.mark.asyncio async def test_search_domains_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -918,7 +1319,7 @@ async def test_search_domains_flattened_error_async(): ) def test_retrieve_register_parameters(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -947,7 +1348,7 @@ def test_retrieve_register_parameters_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -967,7 +1368,7 @@ async def test_retrieve_register_parameters_async( request_type=domains.RetrieveRegisterParametersRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1001,7 +1402,7 @@ async def test_retrieve_register_parameters_async_from_dict(): def test_retrieve_register_parameters_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1033,7 +1434,7 @@ def test_retrieve_register_parameters_field_headers(): @pytest.mark.asyncio async def test_retrieve_register_parameters_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1066,7 +1467,7 @@ async def test_retrieve_register_parameters_field_headers_async(): def test_retrieve_register_parameters_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1096,7 +1497,7 @@ def test_retrieve_register_parameters_flattened(): def test_retrieve_register_parameters_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1112,7 +1513,7 @@ def test_retrieve_register_parameters_flattened_error(): @pytest.mark.asyncio async def test_retrieve_register_parameters_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1147,7 +1548,7 @@ async def test_retrieve_register_parameters_flattened_async(): @pytest.mark.asyncio async def test_retrieve_register_parameters_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1169,7 +1570,7 @@ async def test_retrieve_register_parameters_flattened_error_async(): ) def test_register_domain(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1196,7 +1597,7 @@ def test_register_domain_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1213,7 +1614,7 @@ async def test_register_domain_async( transport: str = "grpc_asyncio", request_type=domains.RegisterDomainRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1245,7 +1646,7 @@ async def test_register_domain_async_from_dict(): def test_register_domain_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1275,7 +1676,7 @@ def test_register_domain_field_headers(): @pytest.mark.asyncio async def test_register_domain_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1306,7 +1707,7 @@ async def test_register_domain_field_headers_async(): def test_register_domain_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1338,7 +1739,7 @@ def test_register_domain_flattened(): def test_register_domain_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1355,7 +1756,7 @@ def test_register_domain_flattened_error(): @pytest.mark.asyncio async def test_register_domain_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1392,7 +1793,7 @@ async def test_register_domain_flattened_async(): @pytest.mark.asyncio async def test_register_domain_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1415,7 +1816,7 @@ async def test_register_domain_flattened_error_async(): ) def test_retrieve_transfer_parameters(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1444,7 +1845,7 @@ def test_retrieve_transfer_parameters_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1464,7 +1865,7 @@ async def test_retrieve_transfer_parameters_async( request_type=domains.RetrieveTransferParametersRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1498,7 +1899,7 @@ async def test_retrieve_transfer_parameters_async_from_dict(): def test_retrieve_transfer_parameters_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1530,7 +1931,7 @@ def test_retrieve_transfer_parameters_field_headers(): @pytest.mark.asyncio async def test_retrieve_transfer_parameters_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1563,7 +1964,7 @@ async def test_retrieve_transfer_parameters_field_headers_async(): def test_retrieve_transfer_parameters_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1593,7 +1994,7 @@ def test_retrieve_transfer_parameters_flattened(): def test_retrieve_transfer_parameters_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1609,7 +2010,7 @@ def test_retrieve_transfer_parameters_flattened_error(): @pytest.mark.asyncio async def test_retrieve_transfer_parameters_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1644,7 +2045,7 @@ async def test_retrieve_transfer_parameters_flattened_async(): @pytest.mark.asyncio async def test_retrieve_transfer_parameters_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1666,7 +2067,7 @@ async def test_retrieve_transfer_parameters_flattened_error_async(): ) def test_transfer_domain(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1693,7 +2094,7 @@ def test_transfer_domain_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1710,7 +2111,7 @@ async def test_transfer_domain_async( transport: str = "grpc_asyncio", request_type=domains.TransferDomainRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1742,7 +2143,7 @@ async def test_transfer_domain_async_from_dict(): def test_transfer_domain_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1772,7 +2173,7 @@ def test_transfer_domain_field_headers(): @pytest.mark.asyncio async def test_transfer_domain_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1803,7 +2204,7 @@ async def test_transfer_domain_field_headers_async(): def test_transfer_domain_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1839,7 +2240,7 @@ def test_transfer_domain_flattened(): def test_transfer_domain_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1857,7 +2258,7 @@ def test_transfer_domain_flattened_error(): @pytest.mark.asyncio async def test_transfer_domain_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1898,7 +2299,7 @@ async def test_transfer_domain_flattened_async(): @pytest.mark.asyncio async def test_transfer_domain_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1922,7 +2323,7 @@ async def test_transfer_domain_flattened_error_async(): ) def test_list_registrations(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1954,7 +2355,7 @@ def test_list_registrations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1973,7 +2374,7 @@ async def test_list_registrations_async( transport: str = "grpc_asyncio", request_type=domains.ListRegistrationsRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2010,7 +2411,7 @@ async def test_list_registrations_async_from_dict(): def test_list_registrations_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2042,7 +2443,7 @@ def test_list_registrations_field_headers(): @pytest.mark.asyncio async def test_list_registrations_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2075,7 +2476,7 @@ async def test_list_registrations_field_headers_async(): def test_list_registrations_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2101,7 +2502,7 @@ def test_list_registrations_flattened(): def test_list_registrations_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2116,7 +2517,7 @@ def test_list_registrations_flattened_error(): @pytest.mark.asyncio async def test_list_registrations_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2147,7 +2548,7 @@ async def test_list_registrations_flattened_async(): @pytest.mark.asyncio async def test_list_registrations_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2161,7 +2562,7 @@ async def test_list_registrations_flattened_error_async(): def test_list_registrations_pager(transport_name: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2213,7 +2614,7 @@ def test_list_registrations_pager(transport_name: str = "grpc"): def test_list_registrations_pages(transport_name: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2257,7 +2658,7 @@ def test_list_registrations_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_registrations_async_pager(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2309,7 +2710,7 @@ async def test_list_registrations_async_pager(): @pytest.mark.asyncio async def test_list_registrations_async_pages(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2366,7 +2767,7 @@ async def test_list_registrations_async_pages(): ) def test_get_registration(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2404,7 +2805,7 @@ def test_get_registration_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2421,7 +2822,7 @@ async def test_get_registration_async( transport: str = "grpc_asyncio", request_type=domains.GetRegistrationRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2464,7 +2865,7 @@ async def test_get_registration_async_from_dict(): def test_get_registration_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2494,7 +2895,7 @@ def test_get_registration_field_headers(): @pytest.mark.asyncio async def test_get_registration_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2525,7 +2926,7 @@ async def test_get_registration_field_headers_async(): def test_get_registration_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2549,7 +2950,7 @@ def test_get_registration_flattened(): def test_get_registration_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2564,7 +2965,7 @@ def test_get_registration_flattened_error(): @pytest.mark.asyncio async def test_get_registration_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2593,7 +2994,7 @@ async def test_get_registration_flattened_async(): @pytest.mark.asyncio async def test_get_registration_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2614,7 +3015,7 @@ async def test_get_registration_flattened_error_async(): ) def test_update_registration(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2643,7 +3044,7 @@ def test_update_registration_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2662,7 +3063,7 @@ async def test_update_registration_async( transport: str = "grpc_asyncio", request_type=domains.UpdateRegistrationRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2696,7 +3097,7 @@ async def test_update_registration_async_from_dict(): def test_update_registration_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2728,7 +3129,7 @@ def test_update_registration_field_headers(): @pytest.mark.asyncio async def test_update_registration_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2761,7 +3162,7 @@ async def test_update_registration_field_headers_async(): def test_update_registration_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2791,7 +3192,7 @@ def test_update_registration_flattened(): def test_update_registration_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2807,7 +3208,7 @@ def test_update_registration_flattened_error(): @pytest.mark.asyncio async def test_update_registration_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2842,7 +3243,7 @@ async def test_update_registration_flattened_async(): @pytest.mark.asyncio async def test_update_registration_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2864,7 +3265,7 @@ async def test_update_registration_flattened_error_async(): ) def test_configure_management_settings(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2893,7 +3294,7 @@ def test_configure_management_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2913,7 +3314,7 @@ async def test_configure_management_settings_async( request_type=domains.ConfigureManagementSettingsRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2947,7 +3348,7 @@ async def test_configure_management_settings_async_from_dict(): def test_configure_management_settings_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2979,7 +3380,7 @@ def test_configure_management_settings_field_headers(): @pytest.mark.asyncio async def test_configure_management_settings_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3012,7 +3413,7 @@ async def test_configure_management_settings_field_headers_async(): def test_configure_management_settings_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3050,7 +3451,7 @@ def test_configure_management_settings_flattened(): def test_configure_management_settings_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3069,7 +3470,7 @@ def test_configure_management_settings_flattened_error(): @pytest.mark.asyncio async def test_configure_management_settings_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3112,7 +3513,7 @@ async def test_configure_management_settings_flattened_async(): @pytest.mark.asyncio async def test_configure_management_settings_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3137,7 +3538,7 @@ async def test_configure_management_settings_flattened_error_async(): ) def test_configure_dns_settings(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3166,7 +3567,7 @@ def test_configure_dns_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3185,7 +3586,7 @@ async def test_configure_dns_settings_async( transport: str = "grpc_asyncio", request_type=domains.ConfigureDnsSettingsRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3219,7 +3620,7 @@ async def test_configure_dns_settings_async_from_dict(): def test_configure_dns_settings_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3251,7 +3652,7 @@ def test_configure_dns_settings_field_headers(): @pytest.mark.asyncio async def test_configure_dns_settings_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3284,7 +3685,7 @@ async def test_configure_dns_settings_field_headers_async(): def test_configure_dns_settings_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3326,7 +3727,7 @@ def test_configure_dns_settings_flattened(): def test_configure_dns_settings_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3347,7 +3748,7 @@ def test_configure_dns_settings_flattened_error(): @pytest.mark.asyncio async def test_configure_dns_settings_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3394,7 +3795,7 @@ async def test_configure_dns_settings_flattened_async(): @pytest.mark.asyncio async def test_configure_dns_settings_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3421,7 +3822,7 @@ async def test_configure_dns_settings_flattened_error_async(): ) def test_configure_contact_settings(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3450,7 +3851,7 @@ def test_configure_contact_settings_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3470,7 +3871,7 @@ async def test_configure_contact_settings_async( request_type=domains.ConfigureContactSettingsRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3504,7 +3905,7 @@ async def test_configure_contact_settings_async_from_dict(): def test_configure_contact_settings_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3536,7 +3937,7 @@ def test_configure_contact_settings_field_headers(): @pytest.mark.asyncio async def test_configure_contact_settings_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3569,7 +3970,7 @@ async def test_configure_contact_settings_field_headers_async(): def test_configure_contact_settings_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3607,7 +4008,7 @@ def test_configure_contact_settings_flattened(): def test_configure_contact_settings_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3626,7 +4027,7 @@ def test_configure_contact_settings_flattened_error(): @pytest.mark.asyncio async def test_configure_contact_settings_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3669,7 +4070,7 @@ async def test_configure_contact_settings_flattened_async(): @pytest.mark.asyncio async def test_configure_contact_settings_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3694,7 +4095,7 @@ async def test_configure_contact_settings_flattened_error_async(): ) def test_export_registration(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3723,7 +4124,7 @@ def test_export_registration_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3742,7 +4143,7 @@ async def test_export_registration_async( transport: str = "grpc_asyncio", request_type=domains.ExportRegistrationRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3776,7 +4177,7 @@ async def test_export_registration_async_from_dict(): def test_export_registration_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3808,7 +4209,7 @@ def test_export_registration_field_headers(): @pytest.mark.asyncio async def test_export_registration_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3841,7 +4242,7 @@ async def test_export_registration_field_headers_async(): def test_export_registration_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3867,7 +4268,7 @@ def test_export_registration_flattened(): def test_export_registration_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3882,7 +4283,7 @@ def test_export_registration_flattened_error(): @pytest.mark.asyncio async def test_export_registration_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3913,7 +4314,7 @@ async def test_export_registration_flattened_async(): @pytest.mark.asyncio async def test_export_registration_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3934,7 +4335,7 @@ async def test_export_registration_flattened_error_async(): ) def test_delete_registration(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3963,7 +4364,7 @@ def test_delete_registration_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3982,7 +4383,7 @@ async def test_delete_registration_async( transport: str = "grpc_asyncio", request_type=domains.DeleteRegistrationRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4016,7 +4417,7 @@ async def test_delete_registration_async_from_dict(): def test_delete_registration_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4048,7 +4449,7 @@ def test_delete_registration_field_headers(): @pytest.mark.asyncio async def test_delete_registration_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4081,7 +4482,7 @@ async def test_delete_registration_field_headers_async(): def test_delete_registration_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4107,7 +4508,7 @@ def test_delete_registration_flattened(): def test_delete_registration_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4122,7 +4523,7 @@ def test_delete_registration_flattened_error(): @pytest.mark.asyncio async def test_delete_registration_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4153,7 +4554,7 @@ async def test_delete_registration_flattened_async(): @pytest.mark.asyncio async def test_delete_registration_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4174,7 +4575,7 @@ async def test_delete_registration_flattened_error_async(): ) def test_retrieve_authorization_code(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4206,7 +4607,7 @@ def test_retrieve_authorization_code_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4226,7 +4627,7 @@ async def test_retrieve_authorization_code_async( request_type=domains.RetrieveAuthorizationCodeRequest, ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4263,7 +4664,7 @@ async def test_retrieve_authorization_code_async_from_dict(): def test_retrieve_authorization_code_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4295,7 +4696,7 @@ def test_retrieve_authorization_code_field_headers(): @pytest.mark.asyncio async def test_retrieve_authorization_code_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4328,7 +4729,7 @@ async def test_retrieve_authorization_code_field_headers_async(): def test_retrieve_authorization_code_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4354,7 +4755,7 @@ def test_retrieve_authorization_code_flattened(): def test_retrieve_authorization_code_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4369,7 +4770,7 @@ def test_retrieve_authorization_code_flattened_error(): @pytest.mark.asyncio async def test_retrieve_authorization_code_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4400,7 +4801,7 @@ async def test_retrieve_authorization_code_flattened_async(): @pytest.mark.asyncio async def test_retrieve_authorization_code_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4421,7 +4822,7 @@ async def test_retrieve_authorization_code_flattened_error_async(): ) def test_reset_authorization_code(request_type, transport: str = "grpc"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4453,7 +4854,7 @@ def test_reset_authorization_code_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4472,7 +4873,7 @@ async def test_reset_authorization_code_async( transport: str = "grpc_asyncio", request_type=domains.ResetAuthorizationCodeRequest ): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4509,7 +4910,7 @@ async def test_reset_authorization_code_async_from_dict(): def test_reset_authorization_code_field_headers(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4541,7 +4942,7 @@ def test_reset_authorization_code_field_headers(): @pytest.mark.asyncio async def test_reset_authorization_code_field_headers_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4574,7 +4975,7 @@ async def test_reset_authorization_code_field_headers_async(): def test_reset_authorization_code_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4600,7 +5001,7 @@ def test_reset_authorization_code_flattened(): def test_reset_authorization_code_flattened_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4615,7 +5016,7 @@ def test_reset_authorization_code_flattened_error(): @pytest.mark.asyncio async def test_reset_authorization_code_flattened_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4646,7 +5047,7 @@ async def test_reset_authorization_code_flattened_async(): @pytest.mark.asyncio async def test_reset_authorization_code_flattened_error_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4667,7 +5068,7 @@ async def test_reset_authorization_code_flattened_error_async(): ) def test_search_domains_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4715,7 +5116,7 @@ def test_search_domains_rest_required_fields(request_type=domains.SearchDomainsR assert "query" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_domains._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4727,7 +5128,7 @@ def test_search_domains_rest_required_fields(request_type=domains.SearchDomainsR jsonified_request["location"] = "location_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_domains._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("query",)) @@ -4740,7 +5141,7 @@ def test_search_domains_rest_required_fields(request_type=domains.SearchDomainsR assert jsonified_request["location"] == "location_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4788,7 +5189,7 @@ def test_search_domains_rest_required_fields(request_type=domains.SearchDomainsR def test_search_domains_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search_domains._get_unset_required_fields({}) @@ -4806,7 +5207,7 @@ def test_search_domains_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_domains_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -4860,7 +5261,7 @@ def test_search_domains_rest_bad_request( transport: str = "rest", request_type=domains.SearchDomainsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4882,7 +5283,7 @@ def test_search_domains_rest_bad_request( def test_search_domains_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4925,7 +5326,7 @@ def test_search_domains_rest_flattened(): def test_search_domains_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4941,7 +5342,7 @@ def test_search_domains_rest_flattened_error(transport: str = "rest"): def test_search_domains_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4954,7 +5355,7 @@ def test_search_domains_rest_error(): ) def test_retrieve_register_parameters_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5004,7 +5405,7 @@ def test_retrieve_register_parameters_rest_required_fields( assert "domainName" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_register_parameters._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5016,7 +5417,7 @@ def test_retrieve_register_parameters_rest_required_fields( jsonified_request["location"] = "location_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_register_parameters._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("domain_name",)) @@ -5029,7 +5430,7 @@ def test_retrieve_register_parameters_rest_required_fields( assert jsonified_request["location"] == "location_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5077,7 +5478,7 @@ def test_retrieve_register_parameters_rest_required_fields( def test_retrieve_register_parameters_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.retrieve_register_parameters._get_unset_required_fields({}) @@ -5095,7 +5496,7 @@ def test_retrieve_register_parameters_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_retrieve_register_parameters_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -5151,7 +5552,7 @@ def test_retrieve_register_parameters_rest_bad_request( transport: str = "rest", request_type=domains.RetrieveRegisterParametersRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5173,7 +5574,7 @@ def test_retrieve_register_parameters_rest_bad_request( def test_retrieve_register_parameters_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5216,7 +5617,7 @@ def test_retrieve_register_parameters_rest_flattened(): def test_retrieve_register_parameters_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5232,7 +5633,7 @@ def test_retrieve_register_parameters_rest_flattened_error(transport: str = "res def test_retrieve_register_parameters_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5245,7 +5646,7 @@ def test_retrieve_register_parameters_rest_error(): ) def test_register_domain_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5291,7 +5692,7 @@ def test_register_domain_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).register_domain._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5300,7 +5701,7 @@ def test_register_domain_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).register_domain._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5309,7 +5710,7 @@ def test_register_domain_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5349,7 +5750,7 @@ def test_register_domain_rest_required_fields( def test_register_domain_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.register_domain._get_unset_required_fields({}) @@ -5368,7 +5769,7 @@ def test_register_domain_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_register_domain_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -5424,7 +5825,7 @@ def test_register_domain_rest_bad_request( transport: str = "rest", request_type=domains.RegisterDomainRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5446,7 +5847,7 @@ def test_register_domain_rest_bad_request( def test_register_domain_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5488,7 +5889,7 @@ def test_register_domain_rest_flattened(): def test_register_domain_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5505,7 +5906,7 @@ def test_register_domain_rest_flattened_error(transport: str = "rest"): def test_register_domain_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5518,7 +5919,7 @@ def test_register_domain_rest_error(): ) def test_retrieve_transfer_parameters_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5568,7 +5969,7 @@ def test_retrieve_transfer_parameters_rest_required_fields( assert "domainName" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_transfer_parameters._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5580,7 +5981,7 @@ def test_retrieve_transfer_parameters_rest_required_fields( jsonified_request["location"] = "location_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_transfer_parameters._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("domain_name",)) @@ -5593,7 +5994,7 @@ def test_retrieve_transfer_parameters_rest_required_fields( assert jsonified_request["location"] == "location_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5641,7 +6042,7 @@ def test_retrieve_transfer_parameters_rest_required_fields( def test_retrieve_transfer_parameters_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.retrieve_transfer_parameters._get_unset_required_fields({}) @@ -5659,7 +6060,7 @@ def test_retrieve_transfer_parameters_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_retrieve_transfer_parameters_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -5715,7 +6116,7 @@ def test_retrieve_transfer_parameters_rest_bad_request( transport: str = "rest", request_type=domains.RetrieveTransferParametersRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5737,7 +6138,7 @@ def test_retrieve_transfer_parameters_rest_bad_request( def test_retrieve_transfer_parameters_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5780,7 +6181,7 @@ def test_retrieve_transfer_parameters_rest_flattened(): def test_retrieve_transfer_parameters_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5796,7 +6197,7 @@ def test_retrieve_transfer_parameters_rest_flattened_error(transport: str = "res def test_retrieve_transfer_parameters_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5809,7 +6210,7 @@ def test_retrieve_transfer_parameters_rest_error(): ) def test_transfer_domain_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5855,7 +6256,7 @@ def test_transfer_domain_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).transfer_domain._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5864,7 +6265,7 @@ def test_transfer_domain_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).transfer_domain._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5873,7 +6274,7 @@ def test_transfer_domain_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5913,7 +6314,7 @@ def test_transfer_domain_rest_required_fields( def test_transfer_domain_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.transfer_domain._get_unset_required_fields({}) @@ -5932,7 +6333,7 @@ def test_transfer_domain_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_transfer_domain_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -5988,7 +6389,7 @@ def test_transfer_domain_rest_bad_request( transport: str = "rest", request_type=domains.TransferDomainRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6010,7 +6411,7 @@ def test_transfer_domain_rest_bad_request( def test_transfer_domain_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6053,7 +6454,7 @@ def test_transfer_domain_rest_flattened(): def test_transfer_domain_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6071,7 +6472,7 @@ def test_transfer_domain_rest_flattened_error(transport: str = "rest"): def test_transfer_domain_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6084,7 +6485,7 @@ def test_transfer_domain_rest_error(): ) def test_list_registrations_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6135,7 +6536,7 @@ def test_list_registrations_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_registrations._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6144,7 +6545,7 @@ def test_list_registrations_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_registrations._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6161,7 +6562,7 @@ def test_list_registrations_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6203,7 +6604,7 @@ def test_list_registrations_rest_required_fields( def test_list_registrations_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_registrations._get_unset_required_fields({}) @@ -6222,7 +6623,7 @@ def test_list_registrations_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_registrations_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -6278,7 +6679,7 @@ def test_list_registrations_rest_bad_request( transport: str = "rest", request_type=domains.ListRegistrationsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6300,7 +6701,7 @@ def test_list_registrations_rest_bad_request( def test_list_registrations_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6342,7 +6743,7 @@ def test_list_registrations_rest_flattened(): def test_list_registrations_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6357,7 +6758,7 @@ def test_list_registrations_rest_flattened_error(transport: str = "rest"): def test_list_registrations_rest_pager(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6425,7 +6826,7 @@ def test_list_registrations_rest_pager(transport: str = "rest"): ) def test_get_registration_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6484,7 +6885,7 @@ def test_get_registration_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6493,7 +6894,7 @@ def test_get_registration_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6502,7 +6903,7 @@ def test_get_registration_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6544,7 +6945,7 @@ def test_get_registration_rest_required_fields( def test_get_registration_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_registration._get_unset_required_fields({}) @@ -6554,7 +6955,7 @@ def test_get_registration_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_registration_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -6606,7 +7007,7 @@ def test_get_registration_rest_bad_request( transport: str = "rest", request_type=domains.GetRegistrationRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6628,7 +7029,7 @@ def test_get_registration_rest_bad_request( def test_get_registration_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6672,7 +7073,7 @@ def test_get_registration_rest_flattened(): def test_get_registration_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6687,7 +7088,7 @@ def test_get_registration_rest_flattened_error(transport: str = "rest"): def test_get_registration_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6700,7 +7101,7 @@ def test_get_registration_rest_error(): ) def test_update_registration_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6882,14 +7283,14 @@ def test_update_registration_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_registration._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -6898,7 +7299,7 @@ def test_update_registration_rest_required_fields( # verify required fields with non-default values are left alone client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6938,7 +7339,7 @@ def test_update_registration_rest_required_fields( def test_update_registration_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_registration._get_unset_required_fields({}) @@ -6948,7 +7349,7 @@ def test_update_registration_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_registration_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -7006,7 +7407,7 @@ def test_update_registration_rest_bad_request( transport: str = "rest", request_type=domains.UpdateRegistrationRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7032,7 +7433,7 @@ def test_update_registration_rest_bad_request( def test_update_registration_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7077,7 +7478,7 @@ def test_update_registration_rest_flattened(): def test_update_registration_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7093,7 +7494,7 @@ def test_update_registration_rest_flattened_error(transport: str = "rest"): def test_update_registration_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7106,7 +7507,7 @@ def test_update_registration_rest_error(): ) def test_configure_management_settings_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7154,7 +7555,7 @@ def test_configure_management_settings_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_management_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7163,7 +7564,7 @@ def test_configure_management_settings_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_management_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7172,7 +7573,7 @@ def test_configure_management_settings_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7212,7 +7613,7 @@ def test_configure_management_settings_rest_required_fields( def test_configure_management_settings_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.configure_management_settings._get_unset_required_fields( @@ -7232,7 +7633,7 @@ def test_configure_management_settings_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_configure_management_settings_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -7290,7 +7691,7 @@ def test_configure_management_settings_rest_bad_request( transport: str = "rest", request_type=domains.ConfigureManagementSettingsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7314,7 +7715,7 @@ def test_configure_management_settings_rest_bad_request( def test_configure_management_settings_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7360,7 +7761,7 @@ def test_configure_management_settings_rest_flattened(): def test_configure_management_settings_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7379,7 +7780,7 @@ def test_configure_management_settings_rest_flattened_error(transport: str = "re def test_configure_management_settings_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7392,7 +7793,7 @@ def test_configure_management_settings_rest_error(): ) def test_configure_dns_settings_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7440,7 +7841,7 @@ def test_configure_dns_settings_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_dns_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7449,7 +7850,7 @@ def test_configure_dns_settings_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_dns_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7458,7 +7859,7 @@ def test_configure_dns_settings_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7498,7 +7899,7 @@ def test_configure_dns_settings_rest_required_fields( def test_configure_dns_settings_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.configure_dns_settings._get_unset_required_fields({}) @@ -7516,7 +7917,7 @@ def test_configure_dns_settings_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_configure_dns_settings_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -7574,7 +7975,7 @@ def test_configure_dns_settings_rest_bad_request( transport: str = "rest", request_type=domains.ConfigureDnsSettingsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7598,7 +7999,7 @@ def test_configure_dns_settings_rest_bad_request( def test_configure_dns_settings_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7646,7 +8047,7 @@ def test_configure_dns_settings_rest_flattened(): def test_configure_dns_settings_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7667,7 +8068,7 @@ def test_configure_dns_settings_rest_flattened_error(transport: str = "rest"): def test_configure_dns_settings_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7680,7 +8081,7 @@ def test_configure_dns_settings_rest_error(): ) def test_configure_contact_settings_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7728,7 +8129,7 @@ def test_configure_contact_settings_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_contact_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7737,7 +8138,7 @@ def test_configure_contact_settings_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).configure_contact_settings._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7746,7 +8147,7 @@ def test_configure_contact_settings_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7786,7 +8187,7 @@ def test_configure_contact_settings_rest_required_fields( def test_configure_contact_settings_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.configure_contact_settings._get_unset_required_fields({}) @@ -7804,7 +8205,7 @@ def test_configure_contact_settings_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_configure_contact_settings_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -7862,7 +8263,7 @@ def test_configure_contact_settings_rest_bad_request( transport: str = "rest", request_type=domains.ConfigureContactSettingsRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7886,7 +8287,7 @@ def test_configure_contact_settings_rest_bad_request( def test_configure_contact_settings_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7932,7 +8333,7 @@ def test_configure_contact_settings_rest_flattened(): def test_configure_contact_settings_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7951,7 +8352,7 @@ def test_configure_contact_settings_rest_flattened_error(transport: str = "rest" def test_configure_contact_settings_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7964,7 +8365,7 @@ def test_configure_contact_settings_rest_error(): ) def test_export_registration_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8010,7 +8411,7 @@ def test_export_registration_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8019,7 +8420,7 @@ def test_export_registration_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).export_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8028,7 +8429,7 @@ def test_export_registration_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8068,7 +8469,7 @@ def test_export_registration_rest_required_fields( def test_export_registration_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.export_registration._get_unset_required_fields({}) @@ -8078,7 +8479,7 @@ def test_export_registration_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_export_registration_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -8136,7 +8537,7 @@ def test_export_registration_rest_bad_request( transport: str = "rest", request_type=domains.ExportRegistrationRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8158,7 +8559,7 @@ def test_export_registration_rest_bad_request( def test_export_registration_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8200,7 +8601,7 @@ def test_export_registration_rest_flattened(): def test_export_registration_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8215,7 +8616,7 @@ def test_export_registration_rest_flattened_error(transport: str = "rest"): def test_export_registration_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8228,7 +8629,7 @@ def test_export_registration_rest_error(): ) def test_delete_registration_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8274,7 +8675,7 @@ def test_delete_registration_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8283,7 +8684,7 @@ def test_delete_registration_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_registration._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8292,7 +8693,7 @@ def test_delete_registration_rest_required_fields( assert jsonified_request["name"] == "name_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8331,7 +8732,7 @@ def test_delete_registration_rest_required_fields( def test_delete_registration_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_registration._get_unset_required_fields({}) @@ -8341,7 +8742,7 @@ def test_delete_registration_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_registration_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -8399,7 +8800,7 @@ def test_delete_registration_rest_bad_request( transport: str = "rest", request_type=domains.DeleteRegistrationRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8421,7 +8822,7 @@ def test_delete_registration_rest_bad_request( def test_delete_registration_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8463,7 +8864,7 @@ def test_delete_registration_rest_flattened(): def test_delete_registration_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8478,7 +8879,7 @@ def test_delete_registration_rest_flattened_error(transport: str = "rest"): def test_delete_registration_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8491,7 +8892,7 @@ def test_delete_registration_rest_error(): ) def test_retrieve_authorization_code_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8544,7 +8945,7 @@ def test_retrieve_authorization_code_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_authorization_code._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8553,7 +8954,7 @@ def test_retrieve_authorization_code_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).retrieve_authorization_code._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8562,7 +8963,7 @@ def test_retrieve_authorization_code_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8604,7 +9005,7 @@ def test_retrieve_authorization_code_rest_required_fields( def test_retrieve_authorization_code_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.retrieve_authorization_code._get_unset_required_fields({}) @@ -8614,7 +9015,7 @@ def test_retrieve_authorization_code_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_retrieve_authorization_code_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -8670,7 +9071,7 @@ def test_retrieve_authorization_code_rest_bad_request( transport: str = "rest", request_type=domains.RetrieveAuthorizationCodeRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8694,7 +9095,7 @@ def test_retrieve_authorization_code_rest_bad_request( def test_retrieve_authorization_code_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8738,7 +9139,7 @@ def test_retrieve_authorization_code_rest_flattened(): def test_retrieve_authorization_code_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8753,7 +9154,7 @@ def test_retrieve_authorization_code_rest_flattened_error(transport: str = "rest def test_retrieve_authorization_code_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8766,7 +9167,7 @@ def test_retrieve_authorization_code_rest_error(): ) def test_reset_authorization_code_rest(request_type): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8819,7 +9220,7 @@ def test_reset_authorization_code_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reset_authorization_code._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8828,7 +9229,7 @@ def test_reset_authorization_code_rest_required_fields( jsonified_request["registration"] = "registration_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).reset_authorization_code._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8837,7 +9238,7 @@ def test_reset_authorization_code_rest_required_fields( assert jsonified_request["registration"] == "registration_value" client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8880,7 +9281,7 @@ def test_reset_authorization_code_rest_required_fields( def test_reset_authorization_code_rest_unset_required_fields(): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.reset_authorization_code._get_unset_required_fields({}) @@ -8890,7 +9291,7 @@ def test_reset_authorization_code_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_reset_authorization_code_rest_interceptors(null_interceptor): transport = transports.DomainsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.DomainsRestInterceptor(), ) client = DomainsClient(transport=transport) @@ -8946,7 +9347,7 @@ def test_reset_authorization_code_rest_bad_request( transport: str = "rest", request_type=domains.ResetAuthorizationCodeRequest ): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8970,7 +9371,7 @@ def test_reset_authorization_code_rest_bad_request( def test_reset_authorization_code_rest_flattened(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9014,7 +9415,7 @@ def test_reset_authorization_code_rest_flattened(): def test_reset_authorization_code_rest_flattened_error(transport: str = "rest"): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9029,24 +9430,24 @@ def test_reset_authorization_code_rest_flattened_error(transport: str = "rest"): def test_reset_authorization_code_rest_error(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DomainsClient( @@ -9056,7 +9457,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -9067,16 +9468,17 @@ 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 = DomainsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = DomainsClient( @@ -9088,7 +9490,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = DomainsClient(transport=transport) assert client.transport is transport @@ -9097,13 +9499,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.DomainsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.DomainsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -9120,7 +9522,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -9134,7 +9536,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = DomainsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -9142,7 +9544,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -9154,7 +9556,7 @@ def test_domains_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.DomainsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -9166,7 +9568,7 @@ def test_domains_base_transport(): ) as Transport: Transport.return_value = None transport = transports.DomainsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -9217,7 +9619,7 @@ def test_domains_base_transport_with_credentials_file(): "google.cloud.domains_v1beta1.services.domains.transports.DomainsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DomainsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -9236,7 +9638,7 @@ def test_domains_base_transport_with_adc(): "google.cloud.domains_v1beta1.services.domains.transports.DomainsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.DomainsTransport() adc.assert_called_once() @@ -9244,7 +9646,7 @@ def test_domains_base_transport_with_adc(): def test_domains_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) DomainsClient() adc.assert_called_once_with( scopes=None, @@ -9264,7 +9666,7 @@ def test_domains_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -9311,7 +9713,7 @@ def test_domains_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -9336,7 +9738,7 @@ def test_domains_transport_create_channel(transport_class, grpc_helpers): [transports.DomainsGrpcTransport, transports.DomainsGrpcAsyncIOTransport], ) def test_domains_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -9374,7 +9776,7 @@ def test_domains_grpc_transport_client_cert_source_for_mtls(transport_class): def test_domains_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -9386,7 +9788,7 @@ def test_domains_http_transport_client_cert_source_for_mtls(): def test_domains_rest_lro_client(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -9411,7 +9813,7 @@ def test_domains_rest_lro_client(): ) def test_domains_host_no_port(transport_name): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="domains.googleapis.com" ), @@ -9434,7 +9836,7 @@ def test_domains_host_no_port(transport_name): ) def test_domains_host_with_port(transport_name): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="domains.googleapis.com:8000" ), @@ -9454,8 +9856,8 @@ def test_domains_host_with_port(transport_name): ], ) def test_domains_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = DomainsClient( credentials=creds1, transport=transport_name, @@ -9556,7 +9958,7 @@ def test_domains_transport_channel_mtls_with_client_cert_source(transport_class) mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -9631,7 +10033,7 @@ def test_domains_transport_channel_mtls_with_adc(transport_class): def test_domains_grpc_lro_client(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -9648,7 +10050,7 @@ def test_domains_grpc_lro_client(): def test_domains_grpc_lro_async_client(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -9801,7 +10203,7 @@ def test_client_with_default_client_info(): transports.DomainsTransport, "_prep_wrapped_messages" ) as prep: client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -9811,7 +10213,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = DomainsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -9820,7 +10222,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = DomainsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -9839,7 +10241,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -9856,7 +10258,7 @@ def test_client_ctx(): ] for transport in transports: client = DomainsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -9887,7 +10289,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, diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer/gapic_version.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer/gapic_version.py index 06d63171de69..360a0d13ebdd 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer/gapic_version.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.5.4" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/gapic_version.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/gapic_version.py index 06d63171de69..360a0d13ebdd 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/gapic_version.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.5.4" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/async_client.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/async_client.py index f6f271971ffe..d5e18cc37c27 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/async_client.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/async_client.py @@ -38,9 +38,9 @@ from google.cloud.edgecontainer_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -65,8 +65,12 @@ class EdgeContainerAsyncClient: _client: EdgeContainerClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EdgeContainerClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EdgeContainerClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = EdgeContainerClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = EdgeContainerClient._DEFAULT_UNIVERSE cluster_path = staticmethod(EdgeContainerClient.cluster_path) parse_cluster_path = staticmethod(EdgeContainerClient.parse_cluster_path) @@ -187,6 +191,25 @@ def transport(self) -> EdgeContainerTransport: """ 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(EdgeContainerClient).get_transport_class, type(EdgeContainerClient) ) @@ -199,7 +222,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the edge container client. + """Instantiates the edge container async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -210,23 +233,38 @@ def __init__( transport (Union[str, ~.EdgeContainerTransport]): 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. @@ -341,6 +379,9 @@ async def sample_list_clusters(): 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, @@ -460,6 +501,9 @@ async def sample_get_cluster(): 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, @@ -595,6 +639,9 @@ async def sample_create_cluster(): 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, @@ -724,6 +771,9 @@ async def sample_update_cluster(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -847,6 +897,9 @@ async def sample_delete_cluster(): 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, @@ -955,6 +1008,9 @@ async def sample_generate_access_token(): gapic_v1.routing_header.to_grpc_metadata((("cluster", request.cluster),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1069,6 +1125,9 @@ async def sample_list_node_pools(): 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, @@ -1189,6 +1248,9 @@ async def sample_get_node_pool(): 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, @@ -1321,6 +1383,9 @@ async def sample_create_node_pool(): 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, @@ -1449,6 +1514,9 @@ async def sample_update_node_pool(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1572,6 +1640,9 @@ async def sample_delete_node_pool(): 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, @@ -1694,6 +1765,9 @@ async def sample_list_machines(): 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, @@ -1814,6 +1888,9 @@ async def sample_get_machine(): 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, @@ -1929,6 +2006,9 @@ async def sample_list_vpn_connections(): 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, @@ -2046,6 +2126,9 @@ async def sample_get_vpn_connection(): 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, @@ -2180,6 +2263,9 @@ async def sample_create_vpn_connection(): 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, @@ -2303,6 +2389,9 @@ async def sample_delete_vpn_connection(): 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, @@ -2365,6 +2454,9 @@ async def list_operations( 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, @@ -2419,6 +2511,9 @@ async def get_operation( 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, @@ -2477,6 +2572,9 @@ async def delete_operation( 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, @@ -2531,6 +2629,9 @@ async def cancel_operation( 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, @@ -2582,6 +2683,9 @@ async def get_location( 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, @@ -2636,6 +2740,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/client.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/client.py index 09710ff4343f..39fe8940b125 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/client.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.edgecontainer_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -133,11 +134,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 = "edgecontainer.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "edgecontainer.{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 @@ -406,7 +411,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 @@ -436,6 +441,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") @@ -469,6 +479,175 @@ 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 + + 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 + + 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 = EdgeContainerClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EdgeContainerClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = EdgeContainerClient._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 = EdgeContainerClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = EdgeContainerClient._DEFAULT_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 EdgeContainerClient._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, *, @@ -488,22 +667,32 @@ def __init__( transport (Union[str, EdgeContainerTransport]): 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. @@ -514,17 +703,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, + ) = EdgeContainerClient._read_environment_variables() + self._client_cert_source = EdgeContainerClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = EdgeContainerClient._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" @@ -533,20 +739,33 @@ 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, EdgeContainerTransport): + transport_provided = isinstance(transport, EdgeContainerTransport) + if transport_provided: # transport is a EdgeContainerTransport 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(EdgeContainerTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or EdgeContainerClient._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( @@ -556,17 +775,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_clusters( @@ -663,6 +882,9 @@ def sample_list_clusters(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -773,6 +995,9 @@ def sample_get_cluster(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -908,6 +1133,9 @@ def sample_create_cluster(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1037,6 +1265,9 @@ def sample_update_cluster(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1160,6 +1391,9 @@ def sample_delete_cluster(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1268,6 +1502,9 @@ def sample_generate_access_token(): gapic_v1.routing_header.to_grpc_metadata((("cluster", request.cluster),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1373,6 +1610,9 @@ def sample_list_node_pools(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1484,6 +1724,9 @@ def sample_get_node_pool(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1616,6 +1859,9 @@ def sample_create_node_pool(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1744,6 +1990,9 @@ def sample_update_node_pool(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1867,6 +2116,9 @@ def sample_delete_node_pool(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1980,6 +2232,9 @@ def sample_list_machines(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2091,6 +2346,9 @@ def sample_get_machine(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2197,6 +2455,9 @@ def sample_list_vpn_connections(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2305,6 +2566,9 @@ def sample_get_vpn_connection(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2439,6 +2703,9 @@ def sample_create_vpn_connection(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2562,6 +2829,9 @@ def sample_delete_vpn_connection(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2637,6 +2907,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2691,6 +2964,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2749,6 +3025,9 @@ def delete_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -2803,6 +3082,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -2854,6 +3136,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2908,6 +3193,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/base.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/base.py index 624b44da4731..185f00947909 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/base.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'edgecontainer.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 @@ -121,6 +121,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-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc.py index 49f302a2f572..3ecb594c4ff7 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'edgecontainer.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-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc_asyncio.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc_asyncio.py index faf110d3d973..64dbc5eb05bc 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc_asyncio.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'edgecontainer.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-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/rest.py b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/rest.py index c1b7f3126de6..8ba11ec83b29 100644 --- a/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/rest.py +++ b/packages/google-cloud-edgecontainer/google/cloud/edgecontainer_v1/services/edge_container/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -756,7 +756,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'edgecontainer.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-edgecontainer/noxfile.py b/packages/google-cloud-edgecontainer/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-edgecontainer/noxfile.py +++ b/packages/google-cloud-edgecontainer/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-edgecontainer/samples/generated_samples/snippet_metadata_google.cloud.edgecontainer.v1.json b/packages/google-cloud-edgecontainer/samples/generated_samples/snippet_metadata_google.cloud.edgecontainer.v1.json index a654ffa5971d..523c75f1dabd 100644 --- a/packages/google-cloud-edgecontainer/samples/generated_samples/snippet_metadata_google.cloud.edgecontainer.v1.json +++ b/packages/google-cloud-edgecontainer/samples/generated_samples/snippet_metadata_google.cloud.edgecontainer.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-edgecontainer", - "version": "0.5.4" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-edgecontainer/tests/unit/gapic/edgecontainer_v1/test_edge_container.py b/packages/google-cloud-edgecontainer/tests/unit/gapic/edgecontainer_v1/test_edge_container.py index 9e4e0371fde1..9e64af12fd12 100644 --- a/packages/google-cloud-edgecontainer/tests/unit/gapic/edgecontainer_v1/test_edge_container.py +++ b/packages/google-cloud-edgecontainer/tests/unit/gapic/edgecontainer_v1/test_edge_container.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -82,6 +82,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -111,6 +134,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert EdgeContainerClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EdgeContainerClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EdgeContainerClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EdgeContainerClient._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 EdgeContainerClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EdgeContainerClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EdgeContainerClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EdgeContainerClient._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 EdgeContainerClient._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 EdgeContainerClient._get_client_cert_source(None, False) is None + assert ( + EdgeContainerClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + EdgeContainerClient._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 ( + EdgeContainerClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + EdgeContainerClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EdgeContainerClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeContainerClient), +) +@mock.patch.object( + EdgeContainerAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeContainerAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EdgeContainerClient._DEFAULT_UNIVERSE + default_endpoint = EdgeContainerClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EdgeContainerClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + EdgeContainerClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EdgeContainerClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EdgeContainerClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EdgeContainerClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + EdgeContainerClient._get_api_endpoint(None, None, default_universe, "always") + == EdgeContainerClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EdgeContainerClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EdgeContainerClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EdgeContainerClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + EdgeContainerClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EdgeContainerClient._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 ( + EdgeContainerClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + EdgeContainerClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + EdgeContainerClient._get_universe_domain(None, None) + == EdgeContainerClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EdgeContainerClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (EdgeContainerClient, transports.EdgeContainerGrpcTransport, "grpc"), + (EdgeContainerClient, transports.EdgeContainerRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -120,7 +400,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_edge_container_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -172,7 +452,7 @@ def test_edge_container_client_service_account_always_use_jwt( ], ) def test_edge_container_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -222,20 +502,22 @@ def test_edge_container_client_get_transport_class(): ) @mock.patch.object( EdgeContainerClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EdgeContainerClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeContainerClient), ) @mock.patch.object( EdgeContainerAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EdgeContainerAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeContainerAsyncClient), ) def test_edge_container_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(EdgeContainerClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -270,7 +552,9 @@ def test_edge_container_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, @@ -300,15 +584,23 @@ def test_edge_container_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") @@ -318,7 +610,9 @@ def test_edge_container_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", @@ -336,7 +630,9 @@ def test_edge_container_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, @@ -369,13 +665,13 @@ def test_edge_container_client_client_options( ) @mock.patch.object( EdgeContainerClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EdgeContainerClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeContainerClient), ) @mock.patch.object( EdgeContainerAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EdgeContainerAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeContainerAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_edge_container_client_mtls_env_auto( @@ -398,7 +694,9 @@ def test_edge_container_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 @@ -430,7 +728,9 @@ def test_edge_container_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 @@ -464,7 +764,9 @@ def test_edge_container_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, @@ -554,6 +856,118 @@ def test_edge_container_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", [EdgeContainerClient, EdgeContainerAsyncClient] +) +@mock.patch.object( + EdgeContainerClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeContainerClient), +) +@mock.patch.object( + EdgeContainerAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeContainerAsyncClient), +) +def test_edge_container_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EdgeContainerClient._DEFAULT_UNIVERSE + default_endpoint = EdgeContainerClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EdgeContainerClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -580,7 +994,9 @@ def test_edge_container_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, @@ -620,7 +1036,9 @@ def test_edge_container_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, @@ -680,7 +1098,9 @@ def test_edge_container_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, @@ -697,8 +1117,8 @@ def test_edge_container_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -727,7 +1147,7 @@ def test_edge_container_client_create_channel_credentials_file( ) def test_list_clusters(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -759,7 +1179,7 @@ def test_list_clusters_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -776,7 +1196,7 @@ async def test_list_clusters_async( transport: str = "grpc_asyncio", request_type=service.ListClustersRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -813,7 +1233,7 @@ async def test_list_clusters_async_from_dict(): def test_list_clusters_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -843,7 +1263,7 @@ def test_list_clusters_field_headers(): @pytest.mark.asyncio async def test_list_clusters_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -874,7 +1294,7 @@ async def test_list_clusters_field_headers_async(): def test_list_clusters_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -898,7 +1318,7 @@ def test_list_clusters_flattened(): def test_list_clusters_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -913,7 +1333,7 @@ def test_list_clusters_flattened_error(): @pytest.mark.asyncio async def test_list_clusters_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -942,7 +1362,7 @@ async def test_list_clusters_flattened_async(): @pytest.mark.asyncio async def test_list_clusters_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -956,7 +1376,7 @@ async def test_list_clusters_flattened_error_async(): def test_list_clusters_pager(transport_name: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1006,7 +1426,7 @@ def test_list_clusters_pager(transport_name: str = "grpc"): def test_list_clusters_pages(transport_name: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1048,7 +1468,7 @@ def test_list_clusters_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_clusters_async_pager(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1098,7 +1518,7 @@ async def test_list_clusters_async_pager(): @pytest.mark.asyncio async def test_list_clusters_async_pages(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1153,7 +1573,7 @@ async def test_list_clusters_async_pages(): ) def test_get_cluster(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1189,7 +1609,7 @@ def test_get_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1206,7 +1626,7 @@ async def test_get_cluster_async( transport: str = "grpc_asyncio", request_type=service.GetClusterRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1247,7 +1667,7 @@ async def test_get_cluster_async_from_dict(): def test_get_cluster_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1277,7 +1697,7 @@ def test_get_cluster_field_headers(): @pytest.mark.asyncio async def test_get_cluster_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1306,7 +1726,7 @@ async def test_get_cluster_field_headers_async(): def test_get_cluster_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1330,7 +1750,7 @@ def test_get_cluster_flattened(): def test_get_cluster_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1345,7 +1765,7 @@ def test_get_cluster_flattened_error(): @pytest.mark.asyncio async def test_get_cluster_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1372,7 +1792,7 @@ async def test_get_cluster_flattened_async(): @pytest.mark.asyncio async def test_get_cluster_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1393,7 +1813,7 @@ async def test_get_cluster_flattened_error_async(): ) def test_create_cluster(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1420,7 +1840,7 @@ def test_create_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1437,7 +1857,7 @@ async def test_create_cluster_async( transport: str = "grpc_asyncio", request_type=service.CreateClusterRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1469,7 +1889,7 @@ async def test_create_cluster_async_from_dict(): def test_create_cluster_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1499,7 +1919,7 @@ def test_create_cluster_field_headers(): @pytest.mark.asyncio async def test_create_cluster_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1530,7 +1950,7 @@ async def test_create_cluster_field_headers_async(): def test_create_cluster_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1562,7 +1982,7 @@ def test_create_cluster_flattened(): def test_create_cluster_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1579,7 +1999,7 @@ def test_create_cluster_flattened_error(): @pytest.mark.asyncio async def test_create_cluster_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1616,7 +2036,7 @@ async def test_create_cluster_flattened_async(): @pytest.mark.asyncio async def test_create_cluster_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1639,7 +2059,7 @@ async def test_create_cluster_flattened_error_async(): ) def test_update_cluster(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1666,7 +2086,7 @@ def test_update_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1683,7 +2103,7 @@ async def test_update_cluster_async( transport: str = "grpc_asyncio", request_type=service.UpdateClusterRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1715,7 +2135,7 @@ async def test_update_cluster_async_from_dict(): def test_update_cluster_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1745,7 +2165,7 @@ def test_update_cluster_field_headers(): @pytest.mark.asyncio async def test_update_cluster_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1776,7 +2196,7 @@ async def test_update_cluster_field_headers_async(): def test_update_cluster_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1804,7 +2224,7 @@ def test_update_cluster_flattened(): def test_update_cluster_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1820,7 +2240,7 @@ def test_update_cluster_flattened_error(): @pytest.mark.asyncio async def test_update_cluster_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1853,7 +2273,7 @@ async def test_update_cluster_flattened_async(): @pytest.mark.asyncio async def test_update_cluster_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1875,7 +2295,7 @@ async def test_update_cluster_flattened_error_async(): ) def test_delete_cluster(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1902,7 +2322,7 @@ def test_delete_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1919,7 +2339,7 @@ async def test_delete_cluster_async( transport: str = "grpc_asyncio", request_type=service.DeleteClusterRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1951,7 +2371,7 @@ async def test_delete_cluster_async_from_dict(): def test_delete_cluster_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1981,7 +2401,7 @@ def test_delete_cluster_field_headers(): @pytest.mark.asyncio async def test_delete_cluster_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2012,7 +2432,7 @@ async def test_delete_cluster_field_headers_async(): def test_delete_cluster_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2036,7 +2456,7 @@ def test_delete_cluster_flattened(): def test_delete_cluster_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2051,7 +2471,7 @@ def test_delete_cluster_flattened_error(): @pytest.mark.asyncio async def test_delete_cluster_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2080,7 +2500,7 @@ async def test_delete_cluster_flattened_async(): @pytest.mark.asyncio async def test_delete_cluster_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2101,7 +2521,7 @@ async def test_delete_cluster_flattened_error_async(): ) def test_generate_access_token(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2133,7 +2553,7 @@ def test_generate_access_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2152,7 +2572,7 @@ async def test_generate_access_token_async( transport: str = "grpc_asyncio", request_type=service.GenerateAccessTokenRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2189,7 +2609,7 @@ async def test_generate_access_token_async_from_dict(): def test_generate_access_token_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2221,7 +2641,7 @@ def test_generate_access_token_field_headers(): @pytest.mark.asyncio async def test_generate_access_token_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2254,7 +2674,7 @@ async def test_generate_access_token_field_headers_async(): def test_generate_access_token_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2280,7 +2700,7 @@ def test_generate_access_token_flattened(): def test_generate_access_token_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2295,7 +2715,7 @@ def test_generate_access_token_flattened_error(): @pytest.mark.asyncio async def test_generate_access_token_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2326,7 +2746,7 @@ async def test_generate_access_token_flattened_async(): @pytest.mark.asyncio async def test_generate_access_token_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2347,7 +2767,7 @@ async def test_generate_access_token_flattened_error_async(): ) def test_list_node_pools(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2379,7 +2799,7 @@ def test_list_node_pools_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2396,7 +2816,7 @@ async def test_list_node_pools_async( transport: str = "grpc_asyncio", request_type=service.ListNodePoolsRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2433,7 +2853,7 @@ async def test_list_node_pools_async_from_dict(): def test_list_node_pools_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2463,7 +2883,7 @@ def test_list_node_pools_field_headers(): @pytest.mark.asyncio async def test_list_node_pools_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2494,7 +2914,7 @@ async def test_list_node_pools_field_headers_async(): def test_list_node_pools_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2518,7 +2938,7 @@ def test_list_node_pools_flattened(): def test_list_node_pools_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2533,7 +2953,7 @@ def test_list_node_pools_flattened_error(): @pytest.mark.asyncio async def test_list_node_pools_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2562,7 +2982,7 @@ async def test_list_node_pools_flattened_async(): @pytest.mark.asyncio async def test_list_node_pools_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2576,7 +2996,7 @@ async def test_list_node_pools_flattened_error_async(): def test_list_node_pools_pager(transport_name: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2626,7 +3046,7 @@ def test_list_node_pools_pager(transport_name: str = "grpc"): def test_list_node_pools_pages(transport_name: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2668,7 +3088,7 @@ def test_list_node_pools_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_node_pools_async_pager(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2718,7 +3138,7 @@ async def test_list_node_pools_async_pager(): @pytest.mark.asyncio async def test_list_node_pools_async_pages(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2773,7 +3193,7 @@ async def test_list_node_pools_async_pages(): ) def test_get_node_pool(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2809,7 +3229,7 @@ def test_get_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2826,7 +3246,7 @@ async def test_get_node_pool_async( transport: str = "grpc_asyncio", request_type=service.GetNodePoolRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2867,7 +3287,7 @@ async def test_get_node_pool_async_from_dict(): def test_get_node_pool_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2897,7 +3317,7 @@ def test_get_node_pool_field_headers(): @pytest.mark.asyncio async def test_get_node_pool_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2926,7 +3346,7 @@ async def test_get_node_pool_field_headers_async(): def test_get_node_pool_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2950,7 +3370,7 @@ def test_get_node_pool_flattened(): def test_get_node_pool_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2965,7 +3385,7 @@ def test_get_node_pool_flattened_error(): @pytest.mark.asyncio async def test_get_node_pool_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2992,7 +3412,7 @@ async def test_get_node_pool_flattened_async(): @pytest.mark.asyncio async def test_get_node_pool_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3013,7 +3433,7 @@ async def test_get_node_pool_flattened_error_async(): ) def test_create_node_pool(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3040,7 +3460,7 @@ def test_create_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3057,7 +3477,7 @@ async def test_create_node_pool_async( transport: str = "grpc_asyncio", request_type=service.CreateNodePoolRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3089,7 +3509,7 @@ async def test_create_node_pool_async_from_dict(): def test_create_node_pool_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3119,7 +3539,7 @@ def test_create_node_pool_field_headers(): @pytest.mark.asyncio async def test_create_node_pool_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3150,7 +3570,7 @@ async def test_create_node_pool_field_headers_async(): def test_create_node_pool_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3182,7 +3602,7 @@ def test_create_node_pool_flattened(): def test_create_node_pool_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3199,7 +3619,7 @@ def test_create_node_pool_flattened_error(): @pytest.mark.asyncio async def test_create_node_pool_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3236,7 +3656,7 @@ async def test_create_node_pool_flattened_async(): @pytest.mark.asyncio async def test_create_node_pool_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3259,7 +3679,7 @@ async def test_create_node_pool_flattened_error_async(): ) def test_update_node_pool(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3286,7 +3706,7 @@ def test_update_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3303,7 +3723,7 @@ async def test_update_node_pool_async( transport: str = "grpc_asyncio", request_type=service.UpdateNodePoolRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3335,7 +3755,7 @@ async def test_update_node_pool_async_from_dict(): def test_update_node_pool_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3365,7 +3785,7 @@ def test_update_node_pool_field_headers(): @pytest.mark.asyncio async def test_update_node_pool_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3396,7 +3816,7 @@ async def test_update_node_pool_field_headers_async(): def test_update_node_pool_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3424,7 +3844,7 @@ def test_update_node_pool_flattened(): def test_update_node_pool_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3440,7 +3860,7 @@ def test_update_node_pool_flattened_error(): @pytest.mark.asyncio async def test_update_node_pool_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3473,7 +3893,7 @@ async def test_update_node_pool_flattened_async(): @pytest.mark.asyncio async def test_update_node_pool_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3495,7 +3915,7 @@ async def test_update_node_pool_flattened_error_async(): ) def test_delete_node_pool(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3522,7 +3942,7 @@ def test_delete_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3539,7 +3959,7 @@ async def test_delete_node_pool_async( transport: str = "grpc_asyncio", request_type=service.DeleteNodePoolRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3571,7 +3991,7 @@ async def test_delete_node_pool_async_from_dict(): def test_delete_node_pool_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3601,7 +4021,7 @@ def test_delete_node_pool_field_headers(): @pytest.mark.asyncio async def test_delete_node_pool_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3632,7 +4052,7 @@ async def test_delete_node_pool_field_headers_async(): def test_delete_node_pool_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3656,7 +4076,7 @@ def test_delete_node_pool_flattened(): def test_delete_node_pool_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3671,7 +4091,7 @@ def test_delete_node_pool_flattened_error(): @pytest.mark.asyncio async def test_delete_node_pool_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3700,7 +4120,7 @@ async def test_delete_node_pool_flattened_async(): @pytest.mark.asyncio async def test_delete_node_pool_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3721,7 +4141,7 @@ async def test_delete_node_pool_flattened_error_async(): ) def test_list_machines(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3753,7 +4173,7 @@ def test_list_machines_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3770,7 +4190,7 @@ async def test_list_machines_async( transport: str = "grpc_asyncio", request_type=service.ListMachinesRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3807,7 +4227,7 @@ async def test_list_machines_async_from_dict(): def test_list_machines_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3837,7 +4257,7 @@ def test_list_machines_field_headers(): @pytest.mark.asyncio async def test_list_machines_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3868,7 +4288,7 @@ async def test_list_machines_field_headers_async(): def test_list_machines_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3892,7 +4312,7 @@ def test_list_machines_flattened(): def test_list_machines_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3907,7 +4327,7 @@ def test_list_machines_flattened_error(): @pytest.mark.asyncio async def test_list_machines_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3936,7 +4356,7 @@ async def test_list_machines_flattened_async(): @pytest.mark.asyncio async def test_list_machines_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3950,7 +4370,7 @@ async def test_list_machines_flattened_error_async(): def test_list_machines_pager(transport_name: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4000,7 +4420,7 @@ def test_list_machines_pager(transport_name: str = "grpc"): def test_list_machines_pages(transport_name: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4042,7 +4462,7 @@ def test_list_machines_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_machines_async_pager(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4092,7 +4512,7 @@ async def test_list_machines_async_pager(): @pytest.mark.asyncio async def test_list_machines_async_pages(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4147,7 +4567,7 @@ async def test_list_machines_async_pages(): ) def test_get_machine(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4183,7 +4603,7 @@ def test_get_machine_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4200,7 +4620,7 @@ async def test_get_machine_async( transport: str = "grpc_asyncio", request_type=service.GetMachineRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4241,7 +4661,7 @@ async def test_get_machine_async_from_dict(): def test_get_machine_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4271,7 +4691,7 @@ def test_get_machine_field_headers(): @pytest.mark.asyncio async def test_get_machine_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4300,7 +4720,7 @@ async def test_get_machine_field_headers_async(): def test_get_machine_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4324,7 +4744,7 @@ def test_get_machine_flattened(): def test_get_machine_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4339,7 +4759,7 @@ def test_get_machine_flattened_error(): @pytest.mark.asyncio async def test_get_machine_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4366,7 +4786,7 @@ async def test_get_machine_flattened_async(): @pytest.mark.asyncio async def test_get_machine_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4387,7 +4807,7 @@ async def test_get_machine_flattened_error_async(): ) def test_list_vpn_connections(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4421,7 +4841,7 @@ def test_list_vpn_connections_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4440,7 +4860,7 @@ async def test_list_vpn_connections_async( transport: str = "grpc_asyncio", request_type=service.ListVpnConnectionsRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4479,7 +4899,7 @@ async def test_list_vpn_connections_async_from_dict(): def test_list_vpn_connections_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4511,7 +4931,7 @@ def test_list_vpn_connections_field_headers(): @pytest.mark.asyncio async def test_list_vpn_connections_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4544,7 +4964,7 @@ async def test_list_vpn_connections_field_headers_async(): def test_list_vpn_connections_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4570,7 +4990,7 @@ def test_list_vpn_connections_flattened(): def test_list_vpn_connections_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4585,7 +5005,7 @@ def test_list_vpn_connections_flattened_error(): @pytest.mark.asyncio async def test_list_vpn_connections_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4616,7 +5036,7 @@ async def test_list_vpn_connections_flattened_async(): @pytest.mark.asyncio async def test_list_vpn_connections_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4630,7 +5050,7 @@ async def test_list_vpn_connections_flattened_error_async(): def test_list_vpn_connections_pager(transport_name: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4682,7 +5102,7 @@ def test_list_vpn_connections_pager(transport_name: str = "grpc"): def test_list_vpn_connections_pages(transport_name: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4726,7 +5146,7 @@ def test_list_vpn_connections_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_vpn_connections_async_pager(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4778,7 +5198,7 @@ async def test_list_vpn_connections_async_pager(): @pytest.mark.asyncio async def test_list_vpn_connections_async_pages(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4835,7 +5255,7 @@ async def test_list_vpn_connections_async_pages(): ) def test_get_vpn_connection(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4877,7 +5297,7 @@ def test_get_vpn_connection_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4896,7 +5316,7 @@ async def test_get_vpn_connection_async( transport: str = "grpc_asyncio", request_type=service.GetVpnConnectionRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4943,7 +5363,7 @@ async def test_get_vpn_connection_async_from_dict(): def test_get_vpn_connection_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4975,7 +5395,7 @@ def test_get_vpn_connection_field_headers(): @pytest.mark.asyncio async def test_get_vpn_connection_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5008,7 +5428,7 @@ async def test_get_vpn_connection_field_headers_async(): def test_get_vpn_connection_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5034,7 +5454,7 @@ def test_get_vpn_connection_flattened(): def test_get_vpn_connection_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5049,7 +5469,7 @@ def test_get_vpn_connection_flattened_error(): @pytest.mark.asyncio async def test_get_vpn_connection_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5080,7 +5500,7 @@ async def test_get_vpn_connection_flattened_async(): @pytest.mark.asyncio async def test_get_vpn_connection_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5101,7 +5521,7 @@ async def test_get_vpn_connection_flattened_error_async(): ) def test_create_vpn_connection(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5130,7 +5550,7 @@ def test_create_vpn_connection_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5149,7 +5569,7 @@ async def test_create_vpn_connection_async( transport: str = "grpc_asyncio", request_type=service.CreateVpnConnectionRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5183,7 +5603,7 @@ async def test_create_vpn_connection_async_from_dict(): def test_create_vpn_connection_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5215,7 +5635,7 @@ def test_create_vpn_connection_field_headers(): @pytest.mark.asyncio async def test_create_vpn_connection_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5248,7 +5668,7 @@ async def test_create_vpn_connection_field_headers_async(): def test_create_vpn_connection_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5282,7 +5702,7 @@ def test_create_vpn_connection_flattened(): def test_create_vpn_connection_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5299,7 +5719,7 @@ def test_create_vpn_connection_flattened_error(): @pytest.mark.asyncio async def test_create_vpn_connection_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5338,7 +5758,7 @@ async def test_create_vpn_connection_flattened_async(): @pytest.mark.asyncio async def test_create_vpn_connection_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5361,7 +5781,7 @@ async def test_create_vpn_connection_flattened_error_async(): ) def test_delete_vpn_connection(request_type, transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5390,7 +5810,7 @@ def test_delete_vpn_connection_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5409,7 +5829,7 @@ async def test_delete_vpn_connection_async( transport: str = "grpc_asyncio", request_type=service.DeleteVpnConnectionRequest ): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5443,7 +5863,7 @@ async def test_delete_vpn_connection_async_from_dict(): def test_delete_vpn_connection_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5475,7 +5895,7 @@ def test_delete_vpn_connection_field_headers(): @pytest.mark.asyncio async def test_delete_vpn_connection_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5508,7 +5928,7 @@ async def test_delete_vpn_connection_field_headers_async(): def test_delete_vpn_connection_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5534,7 +5954,7 @@ def test_delete_vpn_connection_flattened(): def test_delete_vpn_connection_flattened_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5549,7 +5969,7 @@ def test_delete_vpn_connection_flattened_error(): @pytest.mark.asyncio async def test_delete_vpn_connection_flattened_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5580,7 +6000,7 @@ async def test_delete_vpn_connection_flattened_async(): @pytest.mark.asyncio async def test_delete_vpn_connection_flattened_error_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5601,7 +6021,7 @@ async def test_delete_vpn_connection_flattened_error_async(): ) def test_list_clusters_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5652,7 +6072,7 @@ def test_list_clusters_rest_required_fields(request_type=service.ListClustersReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_clusters._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5661,7 +6081,7 @@ def test_list_clusters_rest_required_fields(request_type=service.ListClustersReq jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_clusters._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5679,7 +6099,7 @@ def test_list_clusters_rest_required_fields(request_type=service.ListClustersReq assert jsonified_request["parent"] == "parent_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5721,7 +6141,7 @@ def test_list_clusters_rest_required_fields(request_type=service.ListClustersReq def test_list_clusters_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_clusters._get_unset_required_fields({}) @@ -5741,7 +6161,7 @@ def test_list_clusters_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_clusters_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -5797,7 +6217,7 @@ def test_list_clusters_rest_bad_request( transport: str = "rest", request_type=service.ListClustersRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5819,7 +6239,7 @@ def test_list_clusters_rest_bad_request( def test_list_clusters_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5860,7 +6280,7 @@ def test_list_clusters_rest_flattened(): def test_list_clusters_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5875,7 +6295,7 @@ def test_list_clusters_rest_flattened_error(transport: str = "rest"): def test_list_clusters_rest_pager(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5943,7 +6363,7 @@ def test_list_clusters_rest_pager(transport: str = "rest"): ) def test_get_cluster_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5998,7 +6418,7 @@ def test_get_cluster_rest_required_fields(request_type=service.GetClusterRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6007,7 +6427,7 @@ def test_get_cluster_rest_required_fields(request_type=service.GetClusterRequest jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6016,7 +6436,7 @@ def test_get_cluster_rest_required_fields(request_type=service.GetClusterRequest assert jsonified_request["name"] == "name_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6058,7 +6478,7 @@ def test_get_cluster_rest_required_fields(request_type=service.GetClusterRequest def test_get_cluster_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_cluster._get_unset_required_fields({}) @@ -6068,7 +6488,7 @@ def test_get_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_cluster_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -6122,7 +6542,7 @@ def test_get_cluster_rest_bad_request( transport: str = "rest", request_type=service.GetClusterRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6144,7 +6564,7 @@ def test_get_cluster_rest_bad_request( def test_get_cluster_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6185,7 +6605,7 @@ def test_get_cluster_rest_flattened(): def test_get_cluster_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6200,7 +6620,7 @@ def test_get_cluster_rest_flattened_error(transport: str = "rest"): def test_get_cluster_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6213,7 +6633,7 @@ def test_get_cluster_rest_error(): ) def test_create_cluster_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6355,7 +6775,7 @@ def test_create_cluster_rest_required_fields(request_type=service.CreateClusterR assert "clusterId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6367,7 +6787,7 @@ def test_create_cluster_rest_required_fields(request_type=service.CreateClusterR jsonified_request["clusterId"] = "cluster_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6385,7 +6805,7 @@ def test_create_cluster_rest_required_fields(request_type=service.CreateClusterR assert jsonified_request["clusterId"] == "cluster_id_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6431,7 +6851,7 @@ def test_create_cluster_rest_required_fields(request_type=service.CreateClusterR def test_create_cluster_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_cluster._get_unset_required_fields({}) @@ -6455,7 +6875,7 @@ def test_create_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_cluster_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -6513,7 +6933,7 @@ def test_create_cluster_rest_bad_request( transport: str = "rest", request_type=service.CreateClusterRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6535,7 +6955,7 @@ def test_create_cluster_rest_bad_request( def test_create_cluster_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6576,7 +6996,7 @@ def test_create_cluster_rest_flattened(): def test_create_cluster_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6593,7 +7013,7 @@ def test_create_cluster_rest_flattened_error(transport: str = "rest"): def test_create_cluster_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6606,7 +7026,7 @@ def test_create_cluster_rest_error(): ) def test_update_cluster_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6733,7 +7153,7 @@ def get_message_fields(field): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_cluster_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -6791,7 +7211,7 @@ def test_update_cluster_rest_bad_request( transport: str = "rest", request_type=service.UpdateClusterRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6815,7 +7235,7 @@ def test_update_cluster_rest_bad_request( def test_update_cluster_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6858,7 +7278,7 @@ def test_update_cluster_rest_flattened(): def test_update_cluster_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6874,7 +7294,7 @@ def test_update_cluster_rest_flattened_error(transport: str = "rest"): def test_update_cluster_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6887,7 +7307,7 @@ def test_update_cluster_rest_error(): ) def test_delete_cluster_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6931,7 +7351,7 @@ def test_delete_cluster_rest_required_fields(request_type=service.DeleteClusterR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6940,7 +7360,7 @@ def test_delete_cluster_rest_required_fields(request_type=service.DeleteClusterR jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("request_id",)) @@ -6951,7 +7371,7 @@ def test_delete_cluster_rest_required_fields(request_type=service.DeleteClusterR assert jsonified_request["name"] == "name_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6990,7 +7410,7 @@ def test_delete_cluster_rest_required_fields(request_type=service.DeleteClusterR def test_delete_cluster_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_cluster._get_unset_required_fields({}) @@ -7000,7 +7420,7 @@ def test_delete_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_cluster_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -7058,7 +7478,7 @@ def test_delete_cluster_rest_bad_request( transport: str = "rest", request_type=service.DeleteClusterRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7080,7 +7500,7 @@ def test_delete_cluster_rest_bad_request( def test_delete_cluster_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7119,7 +7539,7 @@ def test_delete_cluster_rest_flattened(): def test_delete_cluster_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7134,7 +7554,7 @@ def test_delete_cluster_rest_flattened_error(transport: str = "rest"): def test_delete_cluster_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7147,7 +7567,7 @@ def test_delete_cluster_rest_error(): ) def test_generate_access_token_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7198,7 +7618,7 @@ def test_generate_access_token_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_access_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7207,7 +7627,7 @@ def test_generate_access_token_rest_required_fields( jsonified_request["cluster"] = "cluster_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_access_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7216,7 +7636,7 @@ def test_generate_access_token_rest_required_fields( assert jsonified_request["cluster"] == "cluster_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7258,7 +7678,7 @@ def test_generate_access_token_rest_required_fields( def test_generate_access_token_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_access_token._get_unset_required_fields({}) @@ -7268,7 +7688,7 @@ def test_generate_access_token_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_access_token_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -7326,7 +7746,7 @@ def test_generate_access_token_rest_bad_request( transport: str = "rest", request_type=service.GenerateAccessTokenRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7348,7 +7768,7 @@ def test_generate_access_token_rest_bad_request( def test_generate_access_token_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7392,7 +7812,7 @@ def test_generate_access_token_rest_flattened(): def test_generate_access_token_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7407,7 +7827,7 @@ def test_generate_access_token_rest_flattened_error(transport: str = "rest"): def test_generate_access_token_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7420,7 +7840,7 @@ def test_generate_access_token_rest_error(): ) def test_list_node_pools_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7473,7 +7893,7 @@ def test_list_node_pools_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_node_pools._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7482,7 +7902,7 @@ def test_list_node_pools_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_node_pools._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7500,7 +7920,7 @@ def test_list_node_pools_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7542,7 +7962,7 @@ def test_list_node_pools_rest_required_fields( def test_list_node_pools_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_node_pools._get_unset_required_fields({}) @@ -7562,7 +7982,7 @@ def test_list_node_pools_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_node_pools_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -7618,7 +8038,7 @@ def test_list_node_pools_rest_bad_request( transport: str = "rest", request_type=service.ListNodePoolsRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7640,7 +8060,7 @@ def test_list_node_pools_rest_bad_request( def test_list_node_pools_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7684,7 +8104,7 @@ def test_list_node_pools_rest_flattened(): def test_list_node_pools_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7699,7 +8119,7 @@ def test_list_node_pools_rest_flattened_error(transport: str = "rest"): def test_list_node_pools_rest_pager(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7769,7 +8189,7 @@ def test_list_node_pools_rest_pager(transport: str = "rest"): ) def test_get_node_pool_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7826,7 +8246,7 @@ def test_get_node_pool_rest_required_fields(request_type=service.GetNodePoolRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7835,7 +8255,7 @@ def test_get_node_pool_rest_required_fields(request_type=service.GetNodePoolRequ jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7844,7 +8264,7 @@ def test_get_node_pool_rest_required_fields(request_type=service.GetNodePoolRequ assert jsonified_request["name"] == "name_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7886,7 +8306,7 @@ def test_get_node_pool_rest_required_fields(request_type=service.GetNodePoolRequ def test_get_node_pool_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_node_pool._get_unset_required_fields({}) @@ -7896,7 +8316,7 @@ def test_get_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_node_pool_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -7950,7 +8370,7 @@ def test_get_node_pool_rest_bad_request( transport: str = "rest", request_type=service.GetNodePoolRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7974,7 +8394,7 @@ def test_get_node_pool_rest_bad_request( def test_get_node_pool_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8018,7 +8438,7 @@ def test_get_node_pool_rest_flattened(): def test_get_node_pool_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8033,7 +8453,7 @@ def test_get_node_pool_rest_flattened_error(transport: str = "rest"): def test_get_node_pool_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8046,7 +8466,7 @@ def test_get_node_pool_rest_error(): ) def test_create_node_pool_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8185,7 +8605,7 @@ def test_create_node_pool_rest_required_fields( assert "nodePoolId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8197,7 +8617,7 @@ def test_create_node_pool_rest_required_fields( jsonified_request["nodePoolId"] = "node_pool_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_node_pool._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8215,7 +8635,7 @@ def test_create_node_pool_rest_required_fields( assert jsonified_request["nodePoolId"] == "node_pool_id_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8261,7 +8681,7 @@ def test_create_node_pool_rest_required_fields( def test_create_node_pool_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_node_pool._get_unset_required_fields({}) @@ -8285,7 +8705,7 @@ def test_create_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_node_pool_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -8343,7 +8763,7 @@ def test_create_node_pool_rest_bad_request( transport: str = "rest", request_type=service.CreateNodePoolRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8365,7 +8785,7 @@ def test_create_node_pool_rest_bad_request( def test_create_node_pool_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8409,7 +8829,7 @@ def test_create_node_pool_rest_flattened(): def test_create_node_pool_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8426,7 +8846,7 @@ def test_create_node_pool_rest_flattened_error(transport: str = "rest"): def test_create_node_pool_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8439,7 +8859,7 @@ def test_create_node_pool_rest_error(): ) def test_update_node_pool_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8563,7 +8983,7 @@ def get_message_fields(field): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_node_pool_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -8621,7 +9041,7 @@ def test_update_node_pool_rest_bad_request( transport: str = "rest", request_type=service.UpdateNodePoolRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8647,7 +9067,7 @@ def test_update_node_pool_rest_bad_request( def test_update_node_pool_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8692,7 +9112,7 @@ def test_update_node_pool_rest_flattened(): def test_update_node_pool_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8708,7 +9128,7 @@ def test_update_node_pool_rest_flattened_error(transport: str = "rest"): def test_update_node_pool_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8721,7 +9141,7 @@ def test_update_node_pool_rest_error(): ) def test_delete_node_pool_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8769,7 +9189,7 @@ def test_delete_node_pool_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8778,7 +9198,7 @@ def test_delete_node_pool_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_node_pool._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("request_id",)) @@ -8789,7 +9209,7 @@ def test_delete_node_pool_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8828,7 +9248,7 @@ def test_delete_node_pool_rest_required_fields( def test_delete_node_pool_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_node_pool._get_unset_required_fields({}) @@ -8838,7 +9258,7 @@ def test_delete_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_node_pool_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -8896,7 +9316,7 @@ def test_delete_node_pool_rest_bad_request( transport: str = "rest", request_type=service.DeleteNodePoolRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8920,7 +9340,7 @@ def test_delete_node_pool_rest_bad_request( def test_delete_node_pool_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8962,7 +9382,7 @@ def test_delete_node_pool_rest_flattened(): def test_delete_node_pool_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8977,7 +9397,7 @@ def test_delete_node_pool_rest_flattened_error(transport: str = "rest"): def test_delete_node_pool_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8990,7 +9410,7 @@ def test_delete_node_pool_rest_error(): ) def test_list_machines_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9041,7 +9461,7 @@ def test_list_machines_rest_required_fields(request_type=service.ListMachinesReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_machines._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9050,7 +9470,7 @@ def test_list_machines_rest_required_fields(request_type=service.ListMachinesReq jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_machines._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -9068,7 +9488,7 @@ def test_list_machines_rest_required_fields(request_type=service.ListMachinesReq assert jsonified_request["parent"] == "parent_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9110,7 +9530,7 @@ def test_list_machines_rest_required_fields(request_type=service.ListMachinesReq def test_list_machines_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_machines._get_unset_required_fields({}) @@ -9130,7 +9550,7 @@ def test_list_machines_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_machines_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -9186,7 +9606,7 @@ def test_list_machines_rest_bad_request( transport: str = "rest", request_type=service.ListMachinesRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9208,7 +9628,7 @@ def test_list_machines_rest_bad_request( def test_list_machines_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9249,7 +9669,7 @@ def test_list_machines_rest_flattened(): def test_list_machines_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9264,7 +9684,7 @@ def test_list_machines_rest_flattened_error(transport: str = "rest"): def test_list_machines_rest_pager(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9332,7 +9752,7 @@ def test_list_machines_rest_pager(transport: str = "rest"): ) def test_get_machine_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9387,7 +9807,7 @@ def test_get_machine_rest_required_fields(request_type=service.GetMachineRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_machine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9396,7 +9816,7 @@ def test_get_machine_rest_required_fields(request_type=service.GetMachineRequest jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_machine._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9405,7 +9825,7 @@ def test_get_machine_rest_required_fields(request_type=service.GetMachineRequest assert jsonified_request["name"] == "name_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9447,7 +9867,7 @@ def test_get_machine_rest_required_fields(request_type=service.GetMachineRequest def test_get_machine_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_machine._get_unset_required_fields({}) @@ -9457,7 +9877,7 @@ def test_get_machine_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_machine_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -9511,7 +9931,7 @@ def test_get_machine_rest_bad_request( transport: str = "rest", request_type=service.GetMachineRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9533,7 +9953,7 @@ def test_get_machine_rest_bad_request( def test_get_machine_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9574,7 +9994,7 @@ def test_get_machine_rest_flattened(): def test_get_machine_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9589,7 +10009,7 @@ def test_get_machine_rest_flattened_error(transport: str = "rest"): def test_get_machine_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9602,7 +10022,7 @@ def test_get_machine_rest_error(): ) def test_list_vpn_connections_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9655,7 +10075,7 @@ def test_list_vpn_connections_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_vpn_connections._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9664,7 +10084,7 @@ def test_list_vpn_connections_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_vpn_connections._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -9682,7 +10102,7 @@ def test_list_vpn_connections_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9724,7 +10144,7 @@ def test_list_vpn_connections_rest_required_fields( def test_list_vpn_connections_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_vpn_connections._get_unset_required_fields({}) @@ -9744,7 +10164,7 @@ def test_list_vpn_connections_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_vpn_connections_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -9802,7 +10222,7 @@ def test_list_vpn_connections_rest_bad_request( transport: str = "rest", request_type=service.ListVpnConnectionsRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9824,7 +10244,7 @@ def test_list_vpn_connections_rest_bad_request( def test_list_vpn_connections_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9866,7 +10286,7 @@ def test_list_vpn_connections_rest_flattened(): def test_list_vpn_connections_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9881,7 +10301,7 @@ def test_list_vpn_connections_rest_flattened_error(transport: str = "rest"): def test_list_vpn_connections_rest_pager(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9951,7 +10371,7 @@ def test_list_vpn_connections_rest_pager(transport: str = "rest"): ) def test_get_vpn_connection_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10012,7 +10432,7 @@ def test_get_vpn_connection_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_vpn_connection._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10021,7 +10441,7 @@ def test_get_vpn_connection_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_vpn_connection._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10030,7 +10450,7 @@ def test_get_vpn_connection_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10072,7 +10492,7 @@ def test_get_vpn_connection_rest_required_fields( def test_get_vpn_connection_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_vpn_connection._get_unset_required_fields({}) @@ -10082,7 +10502,7 @@ def test_get_vpn_connection_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_vpn_connection_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -10140,7 +10560,7 @@ def test_get_vpn_connection_rest_bad_request( transport: str = "rest", request_type=service.GetVpnConnectionRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10162,7 +10582,7 @@ def test_get_vpn_connection_rest_bad_request( def test_get_vpn_connection_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10206,7 +10626,7 @@ def test_get_vpn_connection_rest_flattened(): def test_get_vpn_connection_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10221,7 +10641,7 @@ def test_get_vpn_connection_rest_flattened_error(transport: str = "rest"): def test_get_vpn_connection_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10234,7 +10654,7 @@ def test_get_vpn_connection_rest_error(): ) def test_create_vpn_connection_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10370,7 +10790,7 @@ def test_create_vpn_connection_rest_required_fields( assert "vpnConnectionId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_vpn_connection._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10382,7 +10802,7 @@ def test_create_vpn_connection_rest_required_fields( jsonified_request["vpnConnectionId"] = "vpn_connection_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_vpn_connection._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -10400,7 +10820,7 @@ def test_create_vpn_connection_rest_required_fields( assert jsonified_request["vpnConnectionId"] == "vpn_connection_id_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10446,7 +10866,7 @@ def test_create_vpn_connection_rest_required_fields( def test_create_vpn_connection_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_vpn_connection._get_unset_required_fields({}) @@ -10470,7 +10890,7 @@ def test_create_vpn_connection_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_vpn_connection_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -10530,7 +10950,7 @@ def test_create_vpn_connection_rest_bad_request( transport: str = "rest", request_type=service.CreateVpnConnectionRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10552,7 +10972,7 @@ def test_create_vpn_connection_rest_bad_request( def test_create_vpn_connection_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10594,7 +11014,7 @@ def test_create_vpn_connection_rest_flattened(): def test_create_vpn_connection_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10611,7 +11031,7 @@ def test_create_vpn_connection_rest_flattened_error(transport: str = "rest"): def test_create_vpn_connection_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10624,7 +11044,7 @@ def test_create_vpn_connection_rest_error(): ) def test_delete_vpn_connection_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10670,7 +11090,7 @@ def test_delete_vpn_connection_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_vpn_connection._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10679,7 +11099,7 @@ def test_delete_vpn_connection_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_vpn_connection._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("request_id",)) @@ -10690,7 +11110,7 @@ def test_delete_vpn_connection_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10729,7 +11149,7 @@ def test_delete_vpn_connection_rest_required_fields( def test_delete_vpn_connection_rest_unset_required_fields(): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_vpn_connection._get_unset_required_fields({}) @@ -10739,7 +11159,7 @@ def test_delete_vpn_connection_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_vpn_connection_rest_interceptors(null_interceptor): transport = transports.EdgeContainerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeContainerRestInterceptor(), @@ -10799,7 +11219,7 @@ def test_delete_vpn_connection_rest_bad_request( transport: str = "rest", request_type=service.DeleteVpnConnectionRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10821,7 +11241,7 @@ def test_delete_vpn_connection_rest_bad_request( def test_delete_vpn_connection_rest_flattened(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10863,7 +11283,7 @@ def test_delete_vpn_connection_rest_flattened(): def test_delete_vpn_connection_rest_flattened_error(transport: str = "rest"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10878,24 +11298,24 @@ def test_delete_vpn_connection_rest_flattened_error(transport: str = "rest"): def test_delete_vpn_connection_rest_error(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EdgeContainerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EdgeContainerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EdgeContainerClient( @@ -10905,7 +11325,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EdgeContainerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -10916,16 +11336,17 @@ 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 = EdgeContainerClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EdgeContainerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EdgeContainerClient( @@ -10937,7 +11358,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EdgeContainerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EdgeContainerClient(transport=transport) assert client.transport is transport @@ -10946,13 +11367,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EdgeContainerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EdgeContainerGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -10969,7 +11390,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -10983,7 +11404,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = EdgeContainerClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -10991,7 +11412,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -11003,7 +11424,7 @@ def test_edge_container_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EdgeContainerTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -11015,7 +11436,7 @@ def test_edge_container_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EdgeContainerTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -11074,7 +11495,7 @@ def test_edge_container_base_transport_with_credentials_file(): "google.cloud.edgecontainer_v1.services.edge_container.transports.EdgeContainerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EdgeContainerTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -11093,7 +11514,7 @@ def test_edge_container_base_transport_with_adc(): "google.cloud.edgecontainer_v1.services.edge_container.transports.EdgeContainerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EdgeContainerTransport() adc.assert_called_once() @@ -11101,7 +11522,7 @@ def test_edge_container_base_transport_with_adc(): def test_edge_container_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EdgeContainerClient() adc.assert_called_once_with( scopes=None, @@ -11121,7 +11542,7 @@ def test_edge_container_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -11168,7 +11589,7 @@ def test_edge_container_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -11196,7 +11617,7 @@ def test_edge_container_transport_create_channel(transport_class, grpc_helpers): ], ) def test_edge_container_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -11234,7 +11655,7 @@ def test_edge_container_grpc_transport_client_cert_source_for_mtls(transport_cla def test_edge_container_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -11246,7 +11667,7 @@ def test_edge_container_http_transport_client_cert_source_for_mtls(): def test_edge_container_rest_lro_client(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -11271,7 +11692,7 @@ def test_edge_container_rest_lro_client(): ) def test_edge_container_host_no_port(transport_name): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="edgecontainer.googleapis.com" ), @@ -11294,7 +11715,7 @@ def test_edge_container_host_no_port(transport_name): ) def test_edge_container_host_with_port(transport_name): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="edgecontainer.googleapis.com:8000" ), @@ -11314,8 +11735,8 @@ def test_edge_container_host_with_port(transport_name): ], ) def test_edge_container_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EdgeContainerClient( credentials=creds1, transport=transport_name, @@ -11425,7 +11846,7 @@ def test_edge_container_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -11503,7 +11924,7 @@ def test_edge_container_transport_channel_mtls_with_adc(transport_class): def test_edge_container_grpc_lro_client(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -11520,7 +11941,7 @@ def test_edge_container_grpc_lro_client(): def test_edge_container_grpc_lro_async_client(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -11817,7 +12238,7 @@ def test_client_with_default_client_info(): transports.EdgeContainerTransport, "_prep_wrapped_messages" ) as prep: client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -11827,7 +12248,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EdgeContainerClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -11836,7 +12257,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -11851,7 +12272,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11881,7 +12302,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -11909,7 +12330,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11937,7 +12358,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -11965,7 +12386,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11995,7 +12416,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -12023,7 +12444,7 @@ def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12053,7 +12474,7 @@ def test_delete_operation_rest_bad_request( ) def test_delete_operation_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -12081,7 +12502,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12111,7 +12532,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -12139,7 +12560,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12169,7 +12590,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -12195,7 +12616,7 @@ def test_list_operations_rest(request_type): def test_delete_operation(transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12220,7 +12641,7 @@ def test_delete_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_delete_operation_async(transport: str = "grpc_asyncio"): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12244,7 +12665,7 @@ async def test_delete_operation_async(transport: str = "grpc_asyncio"): def test_delete_operation_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12273,7 +12694,7 @@ def test_delete_operation_field_headers(): @pytest.mark.asyncio async def test_delete_operation_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12300,7 +12721,7 @@ async def test_delete_operation_field_headers_async(): def test_delete_operation_from_dict(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -12318,7 +12739,7 @@ def test_delete_operation_from_dict(): @pytest.mark.asyncio async def test_delete_operation_from_dict_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -12334,7 +12755,7 @@ async def test_delete_operation_from_dict_async(): def test_cancel_operation(transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12359,7 +12780,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12383,7 +12804,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12412,7 +12833,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12439,7 +12860,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -12457,7 +12878,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -12473,7 +12894,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12498,7 +12919,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12524,7 +12945,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12553,7 +12974,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12582,7 +13003,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -12600,7 +13021,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -12618,7 +13039,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12643,7 +13064,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12669,7 +13090,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12698,7 +13119,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12727,7 +13148,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -12745,7 +13166,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -12763,7 +13184,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12788,7 +13209,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12814,7 +13235,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12843,7 +13264,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12872,7 +13293,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12890,7 +13311,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12908,7 +13329,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12933,7 +13354,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12958,7 +13379,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = EdgeContainerClient(credentials=ga_credentials.AnonymousCredentials()) + client = EdgeContainerClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -12985,7 +13406,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = EdgeContainerAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = EdgeContainerAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -13013,7 +13436,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -13031,7 +13454,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = EdgeContainerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -13055,7 +13478,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -13072,7 +13495,7 @@ def test_client_ctx(): ] for transport in transports: client = EdgeContainerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -13103,7 +13526,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, diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork/gapic_version.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork/gapic_version.py index cf99f3acb1ee..360a0d13ebdd 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork/gapic_version.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.2" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/gapic_version.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/gapic_version.py index cf99f3acb1ee..360a0d13ebdd 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/gapic_version.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.1.2" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/async_client.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/async_client.py index 2cef9c711ee6..5db4657d9604 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/async_client.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/async_client.py @@ -38,9 +38,9 @@ from google.cloud.edgenetwork_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -68,8 +68,12 @@ class EdgeNetworkAsyncClient: _client: EdgeNetworkClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EdgeNetworkClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EdgeNetworkClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = EdgeNetworkClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = EdgeNetworkClient._DEFAULT_UNIVERSE interconnect_path = staticmethod(EdgeNetworkClient.interconnect_path) parse_interconnect_path = staticmethod(EdgeNetworkClient.parse_interconnect_path) @@ -186,6 +190,25 @@ def transport(self) -> EdgeNetworkTransport: """ 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(EdgeNetworkClient).get_transport_class, type(EdgeNetworkClient) ) @@ -198,7 +221,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the edge network client. + """Instantiates the edge network async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -209,23 +232,38 @@ def __init__( transport (Union[str, ~.EdgeNetworkTransport]): 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. @@ -327,6 +365,9 @@ async def sample_initialize_zone(): 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, @@ -432,6 +473,9 @@ async def sample_list_zones(): 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, @@ -538,6 +582,9 @@ async def sample_get_zone(): 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, @@ -653,6 +700,9 @@ async def sample_list_networks(): 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, @@ -768,6 +818,9 @@ async def sample_get_network(): 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, @@ -880,6 +933,9 @@ async def sample_diagnose_network(): 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, @@ -1011,6 +1067,9 @@ async def sample_create_network(): 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, @@ -1132,6 +1191,9 @@ async def sample_delete_network(): 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, @@ -1255,6 +1317,9 @@ async def sample_list_subnets(): 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, @@ -1370,6 +1435,9 @@ async def sample_get_subnet(): 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, @@ -1501,6 +1569,9 @@ async def sample_create_subnet(): 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, @@ -1635,6 +1706,9 @@ async def sample_update_subnet(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1756,6 +1830,9 @@ async def sample_delete_subnet(): 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, @@ -1879,6 +1956,9 @@ async def sample_list_interconnects(): 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, @@ -1996,6 +2076,9 @@ async def sample_get_interconnect(): 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, @@ -2110,6 +2193,9 @@ async def sample_diagnose_interconnect(): 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, @@ -2228,6 +2314,9 @@ async def sample_list_interconnect_attachments(): 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, @@ -2346,6 +2435,9 @@ async def sample_get_interconnect_attachment(): 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, @@ -2485,6 +2577,9 @@ async def sample_create_interconnect_attachment(): 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, @@ -2609,6 +2704,9 @@ async def sample_delete_interconnect_attachment(): 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, @@ -2732,6 +2830,9 @@ async def sample_list_routers(): 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, @@ -2847,6 +2948,9 @@ async def sample_get_router(): 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, @@ -2958,6 +3062,9 @@ async def sample_diagnose_router(): 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, @@ -3089,6 +3196,9 @@ async def sample_create_router(): 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, @@ -3223,6 +3333,9 @@ async def sample_update_router(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -3344,6 +3457,9 @@ async def sample_delete_router(): 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, @@ -3406,6 +3522,9 @@ async def list_operations( 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, @@ -3460,6 +3579,9 @@ async def get_operation( 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, @@ -3518,6 +3640,9 @@ async def delete_operation( 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, @@ -3572,6 +3697,9 @@ async def cancel_operation( 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, @@ -3623,6 +3751,9 @@ async def get_location( 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, @@ -3677,6 +3808,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/client.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/client.py index 494ead9ede86..1858f585735f 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/client.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.edgenetwork_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -136,11 +137,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 = "edgenetwork.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "edgenetwork.{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 @@ -411,7 +416,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 @@ -441,6 +446,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") @@ -474,6 +484,175 @@ 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 + + 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 + + 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 = EdgeNetworkClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EdgeNetworkClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = EdgeNetworkClient._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 = EdgeNetworkClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = EdgeNetworkClient._DEFAULT_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 EdgeNetworkClient._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, *, @@ -493,22 +672,32 @@ def __init__( transport (Union[str, EdgeNetworkTransport]): 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. @@ -519,17 +708,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, + ) = EdgeNetworkClient._read_environment_variables() + self._client_cert_source = EdgeNetworkClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = EdgeNetworkClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -538,20 +744,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, EdgeNetworkTransport): + transport_provided = isinstance(transport, EdgeNetworkTransport) + if transport_provided: # transport is a EdgeNetworkTransport 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(EdgeNetworkTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or EdgeNetworkClient._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( @@ -561,17 +777,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 initialize_zone( @@ -664,6 +880,9 @@ def sample_initialize_zone(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -769,6 +988,9 @@ def sample_list_zones(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -875,6 +1097,9 @@ def sample_get_zone(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -981,6 +1206,9 @@ def sample_list_networks(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1087,6 +1315,9 @@ def sample_get_network(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1190,6 +1421,9 @@ def sample_diagnose_network(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1321,6 +1555,9 @@ def sample_create_network(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1442,6 +1679,9 @@ def sample_delete_network(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1556,6 +1796,9 @@ def sample_list_subnets(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1662,6 +1905,9 @@ def sample_get_subnet(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1793,6 +2039,9 @@ def sample_create_subnet(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1927,6 +2176,9 @@ def sample_update_subnet(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2048,6 +2300,9 @@ def sample_delete_subnet(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2162,6 +2417,9 @@ def sample_list_interconnects(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2270,6 +2528,9 @@ def sample_get_interconnect(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2375,6 +2636,9 @@ def sample_diagnose_interconnect(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2486,6 +2750,9 @@ def sample_list_interconnect_attachments(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2597,6 +2864,9 @@ def sample_get_interconnect_attachment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2738,6 +3008,9 @@ def sample_create_interconnect_attachment(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2864,6 +3137,9 @@ def sample_delete_interconnect_attachment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2978,6 +3254,9 @@ def sample_list_routers(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3084,6 +3363,9 @@ def sample_get_router(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3186,6 +3468,9 @@ def sample_diagnose_router(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3317,6 +3602,9 @@ def sample_create_router(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3451,6 +3739,9 @@ def sample_update_router(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3572,6 +3863,9 @@ def sample_delete_router(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3647,6 +3941,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3701,6 +3998,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3759,6 +4059,9 @@ def delete_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3813,6 +4116,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3864,6 +4170,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3918,6 +4227,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/base.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/base.py index 44d75fdaa189..60720743f164 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/base.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'edgenetwork.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 @@ -121,6 +121,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-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc.py index eccbb114a737..a9258b3f867e 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc.py @@ -69,7 +69,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'edgenetwork.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-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc_asyncio.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc_asyncio.py index 77aad988ec70..ea2fdcda5fc4 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc_asyncio.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/grpc_asyncio.py @@ -114,7 +114,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'edgenetwork.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-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/rest.py b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/rest.py index 0cd865dfbc6d..b775ca6a1477 100644 --- a/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/rest.py +++ b/packages/google-cloud-edgenetwork/google/cloud/edgenetwork_v1/services/edge_network/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -1022,7 +1022,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'edgenetwork.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-edgenetwork/samples/generated_samples/snippet_metadata_google.cloud.edgenetwork.v1.json b/packages/google-cloud-edgenetwork/samples/generated_samples/snippet_metadata_google.cloud.edgenetwork.v1.json index 8097c43ca4ef..04d64b8b1330 100644 --- a/packages/google-cloud-edgenetwork/samples/generated_samples/snippet_metadata_google.cloud.edgenetwork.v1.json +++ b/packages/google-cloud-edgenetwork/samples/generated_samples/snippet_metadata_google.cloud.edgenetwork.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-edgenetwork", - "version": "0.1.2" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-edgenetwork/tests/unit/gapic/edgenetwork_v1/test_edge_network.py b/packages/google-cloud-edgenetwork/tests/unit/gapic/edgenetwork_v1/test_edge_network.py index 4cd2a69c0d20..65b50a679299 100644 --- a/packages/google-cloud-edgenetwork/tests/unit/gapic/edgenetwork_v1/test_edge_network.py +++ b/packages/google-cloud-edgenetwork/tests/unit/gapic/edgenetwork_v1/test_edge_network.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -80,6 +80,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -106,6 +129,251 @@ def test__get_default_mtls_endpoint(): assert EdgeNetworkClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert EdgeNetworkClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EdgeNetworkClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EdgeNetworkClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EdgeNetworkClient._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 EdgeNetworkClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EdgeNetworkClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EdgeNetworkClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EdgeNetworkClient._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 EdgeNetworkClient._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 EdgeNetworkClient._get_client_cert_source(None, False) is None + assert ( + EdgeNetworkClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + EdgeNetworkClient._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 ( + EdgeNetworkClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + EdgeNetworkClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EdgeNetworkClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeNetworkClient), +) +@mock.patch.object( + EdgeNetworkAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeNetworkAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EdgeNetworkClient._DEFAULT_UNIVERSE + default_endpoint = EdgeNetworkClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EdgeNetworkClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + EdgeNetworkClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EdgeNetworkClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EdgeNetworkClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EdgeNetworkClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + EdgeNetworkClient._get_api_endpoint(None, None, default_universe, "always") + == EdgeNetworkClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EdgeNetworkClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EdgeNetworkClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EdgeNetworkClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + EdgeNetworkClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EdgeNetworkClient._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 ( + EdgeNetworkClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + EdgeNetworkClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + EdgeNetworkClient._get_universe_domain(None, None) + == EdgeNetworkClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EdgeNetworkClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (EdgeNetworkClient, transports.EdgeNetworkGrpcTransport, "grpc"), + (EdgeNetworkClient, transports.EdgeNetworkRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -115,7 +383,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_edge_network_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -167,7 +435,7 @@ def test_edge_network_client_service_account_always_use_jwt( ], ) def test_edge_network_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -216,19 +484,23 @@ def test_edge_network_client_get_transport_class(): ], ) @mock.patch.object( - EdgeNetworkClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EdgeNetworkClient) + EdgeNetworkClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeNetworkClient), ) @mock.patch.object( EdgeNetworkAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EdgeNetworkAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeNetworkAsyncClient), ) def test_edge_network_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(EdgeNetworkClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -263,7 +535,9 @@ def test_edge_network_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, @@ -293,15 +567,23 @@ def test_edge_network_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") @@ -311,7 +593,9 @@ def test_edge_network_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", @@ -329,7 +613,9 @@ def test_edge_network_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, @@ -361,12 +647,14 @@ def test_edge_network_client_client_options( ], ) @mock.patch.object( - EdgeNetworkClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EdgeNetworkClient) + EdgeNetworkClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeNetworkClient), ) @mock.patch.object( EdgeNetworkAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EdgeNetworkAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeNetworkAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_edge_network_client_mtls_env_auto( @@ -389,7 +677,9 @@ def test_edge_network_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 @@ -421,7 +711,9 @@ def test_edge_network_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 @@ -455,7 +747,9 @@ def test_edge_network_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, @@ -541,6 +835,116 @@ def test_edge_network_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", [EdgeNetworkClient, EdgeNetworkAsyncClient]) +@mock.patch.object( + EdgeNetworkClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeNetworkClient), +) +@mock.patch.object( + EdgeNetworkAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EdgeNetworkAsyncClient), +) +def test_edge_network_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EdgeNetworkClient._DEFAULT_UNIVERSE + default_endpoint = EdgeNetworkClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EdgeNetworkClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -567,7 +971,9 @@ def test_edge_network_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, @@ -602,7 +1008,9 @@ def test_edge_network_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, @@ -655,7 +1063,9 @@ def test_edge_network_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, @@ -672,8 +1082,8 @@ def test_edge_network_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -702,7 +1112,7 @@ def test_edge_network_client_create_channel_credentials_file( ) def test_initialize_zone(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -729,7 +1139,7 @@ def test_initialize_zone_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -746,7 +1156,7 @@ async def test_initialize_zone_async( transport: str = "grpc_asyncio", request_type=service.InitializeZoneRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -778,7 +1188,7 @@ async def test_initialize_zone_async_from_dict(): def test_initialize_zone_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -808,7 +1218,7 @@ def test_initialize_zone_field_headers(): @pytest.mark.asyncio async def test_initialize_zone_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -839,7 +1249,7 @@ async def test_initialize_zone_field_headers_async(): def test_initialize_zone_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -863,7 +1273,7 @@ def test_initialize_zone_flattened(): def test_initialize_zone_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -878,7 +1288,7 @@ def test_initialize_zone_flattened_error(): @pytest.mark.asyncio async def test_initialize_zone_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -907,7 +1317,7 @@ async def test_initialize_zone_flattened_async(): @pytest.mark.asyncio async def test_initialize_zone_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -928,7 +1338,7 @@ async def test_initialize_zone_flattened_error_async(): ) def test_list_zones(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -960,7 +1370,7 @@ def test_list_zones_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -977,7 +1387,7 @@ async def test_list_zones_async( transport: str = "grpc_asyncio", request_type=service.ListZonesRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1014,7 +1424,7 @@ async def test_list_zones_async_from_dict(): def test_list_zones_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1044,7 +1454,7 @@ def test_list_zones_field_headers(): @pytest.mark.asyncio async def test_list_zones_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1075,7 +1485,7 @@ async def test_list_zones_field_headers_async(): def test_list_zones_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1099,7 +1509,7 @@ def test_list_zones_flattened(): def test_list_zones_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1114,7 +1524,7 @@ def test_list_zones_flattened_error(): @pytest.mark.asyncio async def test_list_zones_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1143,7 +1553,7 @@ async def test_list_zones_flattened_async(): @pytest.mark.asyncio async def test_list_zones_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1157,7 +1567,7 @@ async def test_list_zones_flattened_error_async(): def test_list_zones_pager(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1207,7 +1617,7 @@ def test_list_zones_pager(transport_name: str = "grpc"): def test_list_zones_pages(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1249,7 +1659,7 @@ def test_list_zones_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_zones_async_pager(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1299,7 +1709,7 @@ async def test_list_zones_async_pager(): @pytest.mark.asyncio async def test_list_zones_async_pages(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1354,7 +1764,7 @@ async def test_list_zones_async_pages(): ) def test_get_zone(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1386,7 +1796,7 @@ def test_get_zone_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1403,7 +1813,7 @@ async def test_get_zone_async( transport: str = "grpc_asyncio", request_type=service.GetZoneRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1440,7 +1850,7 @@ async def test_get_zone_async_from_dict(): def test_get_zone_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1470,7 +1880,7 @@ def test_get_zone_field_headers(): @pytest.mark.asyncio async def test_get_zone_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1499,7 +1909,7 @@ async def test_get_zone_field_headers_async(): def test_get_zone_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1523,7 +1933,7 @@ def test_get_zone_flattened(): def test_get_zone_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1538,7 +1948,7 @@ def test_get_zone_flattened_error(): @pytest.mark.asyncio async def test_get_zone_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1565,7 +1975,7 @@ async def test_get_zone_flattened_async(): @pytest.mark.asyncio async def test_get_zone_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1586,7 +1996,7 @@ async def test_get_zone_flattened_error_async(): ) def test_list_networks(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1618,7 +2028,7 @@ def test_list_networks_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1635,7 +2045,7 @@ async def test_list_networks_async( transport: str = "grpc_asyncio", request_type=service.ListNetworksRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1672,7 +2082,7 @@ async def test_list_networks_async_from_dict(): def test_list_networks_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1702,7 +2112,7 @@ def test_list_networks_field_headers(): @pytest.mark.asyncio async def test_list_networks_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1733,7 +2143,7 @@ async def test_list_networks_field_headers_async(): def test_list_networks_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1757,7 +2167,7 @@ def test_list_networks_flattened(): def test_list_networks_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1772,7 +2182,7 @@ def test_list_networks_flattened_error(): @pytest.mark.asyncio async def test_list_networks_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1801,7 +2211,7 @@ async def test_list_networks_flattened_async(): @pytest.mark.asyncio async def test_list_networks_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1815,7 +2225,7 @@ async def test_list_networks_flattened_error_async(): def test_list_networks_pager(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1865,7 +2275,7 @@ def test_list_networks_pager(transport_name: str = "grpc"): def test_list_networks_pages(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1907,7 +2317,7 @@ def test_list_networks_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_networks_async_pager(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1957,7 +2367,7 @@ async def test_list_networks_async_pager(): @pytest.mark.asyncio async def test_list_networks_async_pages(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2012,7 +2422,7 @@ async def test_list_networks_async_pages(): ) def test_get_network(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2046,7 +2456,7 @@ def test_get_network_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2063,7 +2473,7 @@ async def test_get_network_async( transport: str = "grpc_asyncio", request_type=service.GetNetworkRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2102,7 +2512,7 @@ async def test_get_network_async_from_dict(): def test_get_network_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2132,7 +2542,7 @@ def test_get_network_field_headers(): @pytest.mark.asyncio async def test_get_network_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2161,7 +2571,7 @@ async def test_get_network_field_headers_async(): def test_get_network_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2185,7 +2595,7 @@ def test_get_network_flattened(): def test_get_network_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2200,7 +2610,7 @@ def test_get_network_flattened_error(): @pytest.mark.asyncio async def test_get_network_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2227,7 +2637,7 @@ async def test_get_network_flattened_async(): @pytest.mark.asyncio async def test_get_network_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2248,7 +2658,7 @@ async def test_get_network_flattened_error_async(): ) def test_diagnose_network(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2275,7 +2685,7 @@ def test_diagnose_network_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2292,7 +2702,7 @@ async def test_diagnose_network_async( transport: str = "grpc_asyncio", request_type=service.DiagnoseNetworkRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2324,7 +2734,7 @@ async def test_diagnose_network_async_from_dict(): def test_diagnose_network_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2354,7 +2764,7 @@ def test_diagnose_network_field_headers(): @pytest.mark.asyncio async def test_diagnose_network_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2385,7 +2795,7 @@ async def test_diagnose_network_field_headers_async(): def test_diagnose_network_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2409,7 +2819,7 @@ def test_diagnose_network_flattened(): def test_diagnose_network_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2424,7 +2834,7 @@ def test_diagnose_network_flattened_error(): @pytest.mark.asyncio async def test_diagnose_network_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2453,7 +2863,7 @@ async def test_diagnose_network_flattened_async(): @pytest.mark.asyncio async def test_diagnose_network_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2474,7 +2884,7 @@ async def test_diagnose_network_flattened_error_async(): ) def test_create_network(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2501,7 +2911,7 @@ def test_create_network_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2518,7 +2928,7 @@ async def test_create_network_async( transport: str = "grpc_asyncio", request_type=service.CreateNetworkRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2550,7 +2960,7 @@ async def test_create_network_async_from_dict(): def test_create_network_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2580,7 +2990,7 @@ def test_create_network_field_headers(): @pytest.mark.asyncio async def test_create_network_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2611,7 +3021,7 @@ async def test_create_network_field_headers_async(): def test_create_network_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2643,7 +3053,7 @@ def test_create_network_flattened(): def test_create_network_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2660,7 +3070,7 @@ def test_create_network_flattened_error(): @pytest.mark.asyncio async def test_create_network_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2697,7 +3107,7 @@ async def test_create_network_flattened_async(): @pytest.mark.asyncio async def test_create_network_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2720,7 +3130,7 @@ async def test_create_network_flattened_error_async(): ) def test_delete_network(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2747,7 +3157,7 @@ def test_delete_network_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2764,7 +3174,7 @@ async def test_delete_network_async( transport: str = "grpc_asyncio", request_type=service.DeleteNetworkRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2796,7 +3206,7 @@ async def test_delete_network_async_from_dict(): def test_delete_network_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2826,7 +3236,7 @@ def test_delete_network_field_headers(): @pytest.mark.asyncio async def test_delete_network_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2857,7 +3267,7 @@ async def test_delete_network_field_headers_async(): def test_delete_network_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2881,7 +3291,7 @@ def test_delete_network_flattened(): def test_delete_network_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2896,7 +3306,7 @@ def test_delete_network_flattened_error(): @pytest.mark.asyncio async def test_delete_network_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2925,7 +3335,7 @@ async def test_delete_network_flattened_async(): @pytest.mark.asyncio async def test_delete_network_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2946,7 +3356,7 @@ async def test_delete_network_flattened_error_async(): ) def test_list_subnets(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2978,7 +3388,7 @@ def test_list_subnets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2995,7 +3405,7 @@ async def test_list_subnets_async( transport: str = "grpc_asyncio", request_type=service.ListSubnetsRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3032,7 +3442,7 @@ async def test_list_subnets_async_from_dict(): def test_list_subnets_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3062,7 +3472,7 @@ def test_list_subnets_field_headers(): @pytest.mark.asyncio async def test_list_subnets_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3093,7 +3503,7 @@ async def test_list_subnets_field_headers_async(): def test_list_subnets_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3117,7 +3527,7 @@ def test_list_subnets_flattened(): def test_list_subnets_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3132,7 +3542,7 @@ def test_list_subnets_flattened_error(): @pytest.mark.asyncio async def test_list_subnets_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3161,7 +3571,7 @@ async def test_list_subnets_flattened_async(): @pytest.mark.asyncio async def test_list_subnets_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3175,7 +3585,7 @@ async def test_list_subnets_flattened_error_async(): def test_list_subnets_pager(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3225,7 +3635,7 @@ def test_list_subnets_pager(transport_name: str = "grpc"): def test_list_subnets_pages(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3267,7 +3677,7 @@ def test_list_subnets_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_subnets_async_pager(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3317,7 +3727,7 @@ async def test_list_subnets_async_pager(): @pytest.mark.asyncio async def test_list_subnets_async_pages(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3372,7 +3782,7 @@ async def test_list_subnets_async_pages(): ) def test_get_subnet(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3414,7 +3824,7 @@ def test_get_subnet_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3431,7 +3841,7 @@ async def test_get_subnet_async( transport: str = "grpc_asyncio", request_type=service.GetSubnetRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3478,7 +3888,7 @@ async def test_get_subnet_async_from_dict(): def test_get_subnet_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3508,7 +3918,7 @@ def test_get_subnet_field_headers(): @pytest.mark.asyncio async def test_get_subnet_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3537,7 +3947,7 @@ async def test_get_subnet_field_headers_async(): def test_get_subnet_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3561,7 +3971,7 @@ def test_get_subnet_flattened(): def test_get_subnet_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3576,7 +3986,7 @@ def test_get_subnet_flattened_error(): @pytest.mark.asyncio async def test_get_subnet_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3603,7 +4013,7 @@ async def test_get_subnet_flattened_async(): @pytest.mark.asyncio async def test_get_subnet_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3624,7 +4034,7 @@ async def test_get_subnet_flattened_error_async(): ) def test_create_subnet(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3651,7 +4061,7 @@ def test_create_subnet_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3668,7 +4078,7 @@ async def test_create_subnet_async( transport: str = "grpc_asyncio", request_type=service.CreateSubnetRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3700,7 +4110,7 @@ async def test_create_subnet_async_from_dict(): def test_create_subnet_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3730,7 +4140,7 @@ def test_create_subnet_field_headers(): @pytest.mark.asyncio async def test_create_subnet_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3761,7 +4171,7 @@ async def test_create_subnet_field_headers_async(): def test_create_subnet_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3793,7 +4203,7 @@ def test_create_subnet_flattened(): def test_create_subnet_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3810,7 +4220,7 @@ def test_create_subnet_flattened_error(): @pytest.mark.asyncio async def test_create_subnet_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3847,7 +4257,7 @@ async def test_create_subnet_flattened_async(): @pytest.mark.asyncio async def test_create_subnet_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3870,7 +4280,7 @@ async def test_create_subnet_flattened_error_async(): ) def test_update_subnet(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3897,7 +4307,7 @@ def test_update_subnet_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3914,7 +4324,7 @@ async def test_update_subnet_async( transport: str = "grpc_asyncio", request_type=service.UpdateSubnetRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3946,7 +4356,7 @@ async def test_update_subnet_async_from_dict(): def test_update_subnet_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3976,7 +4386,7 @@ def test_update_subnet_field_headers(): @pytest.mark.asyncio async def test_update_subnet_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4007,7 +4417,7 @@ async def test_update_subnet_field_headers_async(): def test_update_subnet_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4035,7 +4445,7 @@ def test_update_subnet_flattened(): def test_update_subnet_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4051,7 +4461,7 @@ def test_update_subnet_flattened_error(): @pytest.mark.asyncio async def test_update_subnet_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4084,7 +4494,7 @@ async def test_update_subnet_flattened_async(): @pytest.mark.asyncio async def test_update_subnet_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4106,7 +4516,7 @@ async def test_update_subnet_flattened_error_async(): ) def test_delete_subnet(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4133,7 +4543,7 @@ def test_delete_subnet_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4150,7 +4560,7 @@ async def test_delete_subnet_async( transport: str = "grpc_asyncio", request_type=service.DeleteSubnetRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4182,7 +4592,7 @@ async def test_delete_subnet_async_from_dict(): def test_delete_subnet_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4212,7 +4622,7 @@ def test_delete_subnet_field_headers(): @pytest.mark.asyncio async def test_delete_subnet_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4243,7 +4653,7 @@ async def test_delete_subnet_field_headers_async(): def test_delete_subnet_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4267,7 +4677,7 @@ def test_delete_subnet_flattened(): def test_delete_subnet_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4282,7 +4692,7 @@ def test_delete_subnet_flattened_error(): @pytest.mark.asyncio async def test_delete_subnet_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4311,7 +4721,7 @@ async def test_delete_subnet_flattened_async(): @pytest.mark.asyncio async def test_delete_subnet_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4332,7 +4742,7 @@ async def test_delete_subnet_flattened_error_async(): ) def test_list_interconnects(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4366,7 +4776,7 @@ def test_list_interconnects_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4385,7 +4795,7 @@ async def test_list_interconnects_async( transport: str = "grpc_asyncio", request_type=service.ListInterconnectsRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4424,7 +4834,7 @@ async def test_list_interconnects_async_from_dict(): def test_list_interconnects_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4456,7 +4866,7 @@ def test_list_interconnects_field_headers(): @pytest.mark.asyncio async def test_list_interconnects_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4489,7 +4899,7 @@ async def test_list_interconnects_field_headers_async(): def test_list_interconnects_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4515,7 +4925,7 @@ def test_list_interconnects_flattened(): def test_list_interconnects_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4530,7 +4940,7 @@ def test_list_interconnects_flattened_error(): @pytest.mark.asyncio async def test_list_interconnects_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4561,7 +4971,7 @@ async def test_list_interconnects_flattened_async(): @pytest.mark.asyncio async def test_list_interconnects_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4575,7 +4985,7 @@ async def test_list_interconnects_flattened_error_async(): def test_list_interconnects_pager(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4627,7 +5037,7 @@ def test_list_interconnects_pager(transport_name: str = "grpc"): def test_list_interconnects_pages(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4671,7 +5081,7 @@ def test_list_interconnects_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_interconnects_async_pager(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4723,7 +5133,7 @@ async def test_list_interconnects_async_pager(): @pytest.mark.asyncio async def test_list_interconnects_async_pages(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4780,7 +5190,7 @@ async def test_list_interconnects_async_pages(): ) def test_get_interconnect(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4822,7 +5232,7 @@ def test_get_interconnect_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4839,7 +5249,7 @@ async def test_get_interconnect_async( transport: str = "grpc_asyncio", request_type=service.GetInterconnectRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4886,7 +5296,7 @@ async def test_get_interconnect_async_from_dict(): def test_get_interconnect_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4916,7 +5326,7 @@ def test_get_interconnect_field_headers(): @pytest.mark.asyncio async def test_get_interconnect_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4947,7 +5357,7 @@ async def test_get_interconnect_field_headers_async(): def test_get_interconnect_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4971,7 +5381,7 @@ def test_get_interconnect_flattened(): def test_get_interconnect_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4986,7 +5396,7 @@ def test_get_interconnect_flattened_error(): @pytest.mark.asyncio async def test_get_interconnect_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5015,7 +5425,7 @@ async def test_get_interconnect_flattened_async(): @pytest.mark.asyncio async def test_get_interconnect_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5036,7 +5446,7 @@ async def test_get_interconnect_flattened_error_async(): ) def test_diagnose_interconnect(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5065,7 +5475,7 @@ def test_diagnose_interconnect_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5084,7 +5494,7 @@ async def test_diagnose_interconnect_async( transport: str = "grpc_asyncio", request_type=service.DiagnoseInterconnectRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5118,7 +5528,7 @@ async def test_diagnose_interconnect_async_from_dict(): def test_diagnose_interconnect_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5150,7 +5560,7 @@ def test_diagnose_interconnect_field_headers(): @pytest.mark.asyncio async def test_diagnose_interconnect_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5183,7 +5593,7 @@ async def test_diagnose_interconnect_field_headers_async(): def test_diagnose_interconnect_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5209,7 +5619,7 @@ def test_diagnose_interconnect_flattened(): def test_diagnose_interconnect_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5224,7 +5634,7 @@ def test_diagnose_interconnect_flattened_error(): @pytest.mark.asyncio async def test_diagnose_interconnect_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5255,7 +5665,7 @@ async def test_diagnose_interconnect_flattened_async(): @pytest.mark.asyncio async def test_diagnose_interconnect_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5276,7 +5686,7 @@ async def test_diagnose_interconnect_flattened_error_async(): ) def test_list_interconnect_attachments(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5310,7 +5720,7 @@ def test_list_interconnect_attachments_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5330,7 +5740,7 @@ async def test_list_interconnect_attachments_async( request_type=service.ListInterconnectAttachmentsRequest, ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5369,7 +5779,7 @@ async def test_list_interconnect_attachments_async_from_dict(): def test_list_interconnect_attachments_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5401,7 +5811,7 @@ def test_list_interconnect_attachments_field_headers(): @pytest.mark.asyncio async def test_list_interconnect_attachments_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5434,7 +5844,7 @@ async def test_list_interconnect_attachments_field_headers_async(): def test_list_interconnect_attachments_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5460,7 +5870,7 @@ def test_list_interconnect_attachments_flattened(): def test_list_interconnect_attachments_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5475,7 +5885,7 @@ def test_list_interconnect_attachments_flattened_error(): @pytest.mark.asyncio async def test_list_interconnect_attachments_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5506,7 +5916,7 @@ async def test_list_interconnect_attachments_flattened_async(): @pytest.mark.asyncio async def test_list_interconnect_attachments_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5520,7 +5930,7 @@ async def test_list_interconnect_attachments_flattened_error_async(): def test_list_interconnect_attachments_pager(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -5572,7 +5982,7 @@ def test_list_interconnect_attachments_pager(transport_name: str = "grpc"): def test_list_interconnect_attachments_pages(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -5616,7 +6026,7 @@ def test_list_interconnect_attachments_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_interconnect_attachments_async_pager(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5668,7 +6078,7 @@ async def test_list_interconnect_attachments_async_pager(): @pytest.mark.asyncio async def test_list_interconnect_attachments_async_pages(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5725,7 +6135,7 @@ async def test_list_interconnect_attachments_async_pages(): ) def test_get_interconnect_attachment(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5769,7 +6179,7 @@ def test_get_interconnect_attachment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5789,7 +6199,7 @@ async def test_get_interconnect_attachment_async( request_type=service.GetInterconnectAttachmentRequest, ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5838,7 +6248,7 @@ async def test_get_interconnect_attachment_async_from_dict(): def test_get_interconnect_attachment_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5870,7 +6280,7 @@ def test_get_interconnect_attachment_field_headers(): @pytest.mark.asyncio async def test_get_interconnect_attachment_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5903,7 +6313,7 @@ async def test_get_interconnect_attachment_field_headers_async(): def test_get_interconnect_attachment_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5929,7 +6339,7 @@ def test_get_interconnect_attachment_flattened(): def test_get_interconnect_attachment_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5944,7 +6354,7 @@ def test_get_interconnect_attachment_flattened_error(): @pytest.mark.asyncio async def test_get_interconnect_attachment_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5975,7 +6385,7 @@ async def test_get_interconnect_attachment_flattened_async(): @pytest.mark.asyncio async def test_get_interconnect_attachment_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5996,7 +6406,7 @@ async def test_get_interconnect_attachment_flattened_error_async(): ) def test_create_interconnect_attachment(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6025,7 +6435,7 @@ def test_create_interconnect_attachment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6045,7 +6455,7 @@ async def test_create_interconnect_attachment_async( request_type=service.CreateInterconnectAttachmentRequest, ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6079,7 +6489,7 @@ async def test_create_interconnect_attachment_async_from_dict(): def test_create_interconnect_attachment_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6111,7 +6521,7 @@ def test_create_interconnect_attachment_field_headers(): @pytest.mark.asyncio async def test_create_interconnect_attachment_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6144,7 +6554,7 @@ async def test_create_interconnect_attachment_field_headers_async(): def test_create_interconnect_attachment_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6178,7 +6588,7 @@ def test_create_interconnect_attachment_flattened(): def test_create_interconnect_attachment_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6195,7 +6605,7 @@ def test_create_interconnect_attachment_flattened_error(): @pytest.mark.asyncio async def test_create_interconnect_attachment_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6234,7 +6644,7 @@ async def test_create_interconnect_attachment_flattened_async(): @pytest.mark.asyncio async def test_create_interconnect_attachment_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6257,7 +6667,7 @@ async def test_create_interconnect_attachment_flattened_error_async(): ) def test_delete_interconnect_attachment(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6286,7 +6696,7 @@ def test_delete_interconnect_attachment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6306,7 +6716,7 @@ async def test_delete_interconnect_attachment_async( request_type=service.DeleteInterconnectAttachmentRequest, ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6340,7 +6750,7 @@ async def test_delete_interconnect_attachment_async_from_dict(): def test_delete_interconnect_attachment_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6372,7 +6782,7 @@ def test_delete_interconnect_attachment_field_headers(): @pytest.mark.asyncio async def test_delete_interconnect_attachment_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6405,7 +6815,7 @@ async def test_delete_interconnect_attachment_field_headers_async(): def test_delete_interconnect_attachment_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6431,7 +6841,7 @@ def test_delete_interconnect_attachment_flattened(): def test_delete_interconnect_attachment_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6446,7 +6856,7 @@ def test_delete_interconnect_attachment_flattened_error(): @pytest.mark.asyncio async def test_delete_interconnect_attachment_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6477,7 +6887,7 @@ async def test_delete_interconnect_attachment_flattened_async(): @pytest.mark.asyncio async def test_delete_interconnect_attachment_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6498,7 +6908,7 @@ async def test_delete_interconnect_attachment_flattened_error_async(): ) def test_list_routers(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6530,7 +6940,7 @@ def test_list_routers_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6547,7 +6957,7 @@ async def test_list_routers_async( transport: str = "grpc_asyncio", request_type=service.ListRoutersRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6584,7 +6994,7 @@ async def test_list_routers_async_from_dict(): def test_list_routers_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6614,7 +7024,7 @@ def test_list_routers_field_headers(): @pytest.mark.asyncio async def test_list_routers_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6645,7 +7055,7 @@ async def test_list_routers_field_headers_async(): def test_list_routers_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6669,7 +7079,7 @@ def test_list_routers_flattened(): def test_list_routers_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6684,7 +7094,7 @@ def test_list_routers_flattened_error(): @pytest.mark.asyncio async def test_list_routers_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6713,7 +7123,7 @@ async def test_list_routers_flattened_async(): @pytest.mark.asyncio async def test_list_routers_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6727,7 +7137,7 @@ async def test_list_routers_flattened_error_async(): def test_list_routers_pager(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6777,7 +7187,7 @@ def test_list_routers_pager(transport_name: str = "grpc"): def test_list_routers_pages(transport_name: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6819,7 +7229,7 @@ def test_list_routers_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_routers_async_pager(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6869,7 +7279,7 @@ async def test_list_routers_async_pager(): @pytest.mark.asyncio async def test_list_routers_async_pages(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6924,7 +7334,7 @@ async def test_list_routers_async_pages(): ) def test_get_router(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6962,7 +7372,7 @@ def test_get_router_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6979,7 +7389,7 @@ async def test_get_router_async( transport: str = "grpc_asyncio", request_type=service.GetRouterRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7022,7 +7432,7 @@ async def test_get_router_async_from_dict(): def test_get_router_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7052,7 +7462,7 @@ def test_get_router_field_headers(): @pytest.mark.asyncio async def test_get_router_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7081,7 +7491,7 @@ async def test_get_router_field_headers_async(): def test_get_router_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7105,7 +7515,7 @@ def test_get_router_flattened(): def test_get_router_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7120,7 +7530,7 @@ def test_get_router_flattened_error(): @pytest.mark.asyncio async def test_get_router_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7147,7 +7557,7 @@ async def test_get_router_flattened_async(): @pytest.mark.asyncio async def test_get_router_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7168,7 +7578,7 @@ async def test_get_router_flattened_error_async(): ) def test_diagnose_router(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7195,7 +7605,7 @@ def test_diagnose_router_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7212,7 +7622,7 @@ async def test_diagnose_router_async( transport: str = "grpc_asyncio", request_type=service.DiagnoseRouterRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7244,7 +7654,7 @@ async def test_diagnose_router_async_from_dict(): def test_diagnose_router_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7274,7 +7684,7 @@ def test_diagnose_router_field_headers(): @pytest.mark.asyncio async def test_diagnose_router_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7305,7 +7715,7 @@ async def test_diagnose_router_field_headers_async(): def test_diagnose_router_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7329,7 +7739,7 @@ def test_diagnose_router_flattened(): def test_diagnose_router_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7344,7 +7754,7 @@ def test_diagnose_router_flattened_error(): @pytest.mark.asyncio async def test_diagnose_router_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7373,7 +7783,7 @@ async def test_diagnose_router_flattened_async(): @pytest.mark.asyncio async def test_diagnose_router_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7394,7 +7804,7 @@ async def test_diagnose_router_flattened_error_async(): ) def test_create_router(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7421,7 +7831,7 @@ def test_create_router_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7438,7 +7848,7 @@ async def test_create_router_async( transport: str = "grpc_asyncio", request_type=service.CreateRouterRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7470,7 +7880,7 @@ async def test_create_router_async_from_dict(): def test_create_router_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7500,7 +7910,7 @@ def test_create_router_field_headers(): @pytest.mark.asyncio async def test_create_router_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7531,7 +7941,7 @@ async def test_create_router_field_headers_async(): def test_create_router_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7563,7 +7973,7 @@ def test_create_router_flattened(): def test_create_router_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7580,7 +7990,7 @@ def test_create_router_flattened_error(): @pytest.mark.asyncio async def test_create_router_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7617,7 +8027,7 @@ async def test_create_router_flattened_async(): @pytest.mark.asyncio async def test_create_router_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7640,7 +8050,7 @@ async def test_create_router_flattened_error_async(): ) def test_update_router(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7667,7 +8077,7 @@ def test_update_router_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7684,7 +8094,7 @@ async def test_update_router_async( transport: str = "grpc_asyncio", request_type=service.UpdateRouterRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7716,7 +8126,7 @@ async def test_update_router_async_from_dict(): def test_update_router_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7746,7 +8156,7 @@ def test_update_router_field_headers(): @pytest.mark.asyncio async def test_update_router_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7777,7 +8187,7 @@ async def test_update_router_field_headers_async(): def test_update_router_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7805,7 +8215,7 @@ def test_update_router_flattened(): def test_update_router_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7821,7 +8231,7 @@ def test_update_router_flattened_error(): @pytest.mark.asyncio async def test_update_router_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7854,7 +8264,7 @@ async def test_update_router_flattened_async(): @pytest.mark.asyncio async def test_update_router_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7876,7 +8286,7 @@ async def test_update_router_flattened_error_async(): ) def test_delete_router(request_type, transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7903,7 +8313,7 @@ def test_delete_router_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7920,7 +8330,7 @@ async def test_delete_router_async( transport: str = "grpc_asyncio", request_type=service.DeleteRouterRequest ): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7952,7 +8362,7 @@ async def test_delete_router_async_from_dict(): def test_delete_router_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7982,7 +8392,7 @@ def test_delete_router_field_headers(): @pytest.mark.asyncio async def test_delete_router_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -8013,7 +8423,7 @@ async def test_delete_router_field_headers_async(): def test_delete_router_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8037,7 +8447,7 @@ def test_delete_router_flattened(): def test_delete_router_flattened_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8052,7 +8462,7 @@ def test_delete_router_flattened_error(): @pytest.mark.asyncio async def test_delete_router_flattened_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -8081,7 +8491,7 @@ async def test_delete_router_flattened_async(): @pytest.mark.asyncio async def test_delete_router_flattened_error_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -8102,7 +8512,7 @@ async def test_delete_router_flattened_error_async(): ) def test_initialize_zone_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8150,7 +8560,7 @@ def test_initialize_zone_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).initialize_zone._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8159,7 +8569,7 @@ def test_initialize_zone_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).initialize_zone._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8168,7 +8578,7 @@ def test_initialize_zone_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8211,7 +8621,7 @@ def test_initialize_zone_rest_required_fields( def test_initialize_zone_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.initialize_zone._get_unset_required_fields({}) @@ -8221,7 +8631,7 @@ def test_initialize_zone_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_initialize_zone_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -8277,7 +8687,7 @@ def test_initialize_zone_rest_bad_request( transport: str = "rest", request_type=service.InitializeZoneRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8299,7 +8709,7 @@ def test_initialize_zone_rest_bad_request( def test_initialize_zone_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8341,7 +8751,7 @@ def test_initialize_zone_rest_flattened(): def test_initialize_zone_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8356,7 +8766,7 @@ def test_initialize_zone_rest_flattened_error(transport: str = "rest"): def test_initialize_zone_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8369,7 +8779,7 @@ def test_initialize_zone_rest_error(): ) def test_list_zones_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8420,7 +8830,7 @@ def test_list_zones_rest_required_fields(request_type=service.ListZonesRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_zones._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8429,7 +8839,7 @@ def test_list_zones_rest_required_fields(request_type=service.ListZonesRequest): jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_zones._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8447,7 +8857,7 @@ def test_list_zones_rest_required_fields(request_type=service.ListZonesRequest): assert jsonified_request["parent"] == "parent_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8489,7 +8899,7 @@ def test_list_zones_rest_required_fields(request_type=service.ListZonesRequest): def test_list_zones_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_zones._get_unset_required_fields({}) @@ -8509,7 +8919,7 @@ def test_list_zones_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_zones_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -8565,7 +8975,7 @@ def test_list_zones_rest_bad_request( transport: str = "rest", request_type=service.ListZonesRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8587,7 +8997,7 @@ def test_list_zones_rest_bad_request( def test_list_zones_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8628,7 +9038,7 @@ def test_list_zones_rest_flattened(): def test_list_zones_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8643,7 +9053,7 @@ def test_list_zones_rest_flattened_error(transport: str = "rest"): def test_list_zones_rest_pager(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8711,7 +9121,7 @@ def test_list_zones_rest_pager(transport: str = "rest"): ) def test_get_zone_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8762,7 +9172,7 @@ def test_get_zone_rest_required_fields(request_type=service.GetZoneRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_zone._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8771,7 +9181,7 @@ def test_get_zone_rest_required_fields(request_type=service.GetZoneRequest): jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_zone._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8780,7 +9190,7 @@ def test_get_zone_rest_required_fields(request_type=service.GetZoneRequest): assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8822,7 +9232,7 @@ def test_get_zone_rest_required_fields(request_type=service.GetZoneRequest): def test_get_zone_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_zone._get_unset_required_fields({}) @@ -8832,7 +9242,7 @@ def test_get_zone_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_zone_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -8886,7 +9296,7 @@ def test_get_zone_rest_bad_request( transport: str = "rest", request_type=service.GetZoneRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8908,7 +9318,7 @@ def test_get_zone_rest_bad_request( def test_get_zone_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8949,7 +9359,7 @@ def test_get_zone_rest_flattened(): def test_get_zone_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8964,7 +9374,7 @@ def test_get_zone_rest_flattened_error(transport: str = "rest"): def test_get_zone_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8977,7 +9387,7 @@ def test_get_zone_rest_error(): ) def test_list_networks_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9028,7 +9438,7 @@ def test_list_networks_rest_required_fields(request_type=service.ListNetworksReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_networks._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9037,7 +9447,7 @@ def test_list_networks_rest_required_fields(request_type=service.ListNetworksReq jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_networks._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -9055,7 +9465,7 @@ def test_list_networks_rest_required_fields(request_type=service.ListNetworksReq assert jsonified_request["parent"] == "parent_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9097,7 +9507,7 @@ def test_list_networks_rest_required_fields(request_type=service.ListNetworksReq def test_list_networks_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_networks._get_unset_required_fields({}) @@ -9117,7 +9527,7 @@ def test_list_networks_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_networks_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -9173,7 +9583,7 @@ def test_list_networks_rest_bad_request( transport: str = "rest", request_type=service.ListNetworksRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9195,7 +9605,7 @@ def test_list_networks_rest_bad_request( def test_list_networks_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9237,7 +9647,7 @@ def test_list_networks_rest_flattened(): def test_list_networks_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9252,7 +9662,7 @@ def test_list_networks_rest_flattened_error(transport: str = "rest"): def test_list_networks_rest_pager(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9320,7 +9730,7 @@ def test_list_networks_rest_pager(transport: str = "rest"): ) def test_get_network_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9375,7 +9785,7 @@ def test_get_network_rest_required_fields(request_type=service.GetNetworkRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_network._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9384,7 +9794,7 @@ def test_get_network_rest_required_fields(request_type=service.GetNetworkRequest jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_network._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9393,7 +9803,7 @@ def test_get_network_rest_required_fields(request_type=service.GetNetworkRequest assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9435,7 +9845,7 @@ def test_get_network_rest_required_fields(request_type=service.GetNetworkRequest def test_get_network_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_network._get_unset_required_fields({}) @@ -9445,7 +9855,7 @@ def test_get_network_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_network_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -9499,7 +9909,7 @@ def test_get_network_rest_bad_request( transport: str = "rest", request_type=service.GetNetworkRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9523,7 +9933,7 @@ def test_get_network_rest_bad_request( def test_get_network_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9567,7 +9977,7 @@ def test_get_network_rest_flattened(): def test_get_network_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9582,7 +9992,7 @@ def test_get_network_rest_flattened_error(transport: str = "rest"): def test_get_network_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9595,7 +10005,7 @@ def test_get_network_rest_error(): ) def test_diagnose_network_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9645,7 +10055,7 @@ def test_diagnose_network_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).diagnose_network._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9654,7 +10064,7 @@ def test_diagnose_network_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).diagnose_network._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9663,7 +10073,7 @@ def test_diagnose_network_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9705,7 +10115,7 @@ def test_diagnose_network_rest_required_fields( def test_diagnose_network_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.diagnose_network._get_unset_required_fields({}) @@ -9715,7 +10125,7 @@ def test_diagnose_network_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_diagnose_network_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -9771,7 +10181,7 @@ def test_diagnose_network_rest_bad_request( transport: str = "rest", request_type=service.DiagnoseNetworkRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9795,7 +10205,7 @@ def test_diagnose_network_rest_bad_request( def test_diagnose_network_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9839,7 +10249,7 @@ def test_diagnose_network_rest_flattened(): def test_diagnose_network_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9854,7 +10264,7 @@ def test_diagnose_network_rest_flattened_error(transport: str = "rest"): def test_diagnose_network_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9867,7 +10277,7 @@ def test_diagnose_network_rest_error(): ) def test_create_network_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9988,7 +10398,7 @@ def test_create_network_rest_required_fields(request_type=service.CreateNetworkR assert "networkId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_network._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10000,7 +10410,7 @@ def test_create_network_rest_required_fields(request_type=service.CreateNetworkR jsonified_request["networkId"] = "network_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_network._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -10018,7 +10428,7 @@ def test_create_network_rest_required_fields(request_type=service.CreateNetworkR assert jsonified_request["networkId"] == "network_id_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10064,7 +10474,7 @@ def test_create_network_rest_required_fields(request_type=service.CreateNetworkR def test_create_network_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_network._get_unset_required_fields({}) @@ -10088,7 +10498,7 @@ def test_create_network_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_network_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -10146,7 +10556,7 @@ def test_create_network_rest_bad_request( transport: str = "rest", request_type=service.CreateNetworkRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10168,7 +10578,7 @@ def test_create_network_rest_bad_request( def test_create_network_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10210,7 +10620,7 @@ def test_create_network_rest_flattened(): def test_create_network_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10227,7 +10637,7 @@ def test_create_network_rest_flattened_error(transport: str = "rest"): def test_create_network_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10240,7 +10650,7 @@ def test_create_network_rest_error(): ) def test_delete_network_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10286,7 +10696,7 @@ def test_delete_network_rest_required_fields(request_type=service.DeleteNetworkR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_network._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10295,7 +10705,7 @@ def test_delete_network_rest_required_fields(request_type=service.DeleteNetworkR jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_network._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("request_id",)) @@ -10306,7 +10716,7 @@ def test_delete_network_rest_required_fields(request_type=service.DeleteNetworkR assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10345,7 +10755,7 @@ def test_delete_network_rest_required_fields(request_type=service.DeleteNetworkR def test_delete_network_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_network._get_unset_required_fields({}) @@ -10355,7 +10765,7 @@ def test_delete_network_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_network_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -10413,7 +10823,7 @@ def test_delete_network_rest_bad_request( transport: str = "rest", request_type=service.DeleteNetworkRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10437,7 +10847,7 @@ def test_delete_network_rest_bad_request( def test_delete_network_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10479,7 +10889,7 @@ def test_delete_network_rest_flattened(): def test_delete_network_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10494,7 +10904,7 @@ def test_delete_network_rest_flattened_error(transport: str = "rest"): def test_delete_network_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10507,7 +10917,7 @@ def test_delete_network_rest_error(): ) def test_list_subnets_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10558,7 +10968,7 @@ def test_list_subnets_rest_required_fields(request_type=service.ListSubnetsReque # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_subnets._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10567,7 +10977,7 @@ def test_list_subnets_rest_required_fields(request_type=service.ListSubnetsReque jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_subnets._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -10585,7 +10995,7 @@ def test_list_subnets_rest_required_fields(request_type=service.ListSubnetsReque assert jsonified_request["parent"] == "parent_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10627,7 +11037,7 @@ def test_list_subnets_rest_required_fields(request_type=service.ListSubnetsReque def test_list_subnets_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_subnets._get_unset_required_fields({}) @@ -10647,7 +11057,7 @@ def test_list_subnets_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_subnets_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -10703,7 +11113,7 @@ def test_list_subnets_rest_bad_request( transport: str = "rest", request_type=service.ListSubnetsRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10725,7 +11135,7 @@ def test_list_subnets_rest_bad_request( def test_list_subnets_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10767,7 +11177,7 @@ def test_list_subnets_rest_flattened(): def test_list_subnets_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10782,7 +11192,7 @@ def test_list_subnets_rest_flattened_error(transport: str = "rest"): def test_list_subnets_rest_pager(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10850,7 +11260,7 @@ def test_list_subnets_rest_pager(transport: str = "rest"): ) def test_get_subnet_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10913,7 +11323,7 @@ def test_get_subnet_rest_required_fields(request_type=service.GetSubnetRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_subnet._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10922,7 +11332,7 @@ def test_get_subnet_rest_required_fields(request_type=service.GetSubnetRequest): jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_subnet._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10931,7 +11341,7 @@ def test_get_subnet_rest_required_fields(request_type=service.GetSubnetRequest): assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10973,7 +11383,7 @@ def test_get_subnet_rest_required_fields(request_type=service.GetSubnetRequest): def test_get_subnet_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_subnet._get_unset_required_fields({}) @@ -10983,7 +11393,7 @@ def test_get_subnet_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_subnet_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -11037,7 +11447,7 @@ def test_get_subnet_rest_bad_request( transport: str = "rest", request_type=service.GetSubnetRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11061,7 +11471,7 @@ def test_get_subnet_rest_bad_request( def test_get_subnet_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11105,7 +11515,7 @@ def test_get_subnet_rest_flattened(): def test_get_subnet_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11120,7 +11530,7 @@ def test_get_subnet_rest_flattened_error(transport: str = "rest"): def test_get_subnet_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11133,7 +11543,7 @@ def test_get_subnet_rest_error(): ) def test_create_subnet_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11258,7 +11668,7 @@ def test_create_subnet_rest_required_fields(request_type=service.CreateSubnetReq assert "subnetId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_subnet._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11270,7 +11680,7 @@ def test_create_subnet_rest_required_fields(request_type=service.CreateSubnetReq jsonified_request["subnetId"] = "subnet_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_subnet._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -11288,7 +11698,7 @@ def test_create_subnet_rest_required_fields(request_type=service.CreateSubnetReq assert jsonified_request["subnetId"] == "subnet_id_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11334,7 +11744,7 @@ def test_create_subnet_rest_required_fields(request_type=service.CreateSubnetReq def test_create_subnet_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_subnet._get_unset_required_fields({}) @@ -11358,7 +11768,7 @@ def test_create_subnet_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_subnet_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -11416,7 +11826,7 @@ def test_create_subnet_rest_bad_request( transport: str = "rest", request_type=service.CreateSubnetRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11438,7 +11848,7 @@ def test_create_subnet_rest_bad_request( def test_create_subnet_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11480,7 +11890,7 @@ def test_create_subnet_rest_flattened(): def test_create_subnet_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11497,7 +11907,7 @@ def test_create_subnet_rest_flattened_error(transport: str = "rest"): def test_create_subnet_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11510,7 +11920,7 @@ def test_create_subnet_rest_error(): ) def test_update_subnet_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11636,14 +12046,14 @@ def test_update_subnet_rest_required_fields(request_type=service.UpdateSubnetReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_subnet._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_subnet._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -11657,7 +12067,7 @@ def test_update_subnet_rest_required_fields(request_type=service.UpdateSubnetReq # verify required fields with non-default values are left alone client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11697,7 +12107,7 @@ def test_update_subnet_rest_required_fields(request_type=service.UpdateSubnetReq def test_update_subnet_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_subnet._get_unset_required_fields({}) @@ -11720,7 +12130,7 @@ def test_update_subnet_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_subnet_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -11778,7 +12188,7 @@ def test_update_subnet_rest_bad_request( transport: str = "rest", request_type=service.UpdateSubnetRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11804,7 +12214,7 @@ def test_update_subnet_rest_bad_request( def test_update_subnet_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11849,7 +12259,7 @@ def test_update_subnet_rest_flattened(): def test_update_subnet_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11865,7 +12275,7 @@ def test_update_subnet_rest_flattened_error(transport: str = "rest"): def test_update_subnet_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11878,7 +12288,7 @@ def test_update_subnet_rest_error(): ) def test_delete_subnet_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11924,7 +12334,7 @@ def test_delete_subnet_rest_required_fields(request_type=service.DeleteSubnetReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_subnet._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11933,7 +12343,7 @@ def test_delete_subnet_rest_required_fields(request_type=service.DeleteSubnetReq jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_subnet._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("request_id",)) @@ -11944,7 +12354,7 @@ def test_delete_subnet_rest_required_fields(request_type=service.DeleteSubnetReq assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11983,7 +12393,7 @@ def test_delete_subnet_rest_required_fields(request_type=service.DeleteSubnetReq def test_delete_subnet_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_subnet._get_unset_required_fields({}) @@ -11993,7 +12403,7 @@ def test_delete_subnet_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_subnet_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -12051,7 +12461,7 @@ def test_delete_subnet_rest_bad_request( transport: str = "rest", request_type=service.DeleteSubnetRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12075,7 +12485,7 @@ def test_delete_subnet_rest_bad_request( def test_delete_subnet_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12117,7 +12527,7 @@ def test_delete_subnet_rest_flattened(): def test_delete_subnet_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12132,7 +12542,7 @@ def test_delete_subnet_rest_flattened_error(transport: str = "rest"): def test_delete_subnet_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12145,7 +12555,7 @@ def test_delete_subnet_rest_error(): ) def test_list_interconnects_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12198,7 +12608,7 @@ def test_list_interconnects_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_interconnects._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12207,7 +12617,7 @@ def test_list_interconnects_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_interconnects._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -12225,7 +12635,7 @@ def test_list_interconnects_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12267,7 +12677,7 @@ def test_list_interconnects_rest_required_fields( def test_list_interconnects_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_interconnects._get_unset_required_fields({}) @@ -12287,7 +12697,7 @@ def test_list_interconnects_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_interconnects_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -12345,7 +12755,7 @@ def test_list_interconnects_rest_bad_request( transport: str = "rest", request_type=service.ListInterconnectsRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12367,7 +12777,7 @@ def test_list_interconnects_rest_bad_request( def test_list_interconnects_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12409,7 +12819,7 @@ def test_list_interconnects_rest_flattened(): def test_list_interconnects_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12424,7 +12834,7 @@ def test_list_interconnects_rest_flattened_error(transport: str = "rest"): def test_list_interconnects_rest_pager(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12492,7 +12902,7 @@ def test_list_interconnects_rest_pager(transport: str = "rest"): ) def test_get_interconnect_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12557,7 +12967,7 @@ def test_get_interconnect_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_interconnect._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12566,7 +12976,7 @@ def test_get_interconnect_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_interconnect._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12575,7 +12985,7 @@ def test_get_interconnect_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12617,7 +13027,7 @@ def test_get_interconnect_rest_required_fields( def test_get_interconnect_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_interconnect._get_unset_required_fields({}) @@ -12627,7 +13037,7 @@ def test_get_interconnect_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_interconnect_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -12683,7 +13093,7 @@ def test_get_interconnect_rest_bad_request( transport: str = "rest", request_type=service.GetInterconnectRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12707,7 +13117,7 @@ def test_get_interconnect_rest_bad_request( def test_get_interconnect_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12751,7 +13161,7 @@ def test_get_interconnect_rest_flattened(): def test_get_interconnect_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12766,7 +13176,7 @@ def test_get_interconnect_rest_flattened_error(transport: str = "rest"): def test_get_interconnect_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12779,7 +13189,7 @@ def test_get_interconnect_rest_error(): ) def test_diagnose_interconnect_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12829,7 +13239,7 @@ def test_diagnose_interconnect_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).diagnose_interconnect._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12838,7 +13248,7 @@ def test_diagnose_interconnect_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).diagnose_interconnect._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12847,7 +13257,7 @@ def test_diagnose_interconnect_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12889,7 +13299,7 @@ def test_diagnose_interconnect_rest_required_fields( def test_diagnose_interconnect_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.diagnose_interconnect._get_unset_required_fields({}) @@ -12899,7 +13309,7 @@ def test_diagnose_interconnect_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_diagnose_interconnect_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -12957,7 +13367,7 @@ def test_diagnose_interconnect_rest_bad_request( transport: str = "rest", request_type=service.DiagnoseInterconnectRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12981,7 +13391,7 @@ def test_diagnose_interconnect_rest_bad_request( def test_diagnose_interconnect_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13025,7 +13435,7 @@ def test_diagnose_interconnect_rest_flattened(): def test_diagnose_interconnect_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13040,7 +13450,7 @@ def test_diagnose_interconnect_rest_flattened_error(transport: str = "rest"): def test_diagnose_interconnect_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -13053,7 +13463,7 @@ def test_diagnose_interconnect_rest_error(): ) def test_list_interconnect_attachments_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13106,7 +13516,7 @@ def test_list_interconnect_attachments_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_interconnect_attachments._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13115,7 +13525,7 @@ def test_list_interconnect_attachments_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_interconnect_attachments._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -13133,7 +13543,7 @@ def test_list_interconnect_attachments_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13175,7 +13585,7 @@ def test_list_interconnect_attachments_rest_required_fields( def test_list_interconnect_attachments_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_interconnect_attachments._get_unset_required_fields( @@ -13197,7 +13607,7 @@ def test_list_interconnect_attachments_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_interconnect_attachments_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -13255,7 +13665,7 @@ def test_list_interconnect_attachments_rest_bad_request( transport: str = "rest", request_type=service.ListInterconnectAttachmentsRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13277,7 +13687,7 @@ def test_list_interconnect_attachments_rest_bad_request( def test_list_interconnect_attachments_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13319,7 +13729,7 @@ def test_list_interconnect_attachments_rest_flattened(): def test_list_interconnect_attachments_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13334,7 +13744,7 @@ def test_list_interconnect_attachments_rest_flattened_error(transport: str = "re def test_list_interconnect_attachments_rest_pager(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13404,7 +13814,7 @@ def test_list_interconnect_attachments_rest_pager(transport: str = "rest"): ) def test_get_interconnect_attachment_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13469,7 +13879,7 @@ def test_get_interconnect_attachment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_interconnect_attachment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13478,7 +13888,7 @@ def test_get_interconnect_attachment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_interconnect_attachment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13487,7 +13897,7 @@ def test_get_interconnect_attachment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13529,7 +13939,7 @@ def test_get_interconnect_attachment_rest_required_fields( def test_get_interconnect_attachment_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_interconnect_attachment._get_unset_required_fields({}) @@ -13539,7 +13949,7 @@ def test_get_interconnect_attachment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_interconnect_attachment_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -13597,7 +14007,7 @@ def test_get_interconnect_attachment_rest_bad_request( transport: str = "rest", request_type=service.GetInterconnectAttachmentRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13621,7 +14031,7 @@ def test_get_interconnect_attachment_rest_bad_request( def test_get_interconnect_attachment_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13665,7 +14075,7 @@ def test_get_interconnect_attachment_rest_flattened(): def test_get_interconnect_attachment_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13680,7 +14090,7 @@ def test_get_interconnect_attachment_rest_flattened_error(transport: str = "rest def test_get_interconnect_attachment_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -13693,7 +14103,7 @@ def test_get_interconnect_attachment_rest_error(): ) def test_create_interconnect_attachment_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13824,7 +14234,7 @@ def test_create_interconnect_attachment_rest_required_fields( assert "interconnectAttachmentId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_interconnect_attachment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13839,7 +14249,7 @@ def test_create_interconnect_attachment_rest_required_fields( jsonified_request["interconnectAttachmentId"] = "interconnect_attachment_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_interconnect_attachment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -13860,7 +14270,7 @@ def test_create_interconnect_attachment_rest_required_fields( ) client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13906,7 +14316,7 @@ def test_create_interconnect_attachment_rest_required_fields( def test_create_interconnect_attachment_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_interconnect_attachment._get_unset_required_fields( @@ -13932,7 +14342,7 @@ def test_create_interconnect_attachment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_interconnect_attachment_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -13992,7 +14402,7 @@ def test_create_interconnect_attachment_rest_bad_request( transport: str = "rest", request_type=service.CreateInterconnectAttachmentRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14014,7 +14424,7 @@ def test_create_interconnect_attachment_rest_bad_request( def test_create_interconnect_attachment_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14056,7 +14466,7 @@ def test_create_interconnect_attachment_rest_flattened(): def test_create_interconnect_attachment_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14073,7 +14483,7 @@ def test_create_interconnect_attachment_rest_flattened_error(transport: str = "r def test_create_interconnect_attachment_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -14086,7 +14496,7 @@ def test_create_interconnect_attachment_rest_error(): ) def test_delete_interconnect_attachment_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14134,7 +14544,7 @@ def test_delete_interconnect_attachment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_interconnect_attachment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14143,7 +14553,7 @@ def test_delete_interconnect_attachment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_interconnect_attachment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("request_id",)) @@ -14154,7 +14564,7 @@ def test_delete_interconnect_attachment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14193,7 +14603,7 @@ def test_delete_interconnect_attachment_rest_required_fields( def test_delete_interconnect_attachment_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_interconnect_attachment._get_unset_required_fields( @@ -14205,7 +14615,7 @@ def test_delete_interconnect_attachment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_interconnect_attachment_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -14265,7 +14675,7 @@ def test_delete_interconnect_attachment_rest_bad_request( transport: str = "rest", request_type=service.DeleteInterconnectAttachmentRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14289,7 +14699,7 @@ def test_delete_interconnect_attachment_rest_bad_request( def test_delete_interconnect_attachment_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14331,7 +14741,7 @@ def test_delete_interconnect_attachment_rest_flattened(): def test_delete_interconnect_attachment_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14346,7 +14756,7 @@ def test_delete_interconnect_attachment_rest_flattened_error(transport: str = "r def test_delete_interconnect_attachment_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -14359,7 +14769,7 @@ def test_delete_interconnect_attachment_rest_error(): ) def test_list_routers_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14410,7 +14820,7 @@ def test_list_routers_rest_required_fields(request_type=service.ListRoutersReque # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_routers._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14419,7 +14829,7 @@ def test_list_routers_rest_required_fields(request_type=service.ListRoutersReque jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_routers._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -14437,7 +14847,7 @@ def test_list_routers_rest_required_fields(request_type=service.ListRoutersReque assert jsonified_request["parent"] == "parent_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14479,7 +14889,7 @@ def test_list_routers_rest_required_fields(request_type=service.ListRoutersReque def test_list_routers_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_routers._get_unset_required_fields({}) @@ -14499,7 +14909,7 @@ def test_list_routers_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_routers_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -14555,7 +14965,7 @@ def test_list_routers_rest_bad_request( transport: str = "rest", request_type=service.ListRoutersRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14577,7 +14987,7 @@ def test_list_routers_rest_bad_request( def test_list_routers_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14619,7 +15029,7 @@ def test_list_routers_rest_flattened(): def test_list_routers_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14634,7 +15044,7 @@ def test_list_routers_rest_flattened_error(transport: str = "rest"): def test_list_routers_rest_pager(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14702,7 +15112,7 @@ def test_list_routers_rest_pager(transport: str = "rest"): ) def test_get_router_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14761,7 +15171,7 @@ def test_get_router_rest_required_fields(request_type=service.GetRouterRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_router._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14770,7 +15180,7 @@ def test_get_router_rest_required_fields(request_type=service.GetRouterRequest): jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_router._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14779,7 +15189,7 @@ def test_get_router_rest_required_fields(request_type=service.GetRouterRequest): assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14821,7 +15231,7 @@ def test_get_router_rest_required_fields(request_type=service.GetRouterRequest): def test_get_router_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_router._get_unset_required_fields({}) @@ -14831,7 +15241,7 @@ def test_get_router_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_router_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -14885,7 +15295,7 @@ def test_get_router_rest_bad_request( transport: str = "rest", request_type=service.GetRouterRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14909,7 +15319,7 @@ def test_get_router_rest_bad_request( def test_get_router_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14953,7 +15363,7 @@ def test_get_router_rest_flattened(): def test_get_router_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14968,7 +15378,7 @@ def test_get_router_rest_flattened_error(transport: str = "rest"): def test_get_router_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -14981,7 +15391,7 @@ def test_get_router_rest_error(): ) def test_diagnose_router_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15031,7 +15441,7 @@ def test_diagnose_router_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).diagnose_router._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15040,7 +15450,7 @@ def test_diagnose_router_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).diagnose_router._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15049,7 +15459,7 @@ def test_diagnose_router_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -15091,7 +15501,7 @@ def test_diagnose_router_rest_required_fields( def test_diagnose_router_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.diagnose_router._get_unset_required_fields({}) @@ -15101,7 +15511,7 @@ def test_diagnose_router_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_diagnose_router_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -15157,7 +15567,7 @@ def test_diagnose_router_rest_bad_request( transport: str = "rest", request_type=service.DiagnoseRouterRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15181,7 +15591,7 @@ def test_diagnose_router_rest_bad_request( def test_diagnose_router_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15225,7 +15635,7 @@ def test_diagnose_router_rest_flattened(): def test_diagnose_router_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15240,7 +15650,7 @@ def test_diagnose_router_rest_flattened_error(transport: str = "rest"): def test_diagnose_router_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -15253,7 +15663,7 @@ def test_diagnose_router_rest_error(): ) def test_create_router_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15405,7 +15815,7 @@ def test_create_router_rest_required_fields(request_type=service.CreateRouterReq assert "routerId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_router._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15417,7 +15827,7 @@ def test_create_router_rest_required_fields(request_type=service.CreateRouterReq jsonified_request["routerId"] = "router_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_router._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -15435,7 +15845,7 @@ def test_create_router_rest_required_fields(request_type=service.CreateRouterReq assert jsonified_request["routerId"] == "router_id_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -15481,7 +15891,7 @@ def test_create_router_rest_required_fields(request_type=service.CreateRouterReq def test_create_router_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_router._get_unset_required_fields({}) @@ -15505,7 +15915,7 @@ def test_create_router_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_router_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -15563,7 +15973,7 @@ def test_create_router_rest_bad_request( transport: str = "rest", request_type=service.CreateRouterRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15585,7 +15995,7 @@ def test_create_router_rest_bad_request( def test_create_router_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15627,7 +16037,7 @@ def test_create_router_rest_flattened(): def test_create_router_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15644,7 +16054,7 @@ def test_create_router_rest_flattened_error(transport: str = "rest"): def test_create_router_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -15657,7 +16067,7 @@ def test_create_router_rest_error(): ) def test_update_router_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15810,14 +16220,14 @@ def test_update_router_rest_required_fields(request_type=service.UpdateRouterReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_router._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_router._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -15831,7 +16241,7 @@ def test_update_router_rest_required_fields(request_type=service.UpdateRouterReq # verify required fields with non-default values are left alone client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -15871,7 +16281,7 @@ def test_update_router_rest_required_fields(request_type=service.UpdateRouterReq def test_update_router_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_router._get_unset_required_fields({}) @@ -15894,7 +16304,7 @@ def test_update_router_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_router_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -15952,7 +16362,7 @@ def test_update_router_rest_bad_request( transport: str = "rest", request_type=service.UpdateRouterRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15978,7 +16388,7 @@ def test_update_router_rest_bad_request( def test_update_router_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16023,7 +16433,7 @@ def test_update_router_rest_flattened(): def test_update_router_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16039,7 +16449,7 @@ def test_update_router_rest_flattened_error(transport: str = "rest"): def test_update_router_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -16052,7 +16462,7 @@ def test_update_router_rest_error(): ) def test_delete_router_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16098,7 +16508,7 @@ def test_delete_router_rest_required_fields(request_type=service.DeleteRouterReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_router._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -16107,7 +16517,7 @@ def test_delete_router_rest_required_fields(request_type=service.DeleteRouterReq jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_router._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("request_id",)) @@ -16118,7 +16528,7 @@ def test_delete_router_rest_required_fields(request_type=service.DeleteRouterReq assert jsonified_request["name"] == "name_value" client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -16157,7 +16567,7 @@ def test_delete_router_rest_required_fields(request_type=service.DeleteRouterReq def test_delete_router_rest_unset_required_fields(): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_router._get_unset_required_fields({}) @@ -16167,7 +16577,7 @@ def test_delete_router_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_router_rest_interceptors(null_interceptor): transport = transports.EdgeNetworkRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EdgeNetworkRestInterceptor(), @@ -16225,7 +16635,7 @@ def test_delete_router_rest_bad_request( transport: str = "rest", request_type=service.DeleteRouterRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16249,7 +16659,7 @@ def test_delete_router_rest_bad_request( def test_delete_router_rest_flattened(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16291,7 +16701,7 @@ def test_delete_router_rest_flattened(): def test_delete_router_rest_flattened_error(transport: str = "rest"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16306,24 +16716,24 @@ def test_delete_router_rest_flattened_error(transport: str = "rest"): def test_delete_router_rest_error(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EdgeNetworkGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EdgeNetworkGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EdgeNetworkClient( @@ -16333,7 +16743,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EdgeNetworkGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -16344,16 +16754,17 @@ 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 = EdgeNetworkClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EdgeNetworkGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EdgeNetworkClient( @@ -16365,7 +16776,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EdgeNetworkGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EdgeNetworkClient(transport=transport) assert client.transport is transport @@ -16374,13 +16785,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EdgeNetworkGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EdgeNetworkGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -16397,7 +16808,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -16411,7 +16822,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = EdgeNetworkClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -16419,7 +16830,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -16431,7 +16842,7 @@ def test_edge_network_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EdgeNetworkTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -16443,7 +16854,7 @@ def test_edge_network_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EdgeNetworkTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -16511,7 +16922,7 @@ def test_edge_network_base_transport_with_credentials_file(): "google.cloud.edgenetwork_v1.services.edge_network.transports.EdgeNetworkTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EdgeNetworkTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -16530,7 +16941,7 @@ def test_edge_network_base_transport_with_adc(): "google.cloud.edgenetwork_v1.services.edge_network.transports.EdgeNetworkTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EdgeNetworkTransport() adc.assert_called_once() @@ -16538,7 +16949,7 @@ def test_edge_network_base_transport_with_adc(): def test_edge_network_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EdgeNetworkClient() adc.assert_called_once_with( scopes=None, @@ -16558,7 +16969,7 @@ def test_edge_network_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -16605,7 +17016,7 @@ def test_edge_network_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -16630,7 +17041,7 @@ def test_edge_network_transport_create_channel(transport_class, grpc_helpers): [transports.EdgeNetworkGrpcTransport, transports.EdgeNetworkGrpcAsyncIOTransport], ) def test_edge_network_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -16668,7 +17079,7 @@ def test_edge_network_grpc_transport_client_cert_source_for_mtls(transport_class def test_edge_network_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -16680,7 +17091,7 @@ def test_edge_network_http_transport_client_cert_source_for_mtls(): def test_edge_network_rest_lro_client(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -16705,7 +17116,7 @@ def test_edge_network_rest_lro_client(): ) def test_edge_network_host_no_port(transport_name): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="edgenetwork.googleapis.com" ), @@ -16728,7 +17139,7 @@ def test_edge_network_host_no_port(transport_name): ) def test_edge_network_host_with_port(transport_name): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="edgenetwork.googleapis.com:8000" ), @@ -16748,8 +17159,8 @@ def test_edge_network_host_with_port(transport_name): ], ) def test_edge_network_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EdgeNetworkClient( credentials=creds1, transport=transport_name, @@ -16883,7 +17294,7 @@ def test_edge_network_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -16958,7 +17369,7 @@ def test_edge_network_transport_channel_mtls_with_adc(transport_class): def test_edge_network_grpc_lro_client(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -16975,7 +17386,7 @@ def test_edge_network_grpc_lro_client(): def test_edge_network_grpc_lro_async_client(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -17277,7 +17688,7 @@ def test_client_with_default_client_info(): transports.EdgeNetworkTransport, "_prep_wrapped_messages" ) as prep: client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -17287,7 +17698,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EdgeNetworkClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -17296,7 +17707,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -17311,7 +17722,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17341,7 +17752,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -17369,7 +17780,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17397,7 +17808,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -17425,7 +17836,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17455,7 +17866,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -17483,7 +17894,7 @@ def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17513,7 +17924,7 @@ def test_delete_operation_rest_bad_request( ) def test_delete_operation_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -17541,7 +17952,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17571,7 +17982,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -17599,7 +18010,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17629,7 +18040,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -17655,7 +18066,7 @@ def test_list_operations_rest(request_type): def test_delete_operation(transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17680,7 +18091,7 @@ def test_delete_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_delete_operation_async(transport: str = "grpc_asyncio"): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17704,7 +18115,7 @@ async def test_delete_operation_async(transport: str = "grpc_asyncio"): def test_delete_operation_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -17733,7 +18144,7 @@ def test_delete_operation_field_headers(): @pytest.mark.asyncio async def test_delete_operation_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -17760,7 +18171,7 @@ async def test_delete_operation_field_headers_async(): def test_delete_operation_from_dict(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -17778,7 +18189,7 @@ def test_delete_operation_from_dict(): @pytest.mark.asyncio async def test_delete_operation_from_dict_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -17794,7 +18205,7 @@ async def test_delete_operation_from_dict_async(): def test_cancel_operation(transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17819,7 +18230,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17843,7 +18254,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -17872,7 +18283,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -17899,7 +18310,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -17917,7 +18328,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -17933,7 +18344,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17958,7 +18369,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17984,7 +18395,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18013,7 +18424,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18042,7 +18453,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -18060,7 +18471,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -18078,7 +18489,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18103,7 +18514,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18129,7 +18540,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18158,7 +18569,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18187,7 +18598,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -18205,7 +18616,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -18223,7 +18634,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18248,7 +18659,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18274,7 +18685,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18303,7 +18714,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18332,7 +18743,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -18350,7 +18761,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -18368,7 +18779,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18393,7 +18804,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18418,7 +18829,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = EdgeNetworkClient(credentials=ga_credentials.AnonymousCredentials()) + client = EdgeNetworkClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -18445,7 +18856,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = EdgeNetworkAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = EdgeNetworkAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -18473,7 +18886,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -18491,7 +18904,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = EdgeNetworkAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -18515,7 +18928,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -18532,7 +18945,7 @@ def test_client_ctx(): ] for transport in transports: client = EdgeNetworkClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -18563,7 +18976,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, diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph/gapic_version.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph/gapic_version.py index 288d10b11145..360a0d13ebdd 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph/gapic_version.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.3.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/gapic_version.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/gapic_version.py index 288d10b11145..360a0d13ebdd 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/gapic_version.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.3.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/async_client.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/async_client.py index c0310d6e6215..7ef66629b7fe 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/async_client.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.enterpriseknowledgegraph_v1 import gapic_version as package_version 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.longrunning import operations_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -65,8 +65,14 @@ class EnterpriseKnowledgeGraphServiceAsyncClient: _client: EnterpriseKnowledgeGraphServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EnterpriseKnowledgeGraphServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EnterpriseKnowledgeGraphServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ( + EnterpriseKnowledgeGraphServiceClient._DEFAULT_ENDPOINT_TEMPLATE + ) + _DEFAULT_UNIVERSE = EnterpriseKnowledgeGraphServiceClient._DEFAULT_UNIVERSE cloud_knowledge_graph_entity_path = staticmethod( EnterpriseKnowledgeGraphServiceClient.cloud_knowledge_graph_entity_path @@ -203,6 +209,25 @@ def transport(self) -> EnterpriseKnowledgeGraphServiceTransport: """ 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(EnterpriseKnowledgeGraphServiceClient).get_transport_class, type(EnterpriseKnowledgeGraphServiceClient), @@ -218,7 +243,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the enterprise knowledge graph service client. + """Instantiates the enterprise knowledge graph service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -229,23 +254,38 @@ def __init__( transport (Union[str, ~.EnterpriseKnowledgeGraphServiceTransport]): 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. @@ -361,6 +401,9 @@ async def sample_create_entity_reconciliation_job(): 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, @@ -473,6 +516,9 @@ async def sample_get_entity_reconciliation_job(): 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, @@ -591,6 +637,9 @@ async def sample_list_entity_reconciliation_jobs(): 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, @@ -697,6 +746,9 @@ async def sample_cancel_entity_reconciliation_job(): 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, @@ -792,6 +844,9 @@ async def sample_delete_entity_reconciliation_job(): 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, @@ -902,6 +957,9 @@ async def sample_lookup(): 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, @@ -1015,6 +1073,9 @@ async def sample_search(): 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, @@ -1128,6 +1189,9 @@ async def sample_lookup_public_kg(): 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, @@ -1241,6 +1305,9 @@ async def sample_search_public_kg(): 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, diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/client.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/client.py index 873d774782c6..c80ae26db8df 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/client.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.enterpriseknowledgegraph_v1 import gapic_version as package_version 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.longrunning import operations_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -139,11 +140,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 = "enterpriseknowledgegraph.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "enterpriseknowledgegraph.{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 @@ -377,7 +382,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 @@ -407,6 +412,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") @@ -440,6 +450,179 @@ 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 + + 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 + + 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 = EnterpriseKnowledgeGraphServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EnterpriseKnowledgeGraphServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + EnterpriseKnowledgeGraphServiceClient._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 = EnterpriseKnowledgeGraphServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = ( + EnterpriseKnowledgeGraphServiceClient._DEFAULT_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 EnterpriseKnowledgeGraphServiceClient._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, *, @@ -461,22 +644,32 @@ def __init__( transport (Union[str, EnterpriseKnowledgeGraphServiceTransport]): 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. @@ -487,17 +680,38 @@ 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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = EnterpriseKnowledgeGraphServiceClient._read_environment_variables() + self._client_cert_source = ( + EnterpriseKnowledgeGraphServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + ) + self._universe_domain = ( + EnterpriseKnowledgeGraphServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -506,20 +720,35 @@ 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, EnterpriseKnowledgeGraphServiceTransport): + transport_provided = isinstance( + transport, EnterpriseKnowledgeGraphServiceTransport + ) + if transport_provided: # transport is a EnterpriseKnowledgeGraphServiceTransport 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(EnterpriseKnowledgeGraphServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or EnterpriseKnowledgeGraphServiceClient._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( @@ -529,17 +758,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 create_entity_reconciliation_job( @@ -648,6 +877,9 @@ def sample_create_entity_reconciliation_job(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -753,6 +985,9 @@ def sample_get_entity_reconciliation_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -864,6 +1099,9 @@ def sample_list_entity_reconciliation_jobs(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -972,6 +1210,9 @@ def sample_cancel_entity_reconciliation_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1069,6 +1310,9 @@ def sample_delete_entity_reconciliation_job(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1179,6 +1423,9 @@ def sample_lookup(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1292,6 +1539,9 @@ def sample_search(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1405,6 +1655,9 @@ def sample_lookup_public_kg(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1518,6 +1771,9 @@ def sample_search_public_kg(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/base.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/base.py index 9bc0ff1a5e1d..6e14cd8c5a9e 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/base.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'enterpriseknowledgegraph.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 @@ -121,6 +121,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-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc.py index 37266629c99c..dd0a67a6e043 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'enterpriseknowledgegraph.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-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc_asyncio.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc_asyncio.py index 6625be8a681f..376f378b8b45 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'enterpriseknowledgegraph.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-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/rest.py b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/rest.py index a5d34b140e88..93250789943e 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/rest.py +++ b/packages/google-cloud-enterpriseknowledgegraph/google/cloud/enterpriseknowledgegraph_v1/services/enterprise_knowledge_graph_service/transports/rest.py @@ -31,9 +31,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -355,7 +355,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'enterpriseknowledgegraph.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-enterpriseknowledgegraph/noxfile.py b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/noxfile.py +++ b/packages/google-cloud-enterpriseknowledgegraph/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-enterpriseknowledgegraph/samples/generated_samples/snippet_metadata_google.cloud.enterpriseknowledgegraph.v1.json b/packages/google-cloud-enterpriseknowledgegraph/samples/generated_samples/snippet_metadata_google.cloud.enterpriseknowledgegraph.v1.json index 9f97474f5c2b..ada6b2e84d57 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/samples/generated_samples/snippet_metadata_google.cloud.enterpriseknowledgegraph.v1.json +++ b/packages/google-cloud-enterpriseknowledgegraph/samples/generated_samples/snippet_metadata_google.cloud.enterpriseknowledgegraph.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-enterpriseknowledgegraph", - "version": "0.3.5" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-enterpriseknowledgegraph/tests/unit/gapic/enterpriseknowledgegraph_v1/test_enterprise_knowledge_graph_service.py b/packages/google-cloud-enterpriseknowledgegraph/tests/unit/gapic/enterpriseknowledgegraph_v1/test_enterprise_knowledge_graph_service.py index 2f198b74739b..bd5d77a5a5c3 100644 --- a/packages/google-cloud-enterpriseknowledgegraph/tests/unit/gapic/enterpriseknowledgegraph_v1/test_enterprise_knowledge_graph_service.py +++ b/packages/google-cloud-enterpriseknowledgegraph/tests/unit/gapic/enterpriseknowledgegraph_v1/test_enterprise_knowledge_graph_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -72,6 +72,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -110,6 +133,302 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert EnterpriseKnowledgeGraphServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EnterpriseKnowledgeGraphServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EnterpriseKnowledgeGraphServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EnterpriseKnowledgeGraphServiceClient._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 EnterpriseKnowledgeGraphServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EnterpriseKnowledgeGraphServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EnterpriseKnowledgeGraphServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EnterpriseKnowledgeGraphServiceClient._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 EnterpriseKnowledgeGraphServiceClient._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 ( + EnterpriseKnowledgeGraphServiceClient._get_client_cert_source(None, False) + is None + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._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 ( + EnterpriseKnowledgeGraphServiceClient._get_client_cert_source( + None, True + ) + is mock_default_cert_source + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EnterpriseKnowledgeGraphServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnterpriseKnowledgeGraphServiceClient), +) +@mock.patch.object( + EnterpriseKnowledgeGraphServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnterpriseKnowledgeGraphServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EnterpriseKnowledgeGraphServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + EnterpriseKnowledgeGraphServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ( + EnterpriseKnowledgeGraphServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + ) + + assert ( + EnterpriseKnowledgeGraphServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EnterpriseKnowledgeGraphServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == EnterpriseKnowledgeGraphServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EnterpriseKnowledgeGraphServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EnterpriseKnowledgeGraphServiceClient._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 ( + EnterpriseKnowledgeGraphServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_universe_domain( + None, universe_domain_env + ) + == universe_domain_env + ) + assert ( + EnterpriseKnowledgeGraphServiceClient._get_universe_domain(None, None) + == EnterpriseKnowledgeGraphServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EnterpriseKnowledgeGraphServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + EnterpriseKnowledgeGraphServiceClient, + transports.EnterpriseKnowledgeGraphServiceGrpcTransport, + "grpc", + ), + ( + EnterpriseKnowledgeGraphServiceClient, + transports.EnterpriseKnowledgeGraphServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -121,7 +440,7 @@ def test__get_default_mtls_endpoint(): def test_enterprise_knowledge_graph_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -178,7 +497,7 @@ def test_enterprise_knowledge_graph_service_client_service_account_always_use_jw def test_enterprise_knowledge_graph_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -236,13 +555,13 @@ def test_enterprise_knowledge_graph_service_client_get_transport_class(): ) @mock.patch.object( EnterpriseKnowledgeGraphServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EnterpriseKnowledgeGraphServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnterpriseKnowledgeGraphServiceClient), ) @mock.patch.object( EnterpriseKnowledgeGraphServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EnterpriseKnowledgeGraphServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnterpriseKnowledgeGraphServiceAsyncClient), ) def test_enterprise_knowledge_graph_service_client_client_options( client_class, transport_class, transport_name @@ -251,7 +570,9 @@ def test_enterprise_knowledge_graph_service_client_client_options( with mock.patch.object( EnterpriseKnowledgeGraphServiceClient, "get_transport_class" ) as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -288,7 +609,9 @@ def test_enterprise_knowledge_graph_service_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, @@ -318,15 +641,23 @@ def test_enterprise_knowledge_graph_service_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") @@ -336,7 +667,9 @@ def test_enterprise_knowledge_graph_service_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", @@ -354,7 +687,9 @@ def test_enterprise_knowledge_graph_service_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, @@ -407,13 +742,13 @@ def test_enterprise_knowledge_graph_service_client_client_options( ) @mock.patch.object( EnterpriseKnowledgeGraphServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EnterpriseKnowledgeGraphServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnterpriseKnowledgeGraphServiceClient), ) @mock.patch.object( EnterpriseKnowledgeGraphServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EnterpriseKnowledgeGraphServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnterpriseKnowledgeGraphServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_enterprise_knowledge_graph_service_client_mtls_env_auto( @@ -436,7 +771,9 @@ def test_enterprise_knowledge_graph_service_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 @@ -468,7 +805,9 @@ def test_enterprise_knowledge_graph_service_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 @@ -502,7 +841,9 @@ def test_enterprise_knowledge_graph_service_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, @@ -595,6 +936,123 @@ def test_enterprise_knowledge_graph_service_client_get_mtls_endpoint_and_cert_so 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", + [EnterpriseKnowledgeGraphServiceClient, EnterpriseKnowledgeGraphServiceAsyncClient], +) +@mock.patch.object( + EnterpriseKnowledgeGraphServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnterpriseKnowledgeGraphServiceClient), +) +@mock.patch.object( + EnterpriseKnowledgeGraphServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EnterpriseKnowledgeGraphServiceAsyncClient), +) +def test_enterprise_knowledge_graph_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EnterpriseKnowledgeGraphServiceClient._DEFAULT_UNIVERSE + default_endpoint = ( + EnterpriseKnowledgeGraphServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + ) + mock_universe = "bar.com" + mock_endpoint = ( + EnterpriseKnowledgeGraphServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -629,7 +1087,9 @@ def test_enterprise_knowledge_graph_service_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, @@ -674,7 +1134,9 @@ def test_enterprise_knowledge_graph_service_client_client_options_credentials_fi 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, @@ -734,7 +1196,9 @@ def test_enterprise_knowledge_graph_service_client_create_channel_credentials_fi 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, @@ -751,8 +1215,8 @@ def test_enterprise_knowledge_graph_service_client_create_channel_credentials_fi ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -781,7 +1245,7 @@ def test_enterprise_knowledge_graph_service_client_create_channel_credentials_fi ) def test_create_entity_reconciliation_job(request_type, transport: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -815,7 +1279,7 @@ def test_create_entity_reconciliation_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -835,7 +1299,7 @@ async def test_create_entity_reconciliation_job_async( request_type=service.CreateEntityReconciliationJobRequest, ): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -874,7 +1338,7 @@ async def test_create_entity_reconciliation_job_async_from_dict(): def test_create_entity_reconciliation_job_field_headers(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -906,7 +1370,7 @@ def test_create_entity_reconciliation_job_field_headers(): @pytest.mark.asyncio async def test_create_entity_reconciliation_job_field_headers_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -939,7 +1403,7 @@ async def test_create_entity_reconciliation_job_field_headers_async(): def test_create_entity_reconciliation_job_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -971,7 +1435,7 @@ def test_create_entity_reconciliation_job_flattened(): def test_create_entity_reconciliation_job_flattened_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -989,7 +1453,7 @@ def test_create_entity_reconciliation_job_flattened_error(): @pytest.mark.asyncio async def test_create_entity_reconciliation_job_flattened_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1026,7 +1490,7 @@ async def test_create_entity_reconciliation_job_flattened_async(): @pytest.mark.asyncio async def test_create_entity_reconciliation_job_flattened_error_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1050,7 +1514,7 @@ async def test_create_entity_reconciliation_job_flattened_error_async(): ) def test_get_entity_reconciliation_job(request_type, transport: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1084,7 +1548,7 @@ def test_get_entity_reconciliation_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1104,7 +1568,7 @@ async def test_get_entity_reconciliation_job_async( request_type=service.GetEntityReconciliationJobRequest, ): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1143,7 +1607,7 @@ async def test_get_entity_reconciliation_job_async_from_dict(): def test_get_entity_reconciliation_job_field_headers(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1175,7 +1639,7 @@ def test_get_entity_reconciliation_job_field_headers(): @pytest.mark.asyncio async def test_get_entity_reconciliation_job_field_headers_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1208,7 +1672,7 @@ async def test_get_entity_reconciliation_job_field_headers_async(): def test_get_entity_reconciliation_job_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1234,7 +1698,7 @@ def test_get_entity_reconciliation_job_flattened(): def test_get_entity_reconciliation_job_flattened_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1249,7 +1713,7 @@ def test_get_entity_reconciliation_job_flattened_error(): @pytest.mark.asyncio async def test_get_entity_reconciliation_job_flattened_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1280,7 +1744,7 @@ async def test_get_entity_reconciliation_job_flattened_async(): @pytest.mark.asyncio async def test_get_entity_reconciliation_job_flattened_error_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1301,7 +1765,7 @@ async def test_get_entity_reconciliation_job_flattened_error_async(): ) def test_list_entity_reconciliation_jobs(request_type, transport: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1333,7 +1797,7 @@ def test_list_entity_reconciliation_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1353,7 +1817,7 @@ async def test_list_entity_reconciliation_jobs_async( request_type=service.ListEntityReconciliationJobsRequest, ): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1390,7 +1854,7 @@ async def test_list_entity_reconciliation_jobs_async_from_dict(): def test_list_entity_reconciliation_jobs_field_headers(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1422,7 +1886,7 @@ def test_list_entity_reconciliation_jobs_field_headers(): @pytest.mark.asyncio async def test_list_entity_reconciliation_jobs_field_headers_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1455,7 +1919,7 @@ async def test_list_entity_reconciliation_jobs_field_headers_async(): def test_list_entity_reconciliation_jobs_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1481,7 +1945,7 @@ def test_list_entity_reconciliation_jobs_flattened(): def test_list_entity_reconciliation_jobs_flattened_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1496,7 +1960,7 @@ def test_list_entity_reconciliation_jobs_flattened_error(): @pytest.mark.asyncio async def test_list_entity_reconciliation_jobs_flattened_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1527,7 +1991,7 @@ async def test_list_entity_reconciliation_jobs_flattened_async(): @pytest.mark.asyncio async def test_list_entity_reconciliation_jobs_flattened_error_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1541,7 +2005,7 @@ async def test_list_entity_reconciliation_jobs_flattened_error_async(): def test_list_entity_reconciliation_jobs_pager(transport_name: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1593,7 +2057,7 @@ def test_list_entity_reconciliation_jobs_pager(transport_name: str = "grpc"): def test_list_entity_reconciliation_jobs_pages(transport_name: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1637,7 +2101,7 @@ def test_list_entity_reconciliation_jobs_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_entity_reconciliation_jobs_async_pager(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1689,7 +2153,7 @@ async def test_list_entity_reconciliation_jobs_async_pager(): @pytest.mark.asyncio async def test_list_entity_reconciliation_jobs_async_pages(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1746,7 +2210,7 @@ async def test_list_entity_reconciliation_jobs_async_pages(): ) def test_cancel_entity_reconciliation_job(request_type, transport: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1775,7 +2239,7 @@ def test_cancel_entity_reconciliation_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1795,7 +2259,7 @@ async def test_cancel_entity_reconciliation_job_async( request_type=service.CancelEntityReconciliationJobRequest, ): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1827,7 +2291,7 @@ async def test_cancel_entity_reconciliation_job_async_from_dict(): def test_cancel_entity_reconciliation_job_field_headers(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1859,7 +2323,7 @@ def test_cancel_entity_reconciliation_job_field_headers(): @pytest.mark.asyncio async def test_cancel_entity_reconciliation_job_field_headers_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1890,7 +2354,7 @@ async def test_cancel_entity_reconciliation_job_field_headers_async(): def test_cancel_entity_reconciliation_job_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1916,7 +2380,7 @@ def test_cancel_entity_reconciliation_job_flattened(): def test_cancel_entity_reconciliation_job_flattened_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1931,7 +2395,7 @@ def test_cancel_entity_reconciliation_job_flattened_error(): @pytest.mark.asyncio async def test_cancel_entity_reconciliation_job_flattened_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1960,7 +2424,7 @@ async def test_cancel_entity_reconciliation_job_flattened_async(): @pytest.mark.asyncio async def test_cancel_entity_reconciliation_job_flattened_error_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1981,7 +2445,7 @@ async def test_cancel_entity_reconciliation_job_flattened_error_async(): ) def test_delete_entity_reconciliation_job(request_type, transport: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2010,7 +2474,7 @@ def test_delete_entity_reconciliation_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2030,7 +2494,7 @@ async def test_delete_entity_reconciliation_job_async( request_type=service.DeleteEntityReconciliationJobRequest, ): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2062,7 +2526,7 @@ async def test_delete_entity_reconciliation_job_async_from_dict(): def test_delete_entity_reconciliation_job_field_headers(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2094,7 +2558,7 @@ def test_delete_entity_reconciliation_job_field_headers(): @pytest.mark.asyncio async def test_delete_entity_reconciliation_job_field_headers_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2125,7 +2589,7 @@ async def test_delete_entity_reconciliation_job_field_headers_async(): def test_delete_entity_reconciliation_job_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2151,7 +2615,7 @@ def test_delete_entity_reconciliation_job_flattened(): def test_delete_entity_reconciliation_job_flattened_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2166,7 +2630,7 @@ def test_delete_entity_reconciliation_job_flattened_error(): @pytest.mark.asyncio async def test_delete_entity_reconciliation_job_flattened_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2195,7 +2659,7 @@ async def test_delete_entity_reconciliation_job_flattened_async(): @pytest.mark.asyncio async def test_delete_entity_reconciliation_job_flattened_error_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2216,7 +2680,7 @@ async def test_delete_entity_reconciliation_job_flattened_error_async(): ) def test_lookup(request_type, transport: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2243,7 +2707,7 @@ def test_lookup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2260,7 +2724,7 @@ async def test_lookup_async( transport: str = "grpc_asyncio", request_type=service.LookupRequest ): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2292,7 +2756,7 @@ async def test_lookup_async_from_dict(): def test_lookup_field_headers(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2322,7 +2786,7 @@ def test_lookup_field_headers(): @pytest.mark.asyncio async def test_lookup_field_headers_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2353,7 +2817,7 @@ async def test_lookup_field_headers_async(): def test_lookup_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2381,7 +2845,7 @@ def test_lookup_flattened(): def test_lookup_flattened_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2397,7 +2861,7 @@ def test_lookup_flattened_error(): @pytest.mark.asyncio async def test_lookup_flattened_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2430,7 +2894,7 @@ async def test_lookup_flattened_async(): @pytest.mark.asyncio async def test_lookup_flattened_error_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2452,7 +2916,7 @@ async def test_lookup_flattened_error_async(): ) def test_search(request_type, transport: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2479,7 +2943,7 @@ def test_search_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2496,7 +2960,7 @@ async def test_search_async( transport: str = "grpc_asyncio", request_type=service.SearchRequest ): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2528,7 +2992,7 @@ async def test_search_async_from_dict(): def test_search_field_headers(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2558,7 +3022,7 @@ def test_search_field_headers(): @pytest.mark.asyncio async def test_search_field_headers_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2589,7 +3053,7 @@ async def test_search_field_headers_async(): def test_search_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2617,7 +3081,7 @@ def test_search_flattened(): def test_search_flattened_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2633,7 +3097,7 @@ def test_search_flattened_error(): @pytest.mark.asyncio async def test_search_flattened_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2666,7 +3130,7 @@ async def test_search_flattened_async(): @pytest.mark.asyncio async def test_search_flattened_error_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2688,7 +3152,7 @@ async def test_search_flattened_error_async(): ) def test_lookup_public_kg(request_type, transport: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2715,7 +3179,7 @@ def test_lookup_public_kg_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2732,7 +3196,7 @@ async def test_lookup_public_kg_async( transport: str = "grpc_asyncio", request_type=service.LookupPublicKgRequest ): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2764,7 +3228,7 @@ async def test_lookup_public_kg_async_from_dict(): def test_lookup_public_kg_field_headers(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2794,7 +3258,7 @@ def test_lookup_public_kg_field_headers(): @pytest.mark.asyncio async def test_lookup_public_kg_field_headers_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2825,7 +3289,7 @@ async def test_lookup_public_kg_field_headers_async(): def test_lookup_public_kg_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2853,7 +3317,7 @@ def test_lookup_public_kg_flattened(): def test_lookup_public_kg_flattened_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2869,7 +3333,7 @@ def test_lookup_public_kg_flattened_error(): @pytest.mark.asyncio async def test_lookup_public_kg_flattened_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2902,7 +3366,7 @@ async def test_lookup_public_kg_flattened_async(): @pytest.mark.asyncio async def test_lookup_public_kg_flattened_error_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2924,7 +3388,7 @@ async def test_lookup_public_kg_flattened_error_async(): ) def test_search_public_kg(request_type, transport: str = "grpc"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2951,7 +3415,7 @@ def test_search_public_kg_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2968,7 +3432,7 @@ async def test_search_public_kg_async( transport: str = "grpc_asyncio", request_type=service.SearchPublicKgRequest ): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3000,7 +3464,7 @@ async def test_search_public_kg_async_from_dict(): def test_search_public_kg_field_headers(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3030,7 +3494,7 @@ def test_search_public_kg_field_headers(): @pytest.mark.asyncio async def test_search_public_kg_field_headers_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3061,7 +3525,7 @@ async def test_search_public_kg_field_headers_async(): def test_search_public_kg_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3089,7 +3553,7 @@ def test_search_public_kg_flattened(): def test_search_public_kg_flattened_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3105,7 +3569,7 @@ def test_search_public_kg_flattened_error(): @pytest.mark.asyncio async def test_search_public_kg_flattened_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3138,7 +3602,7 @@ async def test_search_public_kg_flattened_async(): @pytest.mark.asyncio async def test_search_public_kg_flattened_error_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3160,7 +3624,7 @@ async def test_search_public_kg_flattened_error_async(): ) def test_create_entity_reconciliation_job_rest(request_type): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3320,7 +3784,7 @@ def test_create_entity_reconciliation_job_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_entity_reconciliation_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3329,7 +3793,7 @@ def test_create_entity_reconciliation_job_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_entity_reconciliation_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3338,7 +3802,7 @@ def test_create_entity_reconciliation_job_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3381,7 +3845,7 @@ def test_create_entity_reconciliation_job_rest_required_fields( def test_create_entity_reconciliation_job_rest_unset_required_fields(): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -3401,7 +3865,7 @@ def test_create_entity_reconciliation_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_entity_reconciliation_job_rest_interceptors(null_interceptor): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnterpriseKnowledgeGraphServiceRestInterceptor(), @@ -3461,7 +3925,7 @@ def test_create_entity_reconciliation_job_rest_bad_request( transport: str = "rest", request_type=service.CreateEntityReconciliationJobRequest ): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3483,7 +3947,7 @@ def test_create_entity_reconciliation_job_rest_bad_request( def test_create_entity_reconciliation_job_rest_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3528,7 +3992,7 @@ def test_create_entity_reconciliation_job_rest_flattened(): def test_create_entity_reconciliation_job_rest_flattened_error(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3546,7 +4010,7 @@ def test_create_entity_reconciliation_job_rest_flattened_error(transport: str = def test_create_entity_reconciliation_job_rest_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3559,7 +4023,7 @@ def test_create_entity_reconciliation_job_rest_error(): ) def test_get_entity_reconciliation_job_rest(request_type): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3614,7 +4078,7 @@ def test_get_entity_reconciliation_job_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_entity_reconciliation_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3623,7 +4087,7 @@ def test_get_entity_reconciliation_job_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_entity_reconciliation_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3632,7 +4096,7 @@ def test_get_entity_reconciliation_job_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3674,7 +4138,7 @@ def test_get_entity_reconciliation_job_rest_required_fields( def test_get_entity_reconciliation_job_rest_unset_required_fields(): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_entity_reconciliation_job._get_unset_required_fields( @@ -3686,7 +4150,7 @@ def test_get_entity_reconciliation_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_entity_reconciliation_job_rest_interceptors(null_interceptor): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnterpriseKnowledgeGraphServiceRestInterceptor(), @@ -3746,7 +4210,7 @@ def test_get_entity_reconciliation_job_rest_bad_request( transport: str = "rest", request_type=service.GetEntityReconciliationJobRequest ): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3770,7 +4234,7 @@ def test_get_entity_reconciliation_job_rest_bad_request( def test_get_entity_reconciliation_job_rest_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3814,7 +4278,7 @@ def test_get_entity_reconciliation_job_rest_flattened(): def test_get_entity_reconciliation_job_rest_flattened_error(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3829,7 +4293,7 @@ def test_get_entity_reconciliation_job_rest_flattened_error(transport: str = "re def test_get_entity_reconciliation_job_rest_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3842,7 +4306,7 @@ def test_get_entity_reconciliation_job_rest_error(): ) def test_list_entity_reconciliation_jobs_rest(request_type): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3893,7 +4357,7 @@ def test_list_entity_reconciliation_jobs_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_entity_reconciliation_jobs._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3902,7 +4366,7 @@ def test_list_entity_reconciliation_jobs_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_entity_reconciliation_jobs._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3919,7 +4383,7 @@ def test_list_entity_reconciliation_jobs_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3961,7 +4425,7 @@ def test_list_entity_reconciliation_jobs_rest_required_fields( def test_list_entity_reconciliation_jobs_rest_unset_required_fields(): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_entity_reconciliation_jobs._get_unset_required_fields( @@ -3982,7 +4446,7 @@ def test_list_entity_reconciliation_jobs_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_entity_reconciliation_jobs_rest_interceptors(null_interceptor): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnterpriseKnowledgeGraphServiceRestInterceptor(), @@ -4044,7 +4508,7 @@ def test_list_entity_reconciliation_jobs_rest_bad_request( transport: str = "rest", request_type=service.ListEntityReconciliationJobsRequest ): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4066,7 +4530,7 @@ def test_list_entity_reconciliation_jobs_rest_bad_request( def test_list_entity_reconciliation_jobs_rest_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4108,7 +4572,7 @@ def test_list_entity_reconciliation_jobs_rest_flattened(): def test_list_entity_reconciliation_jobs_rest_flattened_error(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4123,7 +4587,7 @@ def test_list_entity_reconciliation_jobs_rest_flattened_error(transport: str = " def test_list_entity_reconciliation_jobs_rest_pager(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4195,7 +4659,7 @@ def test_list_entity_reconciliation_jobs_rest_pager(transport: str = "rest"): ) def test_cancel_entity_reconciliation_job_rest(request_type): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4243,7 +4707,7 @@ def test_cancel_entity_reconciliation_job_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).cancel_entity_reconciliation_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4252,7 +4716,7 @@ def test_cancel_entity_reconciliation_job_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).cancel_entity_reconciliation_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4261,7 +4725,7 @@ def test_cancel_entity_reconciliation_job_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4301,7 +4765,7 @@ def test_cancel_entity_reconciliation_job_rest_required_fields( def test_cancel_entity_reconciliation_job_rest_unset_required_fields(): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -4313,7 +4777,7 @@ def test_cancel_entity_reconciliation_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_cancel_entity_reconciliation_job_rest_interceptors(null_interceptor): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnterpriseKnowledgeGraphServiceRestInterceptor(), @@ -4364,7 +4828,7 @@ def test_cancel_entity_reconciliation_job_rest_bad_request( transport: str = "rest", request_type=service.CancelEntityReconciliationJobRequest ): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4388,7 +4852,7 @@ def test_cancel_entity_reconciliation_job_rest_bad_request( def test_cancel_entity_reconciliation_job_rest_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4430,7 +4894,7 @@ def test_cancel_entity_reconciliation_job_rest_flattened(): def test_cancel_entity_reconciliation_job_rest_flattened_error(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4445,7 +4909,7 @@ def test_cancel_entity_reconciliation_job_rest_flattened_error(transport: str = def test_cancel_entity_reconciliation_job_rest_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4458,7 +4922,7 @@ def test_cancel_entity_reconciliation_job_rest_error(): ) def test_delete_entity_reconciliation_job_rest(request_type): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4506,7 +4970,7 @@ def test_delete_entity_reconciliation_job_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_entity_reconciliation_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4515,7 +4979,7 @@ def test_delete_entity_reconciliation_job_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_entity_reconciliation_job._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4524,7 +4988,7 @@ def test_delete_entity_reconciliation_job_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4563,7 +5027,7 @@ def test_delete_entity_reconciliation_job_rest_required_fields( def test_delete_entity_reconciliation_job_rest_unset_required_fields(): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -4575,7 +5039,7 @@ def test_delete_entity_reconciliation_job_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_entity_reconciliation_job_rest_interceptors(null_interceptor): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnterpriseKnowledgeGraphServiceRestInterceptor(), @@ -4626,7 +5090,7 @@ def test_delete_entity_reconciliation_job_rest_bad_request( transport: str = "rest", request_type=service.DeleteEntityReconciliationJobRequest ): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4650,7 +5114,7 @@ def test_delete_entity_reconciliation_job_rest_bad_request( def test_delete_entity_reconciliation_job_rest_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4692,7 +5156,7 @@ def test_delete_entity_reconciliation_job_rest_flattened(): def test_delete_entity_reconciliation_job_rest_flattened_error(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4707,7 +5171,7 @@ def test_delete_entity_reconciliation_job_rest_flattened_error(transport: str = def test_delete_entity_reconciliation_job_rest_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4720,7 +5184,7 @@ def test_delete_entity_reconciliation_job_rest_error(): ) def test_lookup_rest(request_type): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4768,7 +5232,7 @@ def test_lookup_rest_required_fields(request_type=service.LookupRequest): assert "ids" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).lookup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4780,7 +5244,7 @@ def test_lookup_rest_required_fields(request_type=service.LookupRequest): jsonified_request["ids"] = "ids_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).lookup._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4798,7 +5262,7 @@ def test_lookup_rest_required_fields(request_type=service.LookupRequest): assert jsonified_request["ids"] == "ids_value" client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4846,7 +5310,7 @@ def test_lookup_rest_required_fields(request_type=service.LookupRequest): def test_lookup_rest_unset_required_fields(): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.lookup._get_unset_required_fields({}) @@ -4869,7 +5333,7 @@ def test_lookup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_lookup_rest_interceptors(null_interceptor): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnterpriseKnowledgeGraphServiceRestInterceptor(), @@ -4925,7 +5389,7 @@ def test_lookup_rest_bad_request( transport: str = "rest", request_type=service.LookupRequest ): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4947,7 +5411,7 @@ def test_lookup_rest_bad_request( def test_lookup_rest_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4990,7 +5454,7 @@ def test_lookup_rest_flattened(): def test_lookup_rest_flattened_error(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5006,7 +5470,7 @@ def test_lookup_rest_flattened_error(transport: str = "rest"): def test_lookup_rest_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5019,7 +5483,7 @@ def test_lookup_rest_error(): ) def test_search_rest(request_type): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5067,7 +5531,7 @@ def test_search_rest_required_fields(request_type=service.SearchRequest): assert "query" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5079,7 +5543,7 @@ def test_search_rest_required_fields(request_type=service.SearchRequest): jsonified_request["query"] = "query_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5099,7 +5563,7 @@ def test_search_rest_required_fields(request_type=service.SearchRequest): assert jsonified_request["query"] == "query_value" client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5147,7 +5611,7 @@ def test_search_rest_required_fields(request_type=service.SearchRequest): def test_search_rest_unset_required_fields(): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search._get_unset_required_fields({}) @@ -5172,7 +5636,7 @@ def test_search_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_rest_interceptors(null_interceptor): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnterpriseKnowledgeGraphServiceRestInterceptor(), @@ -5228,7 +5692,7 @@ def test_search_rest_bad_request( transport: str = "rest", request_type=service.SearchRequest ): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5250,7 +5714,7 @@ def test_search_rest_bad_request( def test_search_rest_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5293,7 +5757,7 @@ def test_search_rest_flattened(): def test_search_rest_flattened_error(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5309,7 +5773,7 @@ def test_search_rest_flattened_error(transport: str = "rest"): def test_search_rest_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5322,7 +5786,7 @@ def test_search_rest_error(): ) def test_lookup_public_kg_rest(request_type): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5372,7 +5836,7 @@ def test_lookup_public_kg_rest_required_fields( assert "ids" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).lookup_public_kg._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5384,7 +5848,7 @@ def test_lookup_public_kg_rest_required_fields( jsonified_request["ids"] = "ids_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).lookup_public_kg._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5402,7 +5866,7 @@ def test_lookup_public_kg_rest_required_fields( assert jsonified_request["ids"] == "ids_value" client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5450,7 +5914,7 @@ def test_lookup_public_kg_rest_required_fields( def test_lookup_public_kg_rest_unset_required_fields(): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.lookup_public_kg._get_unset_required_fields({}) @@ -5473,7 +5937,7 @@ def test_lookup_public_kg_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_lookup_public_kg_rest_interceptors(null_interceptor): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnterpriseKnowledgeGraphServiceRestInterceptor(), @@ -5531,7 +5995,7 @@ def test_lookup_public_kg_rest_bad_request( transport: str = "rest", request_type=service.LookupPublicKgRequest ): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5553,7 +6017,7 @@ def test_lookup_public_kg_rest_bad_request( def test_lookup_public_kg_rest_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5596,7 +6060,7 @@ def test_lookup_public_kg_rest_flattened(): def test_lookup_public_kg_rest_flattened_error(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5612,7 +6076,7 @@ def test_lookup_public_kg_rest_flattened_error(transport: str = "rest"): def test_lookup_public_kg_rest_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5625,7 +6089,7 @@ def test_lookup_public_kg_rest_error(): ) def test_search_public_kg_rest(request_type): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5675,7 +6139,7 @@ def test_search_public_kg_rest_required_fields( assert "query" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_public_kg._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5687,7 +6151,7 @@ def test_search_public_kg_rest_required_fields( jsonified_request["query"] = "query_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).search_public_kg._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5707,7 +6171,7 @@ def test_search_public_kg_rest_required_fields( assert jsonified_request["query"] == "query_value" client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5755,7 +6219,7 @@ def test_search_public_kg_rest_required_fields( def test_search_public_kg_rest_unset_required_fields(): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.search_public_kg._get_unset_required_fields({}) @@ -5780,7 +6244,7 @@ def test_search_public_kg_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_search_public_kg_rest_interceptors(null_interceptor): transport = transports.EnterpriseKnowledgeGraphServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EnterpriseKnowledgeGraphServiceRestInterceptor(), @@ -5838,7 +6302,7 @@ def test_search_public_kg_rest_bad_request( transport: str = "rest", request_type=service.SearchPublicKgRequest ): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5860,7 +6324,7 @@ def test_search_public_kg_rest_bad_request( def test_search_public_kg_rest_flattened(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5903,7 +6367,7 @@ def test_search_public_kg_rest_flattened(): def test_search_public_kg_rest_flattened_error(transport: str = "rest"): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5919,24 +6383,24 @@ def test_search_public_kg_rest_flattened_error(transport: str = "rest"): def test_search_public_kg_rest_error(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EnterpriseKnowledgeGraphServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EnterpriseKnowledgeGraphServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EnterpriseKnowledgeGraphServiceClient( @@ -5946,7 +6410,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EnterpriseKnowledgeGraphServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5957,16 +6421,17 @@ 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 = EnterpriseKnowledgeGraphServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EnterpriseKnowledgeGraphServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EnterpriseKnowledgeGraphServiceClient( @@ -5978,7 +6443,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EnterpriseKnowledgeGraphServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EnterpriseKnowledgeGraphServiceClient(transport=transport) assert client.transport is transport @@ -5987,13 +6452,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EnterpriseKnowledgeGraphServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EnterpriseKnowledgeGraphServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -6010,7 +6475,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -6026,7 +6491,7 @@ def test_transport_kind(transport_name): transport = EnterpriseKnowledgeGraphServiceClient.get_transport_class( transport_name )( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -6034,7 +6499,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -6046,7 +6511,7 @@ def test_enterprise_knowledge_graph_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EnterpriseKnowledgeGraphServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -6058,7 +6523,7 @@ def test_enterprise_knowledge_graph_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EnterpriseKnowledgeGraphServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6098,7 +6563,7 @@ def test_enterprise_knowledge_graph_service_base_transport_with_credentials_file "google.cloud.enterpriseknowledgegraph_v1.services.enterprise_knowledge_graph_service.transports.EnterpriseKnowledgeGraphServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EnterpriseKnowledgeGraphServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6117,7 +6582,7 @@ def test_enterprise_knowledge_graph_service_base_transport_with_adc(): "google.cloud.enterpriseknowledgegraph_v1.services.enterprise_knowledge_graph_service.transports.EnterpriseKnowledgeGraphServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EnterpriseKnowledgeGraphServiceTransport() adc.assert_called_once() @@ -6125,7 +6590,7 @@ def test_enterprise_knowledge_graph_service_base_transport_with_adc(): def test_enterprise_knowledge_graph_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EnterpriseKnowledgeGraphServiceClient() adc.assert_called_once_with( scopes=None, @@ -6145,7 +6610,7 @@ def test_enterprise_knowledge_graph_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -6199,7 +6664,7 @@ def test_enterprise_knowledge_graph_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6229,7 +6694,7 @@ def test_enterprise_knowledge_graph_service_transport_create_channel( def test_enterprise_knowledge_graph_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6267,7 +6732,7 @@ def test_enterprise_knowledge_graph_service_grpc_transport_client_cert_source_fo def test_enterprise_knowledge_graph_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -6287,7 +6752,7 @@ def test_enterprise_knowledge_graph_service_http_transport_client_cert_source_fo ) def test_enterprise_knowledge_graph_service_host_no_port(transport_name): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="enterpriseknowledgegraph.googleapis.com" ), @@ -6310,7 +6775,7 @@ def test_enterprise_knowledge_graph_service_host_no_port(transport_name): ) def test_enterprise_knowledge_graph_service_host_with_port(transport_name): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="enterpriseknowledgegraph.googleapis.com:8000" ), @@ -6332,8 +6797,8 @@ def test_enterprise_knowledge_graph_service_host_with_port(transport_name): def test_enterprise_knowledge_graph_service_client_transport_session_collision( transport_name, ): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EnterpriseKnowledgeGraphServiceClient( credentials=creds1, transport=transport_name, @@ -6421,7 +6886,7 @@ def test_enterprise_knowledge_graph_service_transport_channel_mtls_with_client_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6766,7 +7231,7 @@ def test_client_with_default_client_info(): transports.EnterpriseKnowledgeGraphServiceTransport, "_prep_wrapped_messages" ) as prep: client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6776,7 +7241,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EnterpriseKnowledgeGraphServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6785,7 +7250,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EnterpriseKnowledgeGraphServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6804,7 +7269,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -6821,7 +7286,7 @@ def test_client_ctx(): ] for transport in transports: client = EnterpriseKnowledgeGraphServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -6858,7 +7323,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, diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts/gapic_version.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts/gapic_version.py index 1aa1253ea3ab..360a0d13ebdd 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts/gapic_version.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.6.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/gapic_version.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/gapic_version.py index 1aa1253ea3ab..360a0d13ebdd 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/gapic_version.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.6.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/async_client.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/async_client.py index 1a53744ca832..ed1f92a9b67d 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/async_client.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.essential_contacts_v1 import gapic_version as package_version 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.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -60,8 +60,14 @@ class EssentialContactsServiceAsyncClient: _client: EssentialContactsServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EssentialContactsServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EssentialContactsServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = ( + EssentialContactsServiceClient._DEFAULT_ENDPOINT_TEMPLATE + ) + _DEFAULT_UNIVERSE = EssentialContactsServiceClient._DEFAULT_UNIVERSE contact_path = staticmethod(EssentialContactsServiceClient.contact_path) parse_contact_path = staticmethod(EssentialContactsServiceClient.parse_contact_path) @@ -172,6 +178,25 @@ def transport(self) -> EssentialContactsServiceTransport: """ 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(EssentialContactsServiceClient).get_transport_class, type(EssentialContactsServiceClient), @@ -185,7 +210,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the essential contacts service client. + """Instantiates the essential contacts service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -196,23 +221,38 @@ def __init__( transport (Union[str, ~.EssentialContactsServiceTransport]): 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. @@ -333,6 +373,9 @@ async def sample_create_contact(): 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, @@ -456,6 +499,9 @@ async def sample_update_contact(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -572,6 +618,9 @@ async def sample_list_contacts(): 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, @@ -694,6 +743,9 @@ async def sample_get_contact(): 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, @@ -789,6 +841,9 @@ async def sample_delete_contact(): 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, @@ -872,6 +927,9 @@ async def sample_compute_contacts(): 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, @@ -955,6 +1013,9 @@ async def sample_send_test_message(): gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. await rpc( request, diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/client.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/client.py index 16e934c2f586..d917b1cc787c 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/client.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.essential_contacts_v1 import gapic_version as package_version 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.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -130,11 +131,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 = "essentialcontacts.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "essentialcontacts.{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 @@ -280,7 +285,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 @@ -310,6 +315,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") @@ -343,6 +353,177 @@ 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 + + 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 + + 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 = EssentialContactsServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EssentialContactsServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + EssentialContactsServiceClient._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 = EssentialContactsServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = EssentialContactsServiceClient._DEFAULT_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 EssentialContactsServiceClient._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, *, @@ -362,22 +543,32 @@ def __init__( transport (Union[str, EssentialContactsServiceTransport]): 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. @@ -388,17 +579,36 @@ 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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = EssentialContactsServiceClient._read_environment_variables() + self._client_cert_source = ( + EssentialContactsServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + ) + self._universe_domain = EssentialContactsServiceClient._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" @@ -407,20 +617,33 @@ 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, EssentialContactsServiceTransport): + transport_provided = isinstance(transport, EssentialContactsServiceTransport) + if transport_provided: # transport is a EssentialContactsServiceTransport 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(EssentialContactsServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or EssentialContactsServiceClient._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( @@ -430,17 +653,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 create_contact( @@ -552,6 +775,9 @@ def sample_create_contact(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -675,6 +901,9 @@ def sample_update_contact(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -782,6 +1011,9 @@ def sample_list_contacts(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -895,6 +1127,9 @@ def sample_get_contact(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -990,6 +1225,9 @@ def sample_delete_contact(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1074,6 +1312,9 @@ def sample_compute_contacts(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1158,6 +1399,9 @@ def sample_send_test_message(): gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, diff --git a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/base.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/base.py index 473388323885..600e82098162 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/base.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/base.py @@ -57,7 +57,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'essentialcontacts.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 @@ -120,6 +120,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-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc.py index 08fabaa61c7c..c54d1b888473 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc.py @@ -64,7 +64,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'essentialcontacts.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-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc_asyncio.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc_asyncio.py index c101d65145f8..844660151b44 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/grpc_asyncio.py @@ -109,7 +109,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'essentialcontacts.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-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/rest.py b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/rest.py index bff16a322585..cf1929b2bc95 100644 --- a/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/rest.py +++ b/packages/google-cloud-essential-contacts/google/cloud/essential_contacts_v1/services/essential_contacts_service/transports/rest.py @@ -31,9 +31,9 @@ from requests import __version__ as requests_version 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.protobuf import empty_pb2 # type: ignore @@ -282,7 +282,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'essentialcontacts.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-essential-contacts/noxfile.py b/packages/google-cloud-essential-contacts/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-essential-contacts/noxfile.py +++ b/packages/google-cloud-essential-contacts/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-essential-contacts/samples/generated_samples/snippet_metadata_google.cloud.essentialcontacts.v1.json b/packages/google-cloud-essential-contacts/samples/generated_samples/snippet_metadata_google.cloud.essentialcontacts.v1.json index 77a717d08ee6..5c3df15cfed5 100644 --- a/packages/google-cloud-essential-contacts/samples/generated_samples/snippet_metadata_google.cloud.essentialcontacts.v1.json +++ b/packages/google-cloud-essential-contacts/samples/generated_samples/snippet_metadata_google.cloud.essentialcontacts.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-essential-contacts", - "version": "1.6.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-essential-contacts/tests/unit/gapic/essential_contacts_v1/test_essential_contacts_service.py b/packages/google-cloud-essential-contacts/tests/unit/gapic/essential_contacts_v1/test_essential_contacts_service.py index ab3d9e9fbe81..381047bafc7d 100644 --- a/packages/google-cloud-essential-contacts/tests/unit/gapic/essential_contacts_v1/test_essential_contacts_service.py +++ b/packages/google-cloud-essential-contacts/tests/unit/gapic/essential_contacts_v1/test_essential_contacts_service.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -68,6 +68,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -98,6 +121,291 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert EssentialContactsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EssentialContactsServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EssentialContactsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EssentialContactsServiceClient._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 EssentialContactsServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EssentialContactsServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EssentialContactsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EssentialContactsServiceClient._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 EssentialContactsServiceClient._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 EssentialContactsServiceClient._get_client_cert_source(None, False) is None + assert ( + EssentialContactsServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + EssentialContactsServiceClient._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 ( + EssentialContactsServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + EssentialContactsServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EssentialContactsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EssentialContactsServiceClient), +) +@mock.patch.object( + EssentialContactsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EssentialContactsServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EssentialContactsServiceClient._DEFAULT_UNIVERSE + default_endpoint = EssentialContactsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EssentialContactsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + EssentialContactsServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EssentialContactsServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EssentialContactsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EssentialContactsServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + EssentialContactsServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == EssentialContactsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EssentialContactsServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EssentialContactsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EssentialContactsServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + EssentialContactsServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EssentialContactsServiceClient._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 ( + EssentialContactsServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + EssentialContactsServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + EssentialContactsServiceClient._get_universe_domain(None, None) + == EssentialContactsServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EssentialContactsServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + EssentialContactsServiceClient, + transports.EssentialContactsServiceGrpcTransport, + "grpc", + ), + ( + EssentialContactsServiceClient, + transports.EssentialContactsServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -109,7 +417,7 @@ def test__get_default_mtls_endpoint(): def test_essential_contacts_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -163,7 +471,7 @@ def test_essential_contacts_service_client_service_account_always_use_jwt( def test_essential_contacts_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -221,13 +529,13 @@ def test_essential_contacts_service_client_get_transport_class(): ) @mock.patch.object( EssentialContactsServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EssentialContactsServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EssentialContactsServiceClient), ) @mock.patch.object( EssentialContactsServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EssentialContactsServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EssentialContactsServiceAsyncClient), ) def test_essential_contacts_service_client_client_options( client_class, transport_class, transport_name @@ -236,7 +544,9 @@ def test_essential_contacts_service_client_client_options( with mock.patch.object( EssentialContactsServiceClient, "get_transport_class" ) as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -273,7 +583,9 @@ def test_essential_contacts_service_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, @@ -303,15 +615,23 @@ def test_essential_contacts_service_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") @@ -321,7 +641,9 @@ def test_essential_contacts_service_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", @@ -339,7 +661,9 @@ def test_essential_contacts_service_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, @@ -392,13 +716,13 @@ def test_essential_contacts_service_client_client_options( ) @mock.patch.object( EssentialContactsServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EssentialContactsServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EssentialContactsServiceClient), ) @mock.patch.object( EssentialContactsServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EssentialContactsServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EssentialContactsServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_essential_contacts_service_client_mtls_env_auto( @@ -421,7 +745,9 @@ def test_essential_contacts_service_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 @@ -453,7 +779,9 @@ def test_essential_contacts_service_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 @@ -487,7 +815,9 @@ def test_essential_contacts_service_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, @@ -580,6 +910,119 @@ def test_essential_contacts_service_client_get_mtls_endpoint_and_cert_source( 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", + [EssentialContactsServiceClient, EssentialContactsServiceAsyncClient], +) +@mock.patch.object( + EssentialContactsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EssentialContactsServiceClient), +) +@mock.patch.object( + EssentialContactsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EssentialContactsServiceAsyncClient), +) +def test_essential_contacts_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EssentialContactsServiceClient._DEFAULT_UNIVERSE + default_endpoint = EssentialContactsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EssentialContactsServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -614,7 +1057,9 @@ def test_essential_contacts_service_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, @@ -659,7 +1104,9 @@ def test_essential_contacts_service_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, @@ -719,7 +1166,9 @@ def test_essential_contacts_service_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, @@ -736,8 +1185,8 @@ def test_essential_contacts_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -766,7 +1215,7 @@ def test_essential_contacts_service_client_create_channel_credentials_file( ) def test_create_contact(request_type, transport: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -806,7 +1255,7 @@ def test_create_contact_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -823,7 +1272,7 @@ async def test_create_contact_async( transport: str = "grpc_asyncio", request_type=service.CreateContactRequest ): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -868,7 +1317,7 @@ async def test_create_contact_async_from_dict(): def test_create_contact_field_headers(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -898,7 +1347,7 @@ def test_create_contact_field_headers(): @pytest.mark.asyncio async def test_create_contact_field_headers_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -927,7 +1376,7 @@ async def test_create_contact_field_headers_async(): def test_create_contact_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -955,7 +1404,7 @@ def test_create_contact_flattened(): def test_create_contact_flattened_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -971,7 +1420,7 @@ def test_create_contact_flattened_error(): @pytest.mark.asyncio async def test_create_contact_flattened_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1002,7 +1451,7 @@ async def test_create_contact_flattened_async(): @pytest.mark.asyncio async def test_create_contact_flattened_error_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1024,7 +1473,7 @@ async def test_create_contact_flattened_error_async(): ) def test_update_contact(request_type, transport: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1064,7 +1513,7 @@ def test_update_contact_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1081,7 +1530,7 @@ async def test_update_contact_async( transport: str = "grpc_asyncio", request_type=service.UpdateContactRequest ): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1126,7 +1575,7 @@ async def test_update_contact_async_from_dict(): def test_update_contact_field_headers(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1156,7 +1605,7 @@ def test_update_contact_field_headers(): @pytest.mark.asyncio async def test_update_contact_field_headers_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1185,7 +1634,7 @@ async def test_update_contact_field_headers_async(): def test_update_contact_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1213,7 +1662,7 @@ def test_update_contact_flattened(): def test_update_contact_flattened_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1229,7 +1678,7 @@ def test_update_contact_flattened_error(): @pytest.mark.asyncio async def test_update_contact_flattened_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1260,7 +1709,7 @@ async def test_update_contact_flattened_async(): @pytest.mark.asyncio async def test_update_contact_flattened_error_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1282,7 +1731,7 @@ async def test_update_contact_flattened_error_async(): ) def test_list_contacts(request_type, transport: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1312,7 +1761,7 @@ def test_list_contacts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1329,7 +1778,7 @@ async def test_list_contacts_async( transport: str = "grpc_asyncio", request_type=service.ListContactsRequest ): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1364,7 +1813,7 @@ async def test_list_contacts_async_from_dict(): def test_list_contacts_field_headers(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1394,7 +1843,7 @@ def test_list_contacts_field_headers(): @pytest.mark.asyncio async def test_list_contacts_field_headers_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1425,7 +1874,7 @@ async def test_list_contacts_field_headers_async(): def test_list_contacts_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1449,7 +1898,7 @@ def test_list_contacts_flattened(): def test_list_contacts_flattened_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1464,7 +1913,7 @@ def test_list_contacts_flattened_error(): @pytest.mark.asyncio async def test_list_contacts_flattened_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1493,7 +1942,7 @@ async def test_list_contacts_flattened_async(): @pytest.mark.asyncio async def test_list_contacts_flattened_error_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1507,7 +1956,7 @@ async def test_list_contacts_flattened_error_async(): def test_list_contacts_pager(transport_name: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1557,7 +2006,7 @@ def test_list_contacts_pager(transport_name: str = "grpc"): def test_list_contacts_pages(transport_name: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1599,7 +2048,7 @@ def test_list_contacts_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_contacts_async_pager(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1649,7 +2098,7 @@ async def test_list_contacts_async_pager(): @pytest.mark.asyncio async def test_list_contacts_async_pages(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1704,7 +2153,7 @@ async def test_list_contacts_async_pages(): ) def test_get_contact(request_type, transport: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1744,7 +2193,7 @@ def test_get_contact_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1761,7 +2210,7 @@ async def test_get_contact_async( transport: str = "grpc_asyncio", request_type=service.GetContactRequest ): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1806,7 +2255,7 @@ async def test_get_contact_async_from_dict(): def test_get_contact_field_headers(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1836,7 +2285,7 @@ def test_get_contact_field_headers(): @pytest.mark.asyncio async def test_get_contact_field_headers_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1865,7 +2314,7 @@ async def test_get_contact_field_headers_async(): def test_get_contact_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1889,7 +2338,7 @@ def test_get_contact_flattened(): def test_get_contact_flattened_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1904,7 +2353,7 @@ def test_get_contact_flattened_error(): @pytest.mark.asyncio async def test_get_contact_flattened_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1931,7 +2380,7 @@ async def test_get_contact_flattened_async(): @pytest.mark.asyncio async def test_get_contact_flattened_error_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1952,7 +2401,7 @@ async def test_get_contact_flattened_error_async(): ) def test_delete_contact(request_type, transport: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1979,7 +2428,7 @@ def test_delete_contact_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1996,7 +2445,7 @@ async def test_delete_contact_async( transport: str = "grpc_asyncio", request_type=service.DeleteContactRequest ): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2026,7 +2475,7 @@ async def test_delete_contact_async_from_dict(): def test_delete_contact_field_headers(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2056,7 +2505,7 @@ def test_delete_contact_field_headers(): @pytest.mark.asyncio async def test_delete_contact_field_headers_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2085,7 +2534,7 @@ async def test_delete_contact_field_headers_async(): def test_delete_contact_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2109,7 +2558,7 @@ def test_delete_contact_flattened(): def test_delete_contact_flattened_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2124,7 +2573,7 @@ def test_delete_contact_flattened_error(): @pytest.mark.asyncio async def test_delete_contact_flattened_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2151,7 +2600,7 @@ async def test_delete_contact_flattened_async(): @pytest.mark.asyncio async def test_delete_contact_flattened_error_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2172,7 +2621,7 @@ async def test_delete_contact_flattened_error_async(): ) def test_compute_contacts(request_type, transport: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2202,7 +2651,7 @@ def test_compute_contacts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2219,7 +2668,7 @@ async def test_compute_contacts_async( transport: str = "grpc_asyncio", request_type=service.ComputeContactsRequest ): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2254,7 +2703,7 @@ async def test_compute_contacts_async_from_dict(): def test_compute_contacts_field_headers(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2284,7 +2733,7 @@ def test_compute_contacts_field_headers(): @pytest.mark.asyncio async def test_compute_contacts_field_headers_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2315,7 +2764,7 @@ async def test_compute_contacts_field_headers_async(): def test_compute_contacts_pager(transport_name: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2365,7 +2814,7 @@ def test_compute_contacts_pager(transport_name: str = "grpc"): def test_compute_contacts_pages(transport_name: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2407,7 +2856,7 @@ def test_compute_contacts_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_compute_contacts_async_pager(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2457,7 +2906,7 @@ async def test_compute_contacts_async_pager(): @pytest.mark.asyncio async def test_compute_contacts_async_pages(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2512,7 +2961,7 @@ async def test_compute_contacts_async_pages(): ) def test_send_test_message(request_type, transport: str = "grpc"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2541,7 +2990,7 @@ def test_send_test_message_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2560,7 +3009,7 @@ async def test_send_test_message_async( transport: str = "grpc_asyncio", request_type=service.SendTestMessageRequest ): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2592,7 +3041,7 @@ async def test_send_test_message_async_from_dict(): def test_send_test_message_field_headers(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2624,7 +3073,7 @@ def test_send_test_message_field_headers(): @pytest.mark.asyncio async def test_send_test_message_field_headers_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2662,7 +3111,7 @@ async def test_send_test_message_field_headers_async(): ) def test_create_contact_rest(request_type): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2796,7 +3245,7 @@ def test_create_contact_rest_required_fields(request_type=service.CreateContactR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_contact._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2805,7 +3254,7 @@ def test_create_contact_rest_required_fields(request_type=service.CreateContactR jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_contact._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2814,7 +3263,7 @@ def test_create_contact_rest_required_fields(request_type=service.CreateContactR assert jsonified_request["parent"] == "parent_value" client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2857,7 +3306,7 @@ def test_create_contact_rest_required_fields(request_type=service.CreateContactR def test_create_contact_rest_unset_required_fields(): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_contact._get_unset_required_fields({}) @@ -2875,7 +3324,7 @@ def test_create_contact_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_contact_rest_interceptors(null_interceptor): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EssentialContactsServiceRestInterceptor(), @@ -2929,7 +3378,7 @@ def test_create_contact_rest_bad_request( transport: str = "rest", request_type=service.CreateContactRequest ): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2951,7 +3400,7 @@ def test_create_contact_rest_bad_request( def test_create_contact_rest_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2992,7 +3441,7 @@ def test_create_contact_rest_flattened(): def test_create_contact_rest_flattened_error(transport: str = "rest"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3008,7 +3457,7 @@ def test_create_contact_rest_flattened_error(transport: str = "rest"): def test_create_contact_rest_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3021,7 +3470,7 @@ def test_create_contact_rest_error(): ) def test_update_contact_rest(request_type): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3154,14 +3603,14 @@ def test_update_contact_rest_required_fields(request_type=service.UpdateContactR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_contact._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_contact._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3170,7 +3619,7 @@ def test_update_contact_rest_required_fields(request_type=service.UpdateContactR # verify required fields with non-default values are left alone client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3213,7 +3662,7 @@ def test_update_contact_rest_required_fields(request_type=service.UpdateContactR def test_update_contact_rest_unset_required_fields(): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_contact._get_unset_required_fields({}) @@ -3223,7 +3672,7 @@ def test_update_contact_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_contact_rest_interceptors(null_interceptor): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EssentialContactsServiceRestInterceptor(), @@ -3277,7 +3726,7 @@ def test_update_contact_rest_bad_request( transport: str = "rest", request_type=service.UpdateContactRequest ): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3299,7 +3748,7 @@ def test_update_contact_rest_bad_request( def test_update_contact_rest_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3341,7 +3790,7 @@ def test_update_contact_rest_flattened(): def test_update_contact_rest_flattened_error(transport: str = "rest"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3357,7 +3806,7 @@ def test_update_contact_rest_flattened_error(transport: str = "rest"): def test_update_contact_rest_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3370,7 +3819,7 @@ def test_update_contact_rest_error(): ) def test_list_contacts_rest(request_type): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3419,7 +3868,7 @@ def test_list_contacts_rest_required_fields(request_type=service.ListContactsReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_contacts._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3428,7 +3877,7 @@ def test_list_contacts_rest_required_fields(request_type=service.ListContactsReq jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_contacts._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3444,7 +3893,7 @@ def test_list_contacts_rest_required_fields(request_type=service.ListContactsReq assert jsonified_request["parent"] == "parent_value" client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3486,7 +3935,7 @@ def test_list_contacts_rest_required_fields(request_type=service.ListContactsReq def test_list_contacts_rest_unset_required_fields(): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_contacts._get_unset_required_fields({}) @@ -3504,7 +3953,7 @@ def test_list_contacts_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_contacts_rest_interceptors(null_interceptor): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EssentialContactsServiceRestInterceptor(), @@ -3560,7 +4009,7 @@ def test_list_contacts_rest_bad_request( transport: str = "rest", request_type=service.ListContactsRequest ): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3582,7 +4031,7 @@ def test_list_contacts_rest_bad_request( def test_list_contacts_rest_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3622,7 +4071,7 @@ def test_list_contacts_rest_flattened(): def test_list_contacts_rest_flattened_error(transport: str = "rest"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3637,7 +4086,7 @@ def test_list_contacts_rest_flattened_error(transport: str = "rest"): def test_list_contacts_rest_pager(transport: str = "rest"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3705,7 +4154,7 @@ def test_list_contacts_rest_pager(transport: str = "rest"): ) def test_get_contact_rest(request_type): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3764,7 +4213,7 @@ def test_get_contact_rest_required_fields(request_type=service.GetContactRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_contact._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3773,7 +4222,7 @@ def test_get_contact_rest_required_fields(request_type=service.GetContactRequest jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_contact._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3782,7 +4231,7 @@ def test_get_contact_rest_required_fields(request_type=service.GetContactRequest assert jsonified_request["name"] == "name_value" client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3824,7 +4273,7 @@ def test_get_contact_rest_required_fields(request_type=service.GetContactRequest def test_get_contact_rest_unset_required_fields(): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_contact._get_unset_required_fields({}) @@ -3834,7 +4283,7 @@ def test_get_contact_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_contact_rest_interceptors(null_interceptor): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EssentialContactsServiceRestInterceptor(), @@ -3888,7 +4337,7 @@ def test_get_contact_rest_bad_request( transport: str = "rest", request_type=service.GetContactRequest ): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3910,7 +4359,7 @@ def test_get_contact_rest_bad_request( def test_get_contact_rest_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3950,7 +4399,7 @@ def test_get_contact_rest_flattened(): def test_get_contact_rest_flattened_error(transport: str = "rest"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3965,7 +4414,7 @@ def test_get_contact_rest_flattened_error(transport: str = "rest"): def test_get_contact_rest_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3978,7 +4427,7 @@ def test_get_contact_rest_error(): ) def test_delete_contact_rest(request_type): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4022,7 +4471,7 @@ def test_delete_contact_rest_required_fields(request_type=service.DeleteContactR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_contact._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4031,7 +4480,7 @@ def test_delete_contact_rest_required_fields(request_type=service.DeleteContactR jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_contact._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4040,7 +4489,7 @@ def test_delete_contact_rest_required_fields(request_type=service.DeleteContactR assert jsonified_request["name"] == "name_value" client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4079,7 +4528,7 @@ def test_delete_contact_rest_required_fields(request_type=service.DeleteContactR def test_delete_contact_rest_unset_required_fields(): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_contact._get_unset_required_fields({}) @@ -4089,7 +4538,7 @@ def test_delete_contact_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_contact_rest_interceptors(null_interceptor): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EssentialContactsServiceRestInterceptor(), @@ -4137,7 +4586,7 @@ def test_delete_contact_rest_bad_request( transport: str = "rest", request_type=service.DeleteContactRequest ): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4159,7 +4608,7 @@ def test_delete_contact_rest_bad_request( def test_delete_contact_rest_flattened(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4197,7 +4646,7 @@ def test_delete_contact_rest_flattened(): def test_delete_contact_rest_flattened_error(transport: str = "rest"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4212,7 +4661,7 @@ def test_delete_contact_rest_flattened_error(transport: str = "rest"): def test_delete_contact_rest_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4225,7 +4674,7 @@ def test_delete_contact_rest_error(): ) def test_compute_contacts_rest(request_type): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4276,7 +4725,7 @@ def test_compute_contacts_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).compute_contacts._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4285,7 +4734,7 @@ def test_compute_contacts_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).compute_contacts._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4302,7 +4751,7 @@ def test_compute_contacts_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4344,7 +4793,7 @@ def test_compute_contacts_rest_required_fields( def test_compute_contacts_rest_unset_required_fields(): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.compute_contacts._get_unset_required_fields({}) @@ -4363,7 +4812,7 @@ def test_compute_contacts_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_compute_contacts_rest_interceptors(null_interceptor): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EssentialContactsServiceRestInterceptor(), @@ -4419,7 +4868,7 @@ def test_compute_contacts_rest_bad_request( transport: str = "rest", request_type=service.ComputeContactsRequest ): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4441,7 +4890,7 @@ def test_compute_contacts_rest_bad_request( def test_compute_contacts_rest_pager(transport: str = "rest"): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4509,7 +4958,7 @@ def test_compute_contacts_rest_pager(transport: str = "rest"): ) def test_send_test_message_rest(request_type): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4556,7 +5005,7 @@ def test_send_test_message_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).send_test_message._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4566,7 +5015,7 @@ def test_send_test_message_rest_required_fields( jsonified_request["resource"] = "resource_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).send_test_message._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4577,7 +5026,7 @@ def test_send_test_message_rest_required_fields( assert jsonified_request["resource"] == "resource_value" client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4617,7 +5066,7 @@ def test_send_test_message_rest_required_fields( def test_send_test_message_rest_unset_required_fields(): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.send_test_message._get_unset_required_fields({}) @@ -4636,7 +5085,7 @@ def test_send_test_message_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_send_test_message_rest_interceptors(null_interceptor): transport = transports.EssentialContactsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EssentialContactsServiceRestInterceptor(), @@ -4684,7 +5133,7 @@ def test_send_test_message_rest_bad_request( transport: str = "rest", request_type=service.SendTestMessageRequest ): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4706,24 +5155,24 @@ def test_send_test_message_rest_bad_request( def test_send_test_message_rest_error(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EssentialContactsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EssentialContactsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EssentialContactsServiceClient( @@ -4733,7 +5182,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EssentialContactsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -4744,16 +5193,17 @@ 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 = EssentialContactsServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EssentialContactsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EssentialContactsServiceClient( @@ -4765,7 +5215,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EssentialContactsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EssentialContactsServiceClient(transport=transport) assert client.transport is transport @@ -4774,13 +5224,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EssentialContactsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EssentialContactsServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -4797,7 +5247,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -4811,7 +5261,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = EssentialContactsServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -4819,7 +5269,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -4831,7 +5281,7 @@ def test_essential_contacts_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EssentialContactsServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -4843,7 +5293,7 @@ def test_essential_contacts_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EssentialContactsServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -4881,7 +5331,7 @@ def test_essential_contacts_service_base_transport_with_credentials_file(): "google.cloud.essential_contacts_v1.services.essential_contacts_service.transports.EssentialContactsServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EssentialContactsServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -4900,7 +5350,7 @@ def test_essential_contacts_service_base_transport_with_adc(): "google.cloud.essential_contacts_v1.services.essential_contacts_service.transports.EssentialContactsServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EssentialContactsServiceTransport() adc.assert_called_once() @@ -4908,7 +5358,7 @@ def test_essential_contacts_service_base_transport_with_adc(): def test_essential_contacts_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EssentialContactsServiceClient() adc.assert_called_once_with( scopes=None, @@ -4928,7 +5378,7 @@ def test_essential_contacts_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -4977,7 +5427,7 @@ def test_essential_contacts_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5007,7 +5457,7 @@ def test_essential_contacts_service_transport_create_channel( def test_essential_contacts_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5045,7 +5495,7 @@ def test_essential_contacts_service_grpc_transport_client_cert_source_for_mtls( def test_essential_contacts_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5065,7 +5515,7 @@ def test_essential_contacts_service_http_transport_client_cert_source_for_mtls() ) def test_essential_contacts_service_host_no_port(transport_name): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="essentialcontacts.googleapis.com" ), @@ -5088,7 +5538,7 @@ def test_essential_contacts_service_host_no_port(transport_name): ) def test_essential_contacts_service_host_with_port(transport_name): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="essentialcontacts.googleapis.com:8000" ), @@ -5108,8 +5558,8 @@ def test_essential_contacts_service_host_with_port(transport_name): ], ) def test_essential_contacts_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EssentialContactsServiceClient( credentials=creds1, transport=transport_name, @@ -5191,7 +5641,7 @@ def test_essential_contacts_service_transport_channel_mtls_with_client_cert_sour mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5400,7 +5850,7 @@ def test_client_with_default_client_info(): transports.EssentialContactsServiceTransport, "_prep_wrapped_messages" ) as prep: client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5410,7 +5860,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EssentialContactsServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -5419,7 +5869,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EssentialContactsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -5438,7 +5888,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -5455,7 +5905,7 @@ def test_client_ctx(): ] for transport in transports: client = EssentialContactsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -5492,7 +5942,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, diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing/gapic_version.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing/gapic_version.py index 7257802240c5..360a0d13ebdd 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing/gapic_version.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.6.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/gapic_version.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/gapic_version.py index 7257802240c5..360a0d13ebdd 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/gapic_version.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.6.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/async_client.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/async_client.py index 36dd60c151ad..f15ca5c28799 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/async_client.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/async_client.py @@ -38,9 +38,9 @@ from google.cloud.eventarc_publishing_v1 import gapic_version as package_version 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.eventarc_publishing_v1.types import publisher @@ -82,8 +82,12 @@ class PublisherAsyncClient: _client: PublisherClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = PublisherClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = PublisherClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = PublisherClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = PublisherClient._DEFAULT_UNIVERSE common_billing_account_path = staticmethod( PublisherClient.common_billing_account_path @@ -182,6 +186,25 @@ def transport(self) -> PublisherTransport: """ 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(PublisherClient).get_transport_class, type(PublisherClient) ) @@ -194,7 +217,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the publisher client. + """Instantiates the publisher async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -205,23 +228,38 @@ def __init__( transport (Union[str, ~.PublisherTransport]): 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. @@ -306,6 +344,9 @@ async def sample_publish_channel_connection_events(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -385,6 +426,9 @@ async def sample_publish_events(): gapic_v1.routing_header.to_grpc_metadata((("channel", request.channel),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/client.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/client.py index 17d4564911b2..4158689be03e 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/client.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.eventarc_publishing_v1 import gapic_version as package_version 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.eventarc_publishing_v1.types import publisher @@ -150,11 +151,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 = "eventarcpublishing.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "eventarcpublishing.{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 @@ -283,7 +288,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 @@ -313,6 +318,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") @@ -346,6 +356,175 @@ 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 + + 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 + + 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 = PublisherClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = PublisherClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = PublisherClient._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 = PublisherClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = PublisherClient._DEFAULT_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 PublisherClient._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, *, @@ -365,22 +544,32 @@ def __init__( transport (Union[str, PublisherTransport]): 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. @@ -391,17 +580,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = PublisherClient._read_environment_variables() + self._client_cert_source = PublisherClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = PublisherClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -410,20 +616,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, PublisherTransport): + transport_provided = isinstance(transport, PublisherTransport) + if transport_provided: # transport is a PublisherTransport 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(PublisherTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or PublisherClient._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( @@ -433,17 +649,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 publish_channel_connection_events( @@ -522,6 +738,9 @@ def sample_publish_channel_connection_events(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -602,6 +821,9 @@ def sample_publish_events(): gapic_v1.routing_header.to_grpc_metadata((("channel", request.channel),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/base.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/base.py index a6c874436f89..a3c76577baf1 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/base.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/base.py @@ -56,7 +56,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'eventarcpublishing.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 @@ -119,6 +119,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-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc.py index 216a85d6453b..bf0978b5e2e2 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc.py @@ -90,7 +90,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'eventarcpublishing.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-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc_asyncio.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc_asyncio.py index 9271e75c0a05..3b6f828b1a79 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc_asyncio.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/grpc_asyncio.py @@ -135,7 +135,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'eventarcpublishing.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-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/rest.py b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/rest.py index d4f9b5eb19c2..e8bff6ac340b 100644 --- a/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/rest.py +++ b/packages/google-cloud-eventarc-publishing/google/cloud/eventarc_publishing_v1/services/publisher/transports/rest.py @@ -31,9 +31,9 @@ from requests import __version__ as requests_version 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.eventarc_publishing_v1.types import publisher @@ -200,7 +200,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'eventarcpublishing.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-eventarc-publishing/noxfile.py b/packages/google-cloud-eventarc-publishing/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-eventarc-publishing/noxfile.py +++ b/packages/google-cloud-eventarc-publishing/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-eventarc-publishing/samples/generated_samples/snippet_metadata_google.cloud.eventarc.publishing.v1.json b/packages/google-cloud-eventarc-publishing/samples/generated_samples/snippet_metadata_google.cloud.eventarc.publishing.v1.json index 0367b9bec588..315310cec9dd 100644 --- a/packages/google-cloud-eventarc-publishing/samples/generated_samples/snippet_metadata_google.cloud.eventarc.publishing.v1.json +++ b/packages/google-cloud-eventarc-publishing/samples/generated_samples/snippet_metadata_google.cloud.eventarc.publishing.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-eventarc-publishing", - "version": "0.6.5" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-eventarc-publishing/tests/unit/gapic/eventarc_publishing_v1/test_publisher.py b/packages/google-cloud-eventarc-publishing/tests/unit/gapic/eventarc_publishing_v1/test_publisher.py index 10c4044302c6..cfb73c0eeeac 100644 --- a/packages/google-cloud-eventarc-publishing/tests/unit/gapic/eventarc_publishing_v1/test_publisher.py +++ b/packages/google-cloud-eventarc-publishing/tests/unit/gapic/eventarc_publishing_v1/test_publisher.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -66,6 +66,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -90,6 +113,247 @@ def test__get_default_mtls_endpoint(): assert PublisherClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert PublisherClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert PublisherClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert PublisherClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + PublisherClient._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 PublisherClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert PublisherClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert PublisherClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + PublisherClient._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 PublisherClient._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 PublisherClient._get_client_cert_source(None, False) is None + assert ( + PublisherClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + PublisherClient._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 ( + PublisherClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + PublisherClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + PublisherClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PublisherClient), +) +@mock.patch.object( + PublisherAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PublisherAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = PublisherClient._DEFAULT_UNIVERSE + default_endpoint = PublisherClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = PublisherClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + PublisherClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + PublisherClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == PublisherClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + PublisherClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + PublisherClient._get_api_endpoint(None, None, default_universe, "always") + == PublisherClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + PublisherClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == PublisherClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + PublisherClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + PublisherClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + PublisherClient._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 ( + PublisherClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + PublisherClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + PublisherClient._get_universe_domain(None, None) + == PublisherClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + PublisherClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (PublisherClient, transports.PublisherGrpcTransport, "grpc"), + (PublisherClient, transports.PublisherRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -99,7 +363,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_publisher_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -151,7 +415,7 @@ def test_publisher_client_service_account_always_use_jwt( ], ) def test_publisher_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -200,17 +464,21 @@ def test_publisher_client_get_transport_class(): ], ) @mock.patch.object( - PublisherClient, "DEFAULT_ENDPOINT", modify_default_endpoint(PublisherClient) + PublisherClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PublisherClient), ) @mock.patch.object( PublisherAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(PublisherAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PublisherAsyncClient), ) def test_publisher_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(PublisherClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -245,7 +513,9 @@ def test_publisher_client_client_options(client_class, transport_class, transpor 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, @@ -275,15 +545,23 @@ def test_publisher_client_client_options(client_class, transport_class, transpor # 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") @@ -293,7 +571,9 @@ def test_publisher_client_client_options(client_class, transport_class, transpor 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", @@ -311,7 +591,9 @@ def test_publisher_client_client_options(client_class, transport_class, transpor 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, @@ -343,12 +625,14 @@ def test_publisher_client_client_options(client_class, transport_class, transpor ], ) @mock.patch.object( - PublisherClient, "DEFAULT_ENDPOINT", modify_default_endpoint(PublisherClient) + PublisherClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PublisherClient), ) @mock.patch.object( PublisherAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(PublisherAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PublisherAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_publisher_client_mtls_env_auto( @@ -371,7 +655,9 @@ def test_publisher_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 @@ -403,7 +689,9 @@ def test_publisher_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 @@ -437,7 +725,9 @@ def test_publisher_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, @@ -523,6 +813,116 @@ def test_publisher_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", [PublisherClient, PublisherAsyncClient]) +@mock.patch.object( + PublisherClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PublisherClient), +) +@mock.patch.object( + PublisherAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PublisherAsyncClient), +) +def test_publisher_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = PublisherClient._DEFAULT_UNIVERSE + default_endpoint = PublisherClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = PublisherClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -549,7 +949,9 @@ def test_publisher_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, @@ -584,7 +986,9 @@ def test_publisher_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, @@ -637,7 +1041,9 @@ def test_publisher_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, @@ -654,8 +1060,8 @@ def test_publisher_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -684,7 +1090,7 @@ def test_publisher_client_create_channel_credentials_file( ) def test_publish_channel_connection_events(request_type, transport: str = "grpc"): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -713,7 +1119,7 @@ def test_publish_channel_connection_events_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -733,7 +1139,7 @@ async def test_publish_channel_connection_events_async( request_type=publisher.PublishChannelConnectionEventsRequest, ): client = PublisherAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -767,7 +1173,7 @@ async def test_publish_channel_connection_events_async_from_dict(): def test_publish_channel_connection_events_field_headers(): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -799,7 +1205,7 @@ def test_publish_channel_connection_events_field_headers(): @pytest.mark.asyncio async def test_publish_channel_connection_events_field_headers_async(): client = PublisherAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -839,7 +1245,7 @@ async def test_publish_channel_connection_events_field_headers_async(): ) def test_publish_events(request_type, transport: str = "grpc"): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -866,7 +1272,7 @@ def test_publish_events_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -883,7 +1289,7 @@ async def test_publish_events_async( transport: str = "grpc_asyncio", request_type=publisher.PublishEventsRequest ): client = PublisherAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -915,7 +1321,7 @@ async def test_publish_events_async_from_dict(): def test_publish_events_field_headers(): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -945,7 +1351,7 @@ def test_publish_events_field_headers(): @pytest.mark.asyncio async def test_publish_events_field_headers_async(): client = PublisherAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -983,7 +1389,7 @@ async def test_publish_events_field_headers_async(): ) def test_publish_channel_connection_events_rest(request_type): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1016,7 +1422,7 @@ def test_publish_channel_connection_events_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_publish_channel_connection_events_rest_interceptors(null_interceptor): transport = transports.PublisherRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.PublisherRestInterceptor(), ) client = PublisherClient(transport=transport) @@ -1075,7 +1481,7 @@ def test_publish_channel_connection_events_rest_bad_request( request_type=publisher.PublishChannelConnectionEventsRequest, ): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1099,7 +1505,7 @@ def test_publish_channel_connection_events_rest_bad_request( def test_publish_channel_connection_events_rest_error(): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -1112,7 +1518,7 @@ def test_publish_channel_connection_events_rest_error(): ) def test_publish_events_rest(request_type): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1143,7 +1549,7 @@ def test_publish_events_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_publish_events_rest_interceptors(null_interceptor): transport = transports.PublisherRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.PublisherRestInterceptor(), ) client = PublisherClient(transport=transport) @@ -1197,7 +1603,7 @@ def test_publish_events_rest_bad_request( transport: str = "rest", request_type=publisher.PublishEventsRequest ): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1219,24 +1625,24 @@ def test_publish_events_rest_bad_request( def test_publish_events_rest_error(): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.PublisherGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.PublisherGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = PublisherClient( @@ -1246,7 +1652,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.PublisherGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1257,16 +1663,17 @@ 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 = PublisherClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.PublisherGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = PublisherClient( @@ -1278,7 +1685,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.PublisherGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = PublisherClient(transport=transport) assert client.transport is transport @@ -1287,13 +1694,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.PublisherGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.PublisherGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1310,7 +1717,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1324,7 +1731,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = PublisherClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1332,7 +1739,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1344,7 +1751,7 @@ def test_publisher_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.PublisherTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1356,7 +1763,7 @@ def test_publisher_base_transport(): ) as Transport: Transport.return_value = None transport = transports.PublisherTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1389,7 +1796,7 @@ def test_publisher_base_transport_with_credentials_file(): "google.cloud.eventarc_publishing_v1.services.publisher.transports.PublisherTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.PublisherTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1408,7 +1815,7 @@ def test_publisher_base_transport_with_adc(): "google.cloud.eventarc_publishing_v1.services.publisher.transports.PublisherTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.PublisherTransport() adc.assert_called_once() @@ -1416,7 +1823,7 @@ def test_publisher_base_transport_with_adc(): def test_publisher_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) PublisherClient() adc.assert_called_once_with( scopes=None, @@ -1436,7 +1843,7 @@ def test_publisher_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1483,7 +1890,7 @@ def test_publisher_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1508,7 +1915,7 @@ def test_publisher_transport_create_channel(transport_class, grpc_helpers): [transports.PublisherGrpcTransport, transports.PublisherGrpcAsyncIOTransport], ) def test_publisher_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1546,7 +1953,7 @@ def test_publisher_grpc_transport_client_cert_source_for_mtls(transport_class): def test_publisher_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -1566,7 +1973,7 @@ def test_publisher_http_transport_client_cert_source_for_mtls(): ) def test_publisher_host_no_port(transport_name): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="eventarcpublishing.googleapis.com" ), @@ -1589,7 +1996,7 @@ def test_publisher_host_no_port(transport_name): ) def test_publisher_host_with_port(transport_name): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="eventarcpublishing.googleapis.com:8000" ), @@ -1609,8 +2016,8 @@ def test_publisher_host_with_port(transport_name): ], ) def test_publisher_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = PublisherClient( credentials=creds1, transport=transport_name, @@ -1672,7 +2079,7 @@ def test_publisher_transport_channel_mtls_with_client_cert_source(transport_clas mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -1855,7 +2262,7 @@ def test_client_with_default_client_info(): transports.PublisherTransport, "_prep_wrapped_messages" ) as prep: client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1865,7 +2272,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = PublisherClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1874,7 +2281,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = PublisherAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -1893,7 +2300,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -1910,7 +2317,7 @@ def test_client_ctx(): ] for transport in transports: client = PublisherClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -1941,7 +2348,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, diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc/gapic_version.py b/packages/google-cloud-eventarc/google/cloud/eventarc/gapic_version.py index 0611530e449b..360a0d13ebdd 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc/gapic_version.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.10.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/gapic_version.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/gapic_version.py index 0611530e449b..360a0d13ebdd 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/gapic_version.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.10.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py index abe531d58d16..8fc119bb8639 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py @@ -38,9 +38,9 @@ from google.cloud.eventarc_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -77,8 +77,12 @@ class EventarcAsyncClient: _client: EventarcClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = EventarcClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = EventarcClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = EventarcClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = EventarcClient._DEFAULT_UNIVERSE channel_path = staticmethod(EventarcClient.channel_path) parse_channel_path = staticmethod(EventarcClient.parse_channel_path) @@ -199,6 +203,25 @@ def transport(self) -> EventarcTransport: """ 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(EventarcClient).get_transport_class, type(EventarcClient) ) @@ -211,7 +234,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the eventarc client. + """Instantiates the eventarc async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -222,23 +245,38 @@ def __init__( transport (Union[str, ~.EventarcTransport]): 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. @@ -341,6 +379,9 @@ async def sample_get_trigger(): 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, @@ -446,6 +487,9 @@ async def sample_list_triggers(): 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, @@ -593,6 +637,9 @@ async def sample_create_trigger(): 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, @@ -733,6 +780,9 @@ async def sample_update_trigger(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -862,6 +912,9 @@ async def sample_delete_trigger(): 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, @@ -978,6 +1031,9 @@ async def sample_get_channel(): 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, @@ -1083,6 +1139,9 @@ async def sample_list_channels(): 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, @@ -1230,6 +1289,9 @@ async def sample_create_channel(): 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, @@ -1362,6 +1424,9 @@ async def sample_update_channel(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1483,6 +1548,9 @@ async def sample_delete_channel(): 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, @@ -1593,6 +1661,9 @@ async def sample_get_provider(): 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, @@ -1698,6 +1769,9 @@ async def sample_list_providers(): 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, @@ -1814,6 +1888,9 @@ async def sample_get_channel_connection(): 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, @@ -1920,6 +1997,9 @@ async def sample_list_channel_connections(): 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, @@ -2067,6 +2147,9 @@ async def sample_create_channel_connection(): 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, @@ -2186,6 +2269,9 @@ async def sample_delete_channel_connection(): 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, @@ -2302,6 +2388,9 @@ async def sample_get_google_channel_config(): 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, @@ -2429,6 +2518,9 @@ async def sample_update_google_channel_config(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2483,6 +2575,9 @@ async def list_operations( 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, @@ -2537,6 +2632,9 @@ async def get_operation( 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, @@ -2595,6 +2693,9 @@ async def delete_operation( 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, @@ -2649,6 +2750,9 @@ async def cancel_operation( 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, @@ -2766,6 +2870,9 @@ async def set_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2887,6 +2994,9 @@ async def get_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2946,6 +3056,9 @@ async def test_iam_permissions( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -3000,6 +3113,9 @@ async def get_location( 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, @@ -3054,6 +3170,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/client.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/client.py index 8d6197371cdb..9632e9afb20a 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/client.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.eventarc_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -145,11 +146,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 = "eventarc.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "eventarc.{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 @@ -485,7 +490,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 @@ -515,6 +520,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") @@ -548,6 +558,175 @@ 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 + + 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 + + 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 = EventarcClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = EventarcClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = EventarcClient._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 = EventarcClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = EventarcClient._DEFAULT_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 EventarcClient._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, *, @@ -567,22 +746,32 @@ def __init__( transport (Union[str, EventarcTransport]): 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. @@ -593,17 +782,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = EventarcClient._read_environment_variables() + self._client_cert_source = EventarcClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = EventarcClient._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" @@ -612,20 +818,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, EventarcTransport): + transport_provided = isinstance(transport, EventarcTransport) + if transport_provided: # transport is a EventarcTransport 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(EventarcTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or EventarcClient._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( @@ -635,17 +851,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 get_trigger( @@ -739,6 +955,9 @@ def sample_get_trigger(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -844,6 +1063,9 @@ def sample_list_triggers(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -991,6 +1213,9 @@ def sample_create_trigger(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1131,6 +1356,9 @@ def sample_update_trigger(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1260,6 +1488,9 @@ def sample_delete_trigger(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1376,6 +1607,9 @@ def sample_get_channel(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1481,6 +1715,9 @@ def sample_list_channels(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1628,6 +1865,9 @@ def sample_create_channel(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1760,6 +2000,9 @@ def sample_update_channel(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1881,6 +2124,9 @@ def sample_delete_channel(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1991,6 +2237,9 @@ def sample_get_provider(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2096,6 +2345,9 @@ def sample_list_providers(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2212,6 +2464,9 @@ def sample_get_channel_connection(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2318,6 +2573,9 @@ def sample_list_channel_connections(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2467,6 +2725,9 @@ def sample_create_channel_connection(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2588,6 +2849,9 @@ def sample_delete_channel_connection(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2706,6 +2970,9 @@ def sample_get_google_channel_config(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2835,6 +3102,9 @@ def sample_update_google_channel_config(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2902,6 +3172,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2956,6 +3229,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3014,6 +3290,9 @@ def delete_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3068,6 +3347,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3185,6 +3467,9 @@ def set_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3306,6 +3591,9 @@ def get_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3365,6 +3653,9 @@ def test_iam_permissions( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3419,6 +3710,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3473,6 +3767,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py index a97279a7a059..ae8043cf86cf 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py @@ -70,7 +70,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'eventarc.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 @@ -133,6 +133,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-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py index 894496f22a5b..027b6a4b2d4b 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py @@ -79,7 +79,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'eventarc.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-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py index ea03b0af0b6d..5ff539471bc3 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py @@ -124,7 +124,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'eventarc.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-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/rest.py b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/rest.py index bf1d536c9d24..2e1a29a56d06 100644 --- a/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/rest.py +++ b/packages/google-cloud-eventarc/google/cloud/eventarc_v1/services/eventarc/transports/rest.py @@ -40,9 +40,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -873,7 +873,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'eventarc.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-eventarc/noxfile.py b/packages/google-cloud-eventarc/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-eventarc/noxfile.py +++ b/packages/google-cloud-eventarc/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-eventarc/samples/generated_samples/snippet_metadata_google.cloud.eventarc.v1.json b/packages/google-cloud-eventarc/samples/generated_samples/snippet_metadata_google.cloud.eventarc.v1.json index 521276ad7883..596aaecb1b9c 100644 --- a/packages/google-cloud-eventarc/samples/generated_samples/snippet_metadata_google.cloud.eventarc.v1.json +++ b/packages/google-cloud-eventarc/samples/generated_samples/snippet_metadata_google.cloud.eventarc.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-eventarc", - "version": "1.10.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py b/packages/google-cloud-eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py index 8bf1bcd123ef..0196e54a8e2a 100644 --- a/packages/google-cloud-eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py +++ b/packages/google-cloud-eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -93,6 +93,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -117,6 +140,244 @@ def test__get_default_mtls_endpoint(): assert EventarcClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert EventarcClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert EventarcClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert EventarcClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + EventarcClient._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 EventarcClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert EventarcClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert EventarcClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + EventarcClient._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 EventarcClient._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 EventarcClient._get_client_cert_source(None, False) is None + assert ( + EventarcClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + EventarcClient._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 ( + EventarcClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + EventarcClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + EventarcClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EventarcClient), +) +@mock.patch.object( + EventarcAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EventarcAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = EventarcClient._DEFAULT_UNIVERSE + default_endpoint = EventarcClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EventarcClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + EventarcClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + EventarcClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == EventarcClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EventarcClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + EventarcClient._get_api_endpoint(None, None, default_universe, "always") + == EventarcClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EventarcClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == EventarcClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + EventarcClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + EventarcClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + EventarcClient._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 ( + EventarcClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + EventarcClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + EventarcClient._get_universe_domain(None, None) + == EventarcClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + EventarcClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (EventarcClient, transports.EventarcGrpcTransport, "grpc"), + (EventarcClient, transports.EventarcRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -126,7 +387,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_eventarc_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -178,7 +439,7 @@ def test_eventarc_client_service_account_always_use_jwt( ], ) def test_eventarc_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -223,17 +484,21 @@ def test_eventarc_client_get_transport_class(): ], ) @mock.patch.object( - EventarcClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EventarcClient) + EventarcClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EventarcClient), ) @mock.patch.object( EventarcAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EventarcAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EventarcAsyncClient), ) def test_eventarc_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(EventarcClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -268,7 +533,9 @@ def test_eventarc_client_client_options(client_class, transport_class, transport 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, @@ -298,15 +565,23 @@ def test_eventarc_client_client_options(client_class, transport_class, transport # 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") @@ -316,7 +591,9 @@ def test_eventarc_client_client_options(client_class, transport_class, transport 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", @@ -334,7 +611,9 @@ def test_eventarc_client_client_options(client_class, transport_class, transport 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, @@ -366,12 +645,14 @@ def test_eventarc_client_client_options(client_class, transport_class, transport ], ) @mock.patch.object( - EventarcClient, "DEFAULT_ENDPOINT", modify_default_endpoint(EventarcClient) + EventarcClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EventarcClient), ) @mock.patch.object( EventarcAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(EventarcAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EventarcAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_eventarc_client_mtls_env_auto( @@ -394,7 +675,9 @@ def test_eventarc_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 @@ -426,7 +709,9 @@ def test_eventarc_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 @@ -460,7 +745,9 @@ def test_eventarc_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, @@ -546,6 +833,116 @@ def test_eventarc_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", [EventarcClient, EventarcAsyncClient]) +@mock.patch.object( + EventarcClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EventarcClient), +) +@mock.patch.object( + EventarcAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(EventarcAsyncClient), +) +def test_eventarc_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = EventarcClient._DEFAULT_UNIVERSE + default_endpoint = EventarcClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = EventarcClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -568,7 +965,9 @@ def test_eventarc_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, @@ -603,7 +1002,9 @@ def test_eventarc_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, @@ -656,7 +1057,9 @@ def test_eventarc_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, @@ -673,8 +1076,8 @@ def test_eventarc_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -703,7 +1106,7 @@ def test_eventarc_client_create_channel_credentials_file( ) def test_get_trigger(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -741,7 +1144,7 @@ def test_get_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -758,7 +1161,7 @@ async def test_get_trigger_async( transport: str = "grpc_asyncio", request_type=eventarc.GetTriggerRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -801,7 +1204,7 @@ async def test_get_trigger_async_from_dict(): def test_get_trigger_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -831,7 +1234,7 @@ def test_get_trigger_field_headers(): @pytest.mark.asyncio async def test_get_trigger_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -860,7 +1263,7 @@ async def test_get_trigger_field_headers_async(): def test_get_trigger_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -884,7 +1287,7 @@ def test_get_trigger_flattened(): def test_get_trigger_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -899,7 +1302,7 @@ def test_get_trigger_flattened_error(): @pytest.mark.asyncio async def test_get_trigger_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -926,7 +1329,7 @@ async def test_get_trigger_flattened_async(): @pytest.mark.asyncio async def test_get_trigger_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -947,7 +1350,7 @@ async def test_get_trigger_flattened_error_async(): ) def test_list_triggers(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -979,7 +1382,7 @@ def test_list_triggers_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -996,7 +1399,7 @@ async def test_list_triggers_async( transport: str = "grpc_asyncio", request_type=eventarc.ListTriggersRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1033,7 +1436,7 @@ async def test_list_triggers_async_from_dict(): def test_list_triggers_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1063,7 +1466,7 @@ def test_list_triggers_field_headers(): @pytest.mark.asyncio async def test_list_triggers_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1094,7 +1497,7 @@ async def test_list_triggers_field_headers_async(): def test_list_triggers_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1118,7 +1521,7 @@ def test_list_triggers_flattened(): def test_list_triggers_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1133,7 +1536,7 @@ def test_list_triggers_flattened_error(): @pytest.mark.asyncio async def test_list_triggers_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1162,7 +1565,7 @@ async def test_list_triggers_flattened_async(): @pytest.mark.asyncio async def test_list_triggers_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1176,7 +1579,7 @@ async def test_list_triggers_flattened_error_async(): def test_list_triggers_pager(transport_name: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1226,7 +1629,7 @@ def test_list_triggers_pager(transport_name: str = "grpc"): def test_list_triggers_pages(transport_name: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1268,7 +1671,7 @@ def test_list_triggers_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_triggers_async_pager(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1318,7 +1721,7 @@ async def test_list_triggers_async_pager(): @pytest.mark.asyncio async def test_list_triggers_async_pages(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1373,7 +1776,7 @@ async def test_list_triggers_async_pages(): ) def test_create_trigger(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1400,7 +1803,7 @@ def test_create_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1417,7 +1820,7 @@ async def test_create_trigger_async( transport: str = "grpc_asyncio", request_type=eventarc.CreateTriggerRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1449,7 +1852,7 @@ async def test_create_trigger_async_from_dict(): def test_create_trigger_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1479,7 +1882,7 @@ def test_create_trigger_field_headers(): @pytest.mark.asyncio async def test_create_trigger_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1510,7 +1913,7 @@ async def test_create_trigger_field_headers_async(): def test_create_trigger_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1542,7 +1945,7 @@ def test_create_trigger_flattened(): def test_create_trigger_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1559,7 +1962,7 @@ def test_create_trigger_flattened_error(): @pytest.mark.asyncio async def test_create_trigger_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1596,7 +1999,7 @@ async def test_create_trigger_flattened_async(): @pytest.mark.asyncio async def test_create_trigger_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1619,7 +2022,7 @@ async def test_create_trigger_flattened_error_async(): ) def test_update_trigger(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1646,7 +2049,7 @@ def test_update_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1663,7 +2066,7 @@ async def test_update_trigger_async( transport: str = "grpc_asyncio", request_type=eventarc.UpdateTriggerRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1695,7 +2098,7 @@ async def test_update_trigger_async_from_dict(): def test_update_trigger_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1725,7 +2128,7 @@ def test_update_trigger_field_headers(): @pytest.mark.asyncio async def test_update_trigger_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1756,7 +2159,7 @@ async def test_update_trigger_field_headers_async(): def test_update_trigger_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1788,7 +2191,7 @@ def test_update_trigger_flattened(): def test_update_trigger_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1805,7 +2208,7 @@ def test_update_trigger_flattened_error(): @pytest.mark.asyncio async def test_update_trigger_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1842,7 +2245,7 @@ async def test_update_trigger_flattened_async(): @pytest.mark.asyncio async def test_update_trigger_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1865,7 +2268,7 @@ async def test_update_trigger_flattened_error_async(): ) def test_delete_trigger(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1892,7 +2295,7 @@ def test_delete_trigger_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1909,7 +2312,7 @@ async def test_delete_trigger_async( transport: str = "grpc_asyncio", request_type=eventarc.DeleteTriggerRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1941,7 +2344,7 @@ async def test_delete_trigger_async_from_dict(): def test_delete_trigger_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1971,7 +2374,7 @@ def test_delete_trigger_field_headers(): @pytest.mark.asyncio async def test_delete_trigger_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2002,7 +2405,7 @@ async def test_delete_trigger_field_headers_async(): def test_delete_trigger_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2030,7 +2433,7 @@ def test_delete_trigger_flattened(): def test_delete_trigger_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2046,7 +2449,7 @@ def test_delete_trigger_flattened_error(): @pytest.mark.asyncio async def test_delete_trigger_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2079,7 +2482,7 @@ async def test_delete_trigger_flattened_async(): @pytest.mark.asyncio async def test_delete_trigger_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2101,7 +2504,7 @@ async def test_delete_trigger_flattened_error_async(): ) def test_get_channel(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2142,7 +2545,7 @@ def test_get_channel_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2159,7 +2562,7 @@ async def test_get_channel_async( transport: str = "grpc_asyncio", request_type=eventarc.GetChannelRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2204,7 +2607,7 @@ async def test_get_channel_async_from_dict(): def test_get_channel_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2234,7 +2637,7 @@ def test_get_channel_field_headers(): @pytest.mark.asyncio async def test_get_channel_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2263,7 +2666,7 @@ async def test_get_channel_field_headers_async(): def test_get_channel_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2287,7 +2690,7 @@ def test_get_channel_flattened(): def test_get_channel_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2302,7 +2705,7 @@ def test_get_channel_flattened_error(): @pytest.mark.asyncio async def test_get_channel_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2329,7 +2732,7 @@ async def test_get_channel_flattened_async(): @pytest.mark.asyncio async def test_get_channel_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2350,7 +2753,7 @@ async def test_get_channel_flattened_error_async(): ) def test_list_channels(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2382,7 +2785,7 @@ def test_list_channels_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2399,7 +2802,7 @@ async def test_list_channels_async( transport: str = "grpc_asyncio", request_type=eventarc.ListChannelsRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2436,7 +2839,7 @@ async def test_list_channels_async_from_dict(): def test_list_channels_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2466,7 +2869,7 @@ def test_list_channels_field_headers(): @pytest.mark.asyncio async def test_list_channels_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2497,7 +2900,7 @@ async def test_list_channels_field_headers_async(): def test_list_channels_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2521,7 +2924,7 @@ def test_list_channels_flattened(): def test_list_channels_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2536,7 +2939,7 @@ def test_list_channels_flattened_error(): @pytest.mark.asyncio async def test_list_channels_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2565,7 +2968,7 @@ async def test_list_channels_flattened_async(): @pytest.mark.asyncio async def test_list_channels_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2579,7 +2982,7 @@ async def test_list_channels_flattened_error_async(): def test_list_channels_pager(transport_name: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2629,7 +3032,7 @@ def test_list_channels_pager(transport_name: str = "grpc"): def test_list_channels_pages(transport_name: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2671,7 +3074,7 @@ def test_list_channels_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_channels_async_pager(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2721,7 +3124,7 @@ async def test_list_channels_async_pager(): @pytest.mark.asyncio async def test_list_channels_async_pages(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2776,7 +3179,7 @@ async def test_list_channels_async_pages(): ) def test_create_channel(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2803,7 +3206,7 @@ def test_create_channel_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2820,7 +3223,7 @@ async def test_create_channel_async( transport: str = "grpc_asyncio", request_type=eventarc.CreateChannelRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2852,7 +3255,7 @@ async def test_create_channel_async_from_dict(): def test_create_channel_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2882,7 +3285,7 @@ def test_create_channel_field_headers(): @pytest.mark.asyncio async def test_create_channel_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2913,7 +3316,7 @@ async def test_create_channel_field_headers_async(): def test_create_channel_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2945,7 +3348,7 @@ def test_create_channel_flattened(): def test_create_channel_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2962,7 +3365,7 @@ def test_create_channel_flattened_error(): @pytest.mark.asyncio async def test_create_channel_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2999,7 +3402,7 @@ async def test_create_channel_flattened_async(): @pytest.mark.asyncio async def test_create_channel_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3022,7 +3425,7 @@ async def test_create_channel_flattened_error_async(): ) def test_update_channel(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3049,7 +3452,7 @@ def test_update_channel_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3066,7 +3469,7 @@ async def test_update_channel_async( transport: str = "grpc_asyncio", request_type=eventarc.UpdateChannelRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3098,7 +3501,7 @@ async def test_update_channel_async_from_dict(): def test_update_channel_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3128,7 +3531,7 @@ def test_update_channel_field_headers(): @pytest.mark.asyncio async def test_update_channel_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3159,7 +3562,7 @@ async def test_update_channel_field_headers_async(): def test_update_channel_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3187,7 +3590,7 @@ def test_update_channel_flattened(): def test_update_channel_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3203,7 +3606,7 @@ def test_update_channel_flattened_error(): @pytest.mark.asyncio async def test_update_channel_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3236,7 +3639,7 @@ async def test_update_channel_flattened_async(): @pytest.mark.asyncio async def test_update_channel_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3258,7 +3661,7 @@ async def test_update_channel_flattened_error_async(): ) def test_delete_channel(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3285,7 +3688,7 @@ def test_delete_channel_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3302,7 +3705,7 @@ async def test_delete_channel_async( transport: str = "grpc_asyncio", request_type=eventarc.DeleteChannelRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3334,7 +3737,7 @@ async def test_delete_channel_async_from_dict(): def test_delete_channel_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3364,7 +3767,7 @@ def test_delete_channel_field_headers(): @pytest.mark.asyncio async def test_delete_channel_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3395,7 +3798,7 @@ async def test_delete_channel_field_headers_async(): def test_delete_channel_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3419,7 +3822,7 @@ def test_delete_channel_flattened(): def test_delete_channel_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3434,7 +3837,7 @@ def test_delete_channel_flattened_error(): @pytest.mark.asyncio async def test_delete_channel_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3463,7 +3866,7 @@ async def test_delete_channel_flattened_async(): @pytest.mark.asyncio async def test_delete_channel_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3484,7 +3887,7 @@ async def test_delete_channel_flattened_error_async(): ) def test_get_provider(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3516,7 +3919,7 @@ def test_get_provider_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3533,7 +3936,7 @@ async def test_get_provider_async( transport: str = "grpc_asyncio", request_type=eventarc.GetProviderRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3570,7 +3973,7 @@ async def test_get_provider_async_from_dict(): def test_get_provider_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3600,7 +4003,7 @@ def test_get_provider_field_headers(): @pytest.mark.asyncio async def test_get_provider_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3629,7 +4032,7 @@ async def test_get_provider_field_headers_async(): def test_get_provider_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3653,7 +4056,7 @@ def test_get_provider_flattened(): def test_get_provider_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3668,7 +4071,7 @@ def test_get_provider_flattened_error(): @pytest.mark.asyncio async def test_get_provider_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3695,7 +4098,7 @@ async def test_get_provider_flattened_async(): @pytest.mark.asyncio async def test_get_provider_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3716,7 +4119,7 @@ async def test_get_provider_flattened_error_async(): ) def test_list_providers(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3748,7 +4151,7 @@ def test_list_providers_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3765,7 +4168,7 @@ async def test_list_providers_async( transport: str = "grpc_asyncio", request_type=eventarc.ListProvidersRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3802,7 +4205,7 @@ async def test_list_providers_async_from_dict(): def test_list_providers_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3832,7 +4235,7 @@ def test_list_providers_field_headers(): @pytest.mark.asyncio async def test_list_providers_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3863,7 +4266,7 @@ async def test_list_providers_field_headers_async(): def test_list_providers_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3887,7 +4290,7 @@ def test_list_providers_flattened(): def test_list_providers_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3902,7 +4305,7 @@ def test_list_providers_flattened_error(): @pytest.mark.asyncio async def test_list_providers_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3931,7 +4334,7 @@ async def test_list_providers_flattened_async(): @pytest.mark.asyncio async def test_list_providers_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3945,7 +4348,7 @@ async def test_list_providers_flattened_error_async(): def test_list_providers_pager(transport_name: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3995,7 +4398,7 @@ def test_list_providers_pager(transport_name: str = "grpc"): def test_list_providers_pages(transport_name: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4037,7 +4440,7 @@ def test_list_providers_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_providers_async_pager(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4087,7 +4490,7 @@ async def test_list_providers_async_pager(): @pytest.mark.asyncio async def test_list_providers_async_pages(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4142,7 +4545,7 @@ async def test_list_providers_async_pages(): ) def test_get_channel_connection(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4180,7 +4583,7 @@ def test_get_channel_connection_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4199,7 +4602,7 @@ async def test_get_channel_connection_async( transport: str = "grpc_asyncio", request_type=eventarc.GetChannelConnectionRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4242,7 +4645,7 @@ async def test_get_channel_connection_async_from_dict(): def test_get_channel_connection_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4274,7 +4677,7 @@ def test_get_channel_connection_field_headers(): @pytest.mark.asyncio async def test_get_channel_connection_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4307,7 +4710,7 @@ async def test_get_channel_connection_field_headers_async(): def test_get_channel_connection_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4333,7 +4736,7 @@ def test_get_channel_connection_flattened(): def test_get_channel_connection_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4348,7 +4751,7 @@ def test_get_channel_connection_flattened_error(): @pytest.mark.asyncio async def test_get_channel_connection_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4379,7 +4782,7 @@ async def test_get_channel_connection_flattened_async(): @pytest.mark.asyncio async def test_get_channel_connection_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4400,7 +4803,7 @@ async def test_get_channel_connection_flattened_error_async(): ) def test_list_channel_connections(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4434,7 +4837,7 @@ def test_list_channel_connections_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4453,7 +4856,7 @@ async def test_list_channel_connections_async( transport: str = "grpc_asyncio", request_type=eventarc.ListChannelConnectionsRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4492,7 +4895,7 @@ async def test_list_channel_connections_async_from_dict(): def test_list_channel_connections_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4524,7 +4927,7 @@ def test_list_channel_connections_field_headers(): @pytest.mark.asyncio async def test_list_channel_connections_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4557,7 +4960,7 @@ async def test_list_channel_connections_field_headers_async(): def test_list_channel_connections_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4583,7 +4986,7 @@ def test_list_channel_connections_flattened(): def test_list_channel_connections_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4598,7 +5001,7 @@ def test_list_channel_connections_flattened_error(): @pytest.mark.asyncio async def test_list_channel_connections_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4629,7 +5032,7 @@ async def test_list_channel_connections_flattened_async(): @pytest.mark.asyncio async def test_list_channel_connections_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4643,7 +5046,7 @@ async def test_list_channel_connections_flattened_error_async(): def test_list_channel_connections_pager(transport_name: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4695,7 +5098,7 @@ def test_list_channel_connections_pager(transport_name: str = "grpc"): def test_list_channel_connections_pages(transport_name: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4739,7 +5142,7 @@ def test_list_channel_connections_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_channel_connections_async_pager(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4793,7 +5196,7 @@ async def test_list_channel_connections_async_pager(): @pytest.mark.asyncio async def test_list_channel_connections_async_pages(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4850,7 +5253,7 @@ async def test_list_channel_connections_async_pages(): ) def test_create_channel_connection(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4879,7 +5282,7 @@ def test_create_channel_connection_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4899,7 +5302,7 @@ async def test_create_channel_connection_async( request_type=eventarc.CreateChannelConnectionRequest, ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4933,7 +5336,7 @@ async def test_create_channel_connection_async_from_dict(): def test_create_channel_connection_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4965,7 +5368,7 @@ def test_create_channel_connection_field_headers(): @pytest.mark.asyncio async def test_create_channel_connection_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4998,7 +5401,7 @@ async def test_create_channel_connection_field_headers_async(): def test_create_channel_connection_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5034,7 +5437,7 @@ def test_create_channel_connection_flattened(): def test_create_channel_connection_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5053,7 +5456,7 @@ def test_create_channel_connection_flattened_error(): @pytest.mark.asyncio async def test_create_channel_connection_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5094,7 +5497,7 @@ async def test_create_channel_connection_flattened_async(): @pytest.mark.asyncio async def test_create_channel_connection_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5119,7 +5522,7 @@ async def test_create_channel_connection_flattened_error_async(): ) def test_delete_channel_connection(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5148,7 +5551,7 @@ def test_delete_channel_connection_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5168,7 +5571,7 @@ async def test_delete_channel_connection_async( request_type=eventarc.DeleteChannelConnectionRequest, ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5202,7 +5605,7 @@ async def test_delete_channel_connection_async_from_dict(): def test_delete_channel_connection_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5234,7 +5637,7 @@ def test_delete_channel_connection_field_headers(): @pytest.mark.asyncio async def test_delete_channel_connection_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5267,7 +5670,7 @@ async def test_delete_channel_connection_field_headers_async(): def test_delete_channel_connection_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5293,7 +5696,7 @@ def test_delete_channel_connection_flattened(): def test_delete_channel_connection_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5308,7 +5711,7 @@ def test_delete_channel_connection_flattened_error(): @pytest.mark.asyncio async def test_delete_channel_connection_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5339,7 +5742,7 @@ async def test_delete_channel_connection_flattened_async(): @pytest.mark.asyncio async def test_delete_channel_connection_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5360,7 +5763,7 @@ async def test_delete_channel_connection_flattened_error_async(): ) def test_get_google_channel_config(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5394,7 +5797,7 @@ def test_get_google_channel_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5413,7 +5816,7 @@ async def test_get_google_channel_config_async( transport: str = "grpc_asyncio", request_type=eventarc.GetGoogleChannelConfigRequest ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5452,7 +5855,7 @@ async def test_get_google_channel_config_async_from_dict(): def test_get_google_channel_config_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5484,7 +5887,7 @@ def test_get_google_channel_config_field_headers(): @pytest.mark.asyncio async def test_get_google_channel_config_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5517,7 +5920,7 @@ async def test_get_google_channel_config_field_headers_async(): def test_get_google_channel_config_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5543,7 +5946,7 @@ def test_get_google_channel_config_flattened(): def test_get_google_channel_config_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5558,7 +5961,7 @@ def test_get_google_channel_config_flattened_error(): @pytest.mark.asyncio async def test_get_google_channel_config_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5589,7 +5992,7 @@ async def test_get_google_channel_config_flattened_async(): @pytest.mark.asyncio async def test_get_google_channel_config_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5610,7 +6013,7 @@ async def test_get_google_channel_config_flattened_error_async(): ) def test_update_google_channel_config(request_type, transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5644,7 +6047,7 @@ def test_update_google_channel_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5664,7 +6067,7 @@ async def test_update_google_channel_config_async( request_type=eventarc.UpdateGoogleChannelConfigRequest, ): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5703,7 +6106,7 @@ async def test_update_google_channel_config_async_from_dict(): def test_update_google_channel_config_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5735,7 +6138,7 @@ def test_update_google_channel_config_field_headers(): @pytest.mark.asyncio async def test_update_google_channel_config_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5768,7 +6171,7 @@ async def test_update_google_channel_config_field_headers_async(): def test_update_google_channel_config_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5800,7 +6203,7 @@ def test_update_google_channel_config_flattened(): def test_update_google_channel_config_flattened_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5818,7 +6221,7 @@ def test_update_google_channel_config_flattened_error(): @pytest.mark.asyncio async def test_update_google_channel_config_flattened_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5855,7 +6258,7 @@ async def test_update_google_channel_config_flattened_async(): @pytest.mark.asyncio async def test_update_google_channel_config_flattened_error_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5879,7 +6282,7 @@ async def test_update_google_channel_config_flattened_error_async(): ) def test_get_trigger_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5936,7 +6339,7 @@ def test_get_trigger_rest_required_fields(request_type=eventarc.GetTriggerReques # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5945,7 +6348,7 @@ def test_get_trigger_rest_required_fields(request_type=eventarc.GetTriggerReques jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5954,7 +6357,7 @@ def test_get_trigger_rest_required_fields(request_type=eventarc.GetTriggerReques assert jsonified_request["name"] == "name_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5996,7 +6399,7 @@ def test_get_trigger_rest_required_fields(request_type=eventarc.GetTriggerReques def test_get_trigger_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_trigger._get_unset_required_fields({}) @@ -6006,7 +6409,7 @@ def test_get_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_trigger_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -6058,7 +6461,7 @@ def test_get_trigger_rest_bad_request( transport: str = "rest", request_type=eventarc.GetTriggerRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6080,7 +6483,7 @@ def test_get_trigger_rest_bad_request( def test_get_trigger_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6121,7 +6524,7 @@ def test_get_trigger_rest_flattened(): def test_get_trigger_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6136,7 +6539,7 @@ def test_get_trigger_rest_flattened_error(transport: str = "rest"): def test_get_trigger_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6149,7 +6552,7 @@ def test_get_trigger_rest_error(): ) def test_list_triggers_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6200,7 +6603,7 @@ def test_list_triggers_rest_required_fields(request_type=eventarc.ListTriggersRe # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_triggers._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6209,7 +6612,7 @@ def test_list_triggers_rest_required_fields(request_type=eventarc.ListTriggersRe jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_triggers._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6227,7 +6630,7 @@ def test_list_triggers_rest_required_fields(request_type=eventarc.ListTriggersRe assert jsonified_request["parent"] == "parent_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6269,7 +6672,7 @@ def test_list_triggers_rest_required_fields(request_type=eventarc.ListTriggersRe def test_list_triggers_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_triggers._get_unset_required_fields({}) @@ -6289,7 +6692,7 @@ def test_list_triggers_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_triggers_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -6343,7 +6746,7 @@ def test_list_triggers_rest_bad_request( transport: str = "rest", request_type=eventarc.ListTriggersRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6365,7 +6768,7 @@ def test_list_triggers_rest_bad_request( def test_list_triggers_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6406,7 +6809,7 @@ def test_list_triggers_rest_flattened(): def test_list_triggers_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6421,7 +6824,7 @@ def test_list_triggers_rest_flattened_error(transport: str = "rest"): def test_list_triggers_rest_pager(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6489,7 +6892,7 @@ def test_list_triggers_rest_pager(transport: str = "rest"): ) def test_create_trigger_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6643,7 +7046,7 @@ def test_create_trigger_rest_required_fields( assert "validateOnly" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6658,7 +7061,7 @@ def test_create_trigger_rest_required_fields( jsonified_request["validateOnly"] = True unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_trigger._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6678,7 +7081,7 @@ def test_create_trigger_rest_required_fields( assert jsonified_request["validateOnly"] == True client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6728,7 +7131,7 @@ def test_create_trigger_rest_required_fields( def test_create_trigger_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_trigger._get_unset_required_fields({}) @@ -6753,7 +7156,7 @@ def test_create_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_trigger_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -6809,7 +7212,7 @@ def test_create_trigger_rest_bad_request( transport: str = "rest", request_type=eventarc.CreateTriggerRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6831,7 +7234,7 @@ def test_create_trigger_rest_bad_request( def test_create_trigger_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6872,7 +7275,7 @@ def test_create_trigger_rest_flattened(): def test_create_trigger_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6889,7 +7292,7 @@ def test_create_trigger_rest_flattened_error(transport: str = "rest"): def test_create_trigger_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6902,7 +7305,7 @@ def test_create_trigger_rest_error(): ) def test_update_trigger_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7055,7 +7458,7 @@ def test_update_trigger_rest_required_fields( assert "validateOnly" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7066,7 +7469,7 @@ def test_update_trigger_rest_required_fields( jsonified_request["validateOnly"] = True unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_trigger._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7083,7 +7486,7 @@ def test_update_trigger_rest_required_fields( assert jsonified_request["validateOnly"] == True client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7129,7 +7532,7 @@ def test_update_trigger_rest_required_fields( def test_update_trigger_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_trigger._get_unset_required_fields({}) @@ -7148,7 +7551,7 @@ def test_update_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_trigger_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -7204,7 +7607,7 @@ def test_update_trigger_rest_bad_request( transport: str = "rest", request_type=eventarc.UpdateTriggerRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7228,7 +7631,7 @@ def test_update_trigger_rest_bad_request( def test_update_trigger_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7272,7 +7675,7 @@ def test_update_trigger_rest_flattened(): def test_update_trigger_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7289,7 +7692,7 @@ def test_update_trigger_rest_flattened_error(transport: str = "rest"): def test_update_trigger_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7302,7 +7705,7 @@ def test_update_trigger_rest_error(): ) def test_delete_trigger_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7350,7 +7753,7 @@ def test_delete_trigger_rest_required_fields( assert "validateOnly" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_trigger._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7362,7 +7765,7 @@ def test_delete_trigger_rest_required_fields( jsonified_request["validateOnly"] = True unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_trigger._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7381,7 +7784,7 @@ def test_delete_trigger_rest_required_fields( assert jsonified_request["validateOnly"] == True client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7426,7 +7829,7 @@ def test_delete_trigger_rest_required_fields( def test_delete_trigger_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_trigger._get_unset_required_fields({}) @@ -7450,7 +7853,7 @@ def test_delete_trigger_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_trigger_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -7506,7 +7909,7 @@ def test_delete_trigger_rest_bad_request( transport: str = "rest", request_type=eventarc.DeleteTriggerRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7528,7 +7931,7 @@ def test_delete_trigger_rest_bad_request( def test_delete_trigger_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7568,7 +7971,7 @@ def test_delete_trigger_rest_flattened(): def test_delete_trigger_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7584,7 +7987,7 @@ def test_delete_trigger_rest_flattened_error(transport: str = "rest"): def test_delete_trigger_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7597,7 +8000,7 @@ def test_delete_trigger_rest_error(): ) def test_get_channel_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7657,7 +8060,7 @@ def test_get_channel_rest_required_fields(request_type=eventarc.GetChannelReques # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_channel._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7666,7 +8069,7 @@ def test_get_channel_rest_required_fields(request_type=eventarc.GetChannelReques jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_channel._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7675,7 +8078,7 @@ def test_get_channel_rest_required_fields(request_type=eventarc.GetChannelReques assert jsonified_request["name"] == "name_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7717,7 +8120,7 @@ def test_get_channel_rest_required_fields(request_type=eventarc.GetChannelReques def test_get_channel_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_channel._get_unset_required_fields({}) @@ -7727,7 +8130,7 @@ def test_get_channel_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_channel_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -7779,7 +8182,7 @@ def test_get_channel_rest_bad_request( transport: str = "rest", request_type=eventarc.GetChannelRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7801,7 +8204,7 @@ def test_get_channel_rest_bad_request( def test_get_channel_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7842,7 +8245,7 @@ def test_get_channel_rest_flattened(): def test_get_channel_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7857,7 +8260,7 @@ def test_get_channel_rest_flattened_error(transport: str = "rest"): def test_get_channel_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7870,7 +8273,7 @@ def test_get_channel_rest_error(): ) def test_list_channels_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7921,7 +8324,7 @@ def test_list_channels_rest_required_fields(request_type=eventarc.ListChannelsRe # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_channels._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7930,7 +8333,7 @@ def test_list_channels_rest_required_fields(request_type=eventarc.ListChannelsRe jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_channels._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7947,7 +8350,7 @@ def test_list_channels_rest_required_fields(request_type=eventarc.ListChannelsRe assert jsonified_request["parent"] == "parent_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7989,7 +8392,7 @@ def test_list_channels_rest_required_fields(request_type=eventarc.ListChannelsRe def test_list_channels_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_channels._get_unset_required_fields({}) @@ -8008,7 +8411,7 @@ def test_list_channels_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_channels_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -8062,7 +8465,7 @@ def test_list_channels_rest_bad_request( transport: str = "rest", request_type=eventarc.ListChannelsRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8084,7 +8487,7 @@ def test_list_channels_rest_bad_request( def test_list_channels_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8125,7 +8528,7 @@ def test_list_channels_rest_flattened(): def test_list_channels_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8140,7 +8543,7 @@ def test_list_channels_rest_flattened_error(transport: str = "rest"): def test_list_channels_rest_pager(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8208,7 +8611,7 @@ def test_list_channels_rest_pager(transport: str = "rest"): ) def test_create_channel_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8336,7 +8739,7 @@ def test_create_channel_rest_required_fields( assert "validateOnly" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_channel_._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8351,7 +8754,7 @@ def test_create_channel_rest_required_fields( jsonified_request["validateOnly"] = True unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_channel_._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8371,7 +8774,7 @@ def test_create_channel_rest_required_fields( assert jsonified_request["validateOnly"] == True client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8421,7 +8824,7 @@ def test_create_channel_rest_required_fields( def test_create_channel_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_channel_._get_unset_required_fields({}) @@ -8446,7 +8849,7 @@ def test_create_channel_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_channel_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -8502,7 +8905,7 @@ def test_create_channel_rest_bad_request( transport: str = "rest", request_type=eventarc.CreateChannelRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8524,7 +8927,7 @@ def test_create_channel_rest_bad_request( def test_create_channel_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8565,7 +8968,7 @@ def test_create_channel_rest_flattened(): def test_create_channel_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8582,7 +8985,7 @@ def test_create_channel_rest_flattened_error(transport: str = "rest"): def test_create_channel_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8595,7 +8998,7 @@ def test_create_channel_rest_error(): ) def test_update_channel_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8722,7 +9125,7 @@ def test_update_channel_rest_required_fields( assert "validateOnly" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_channel._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8733,7 +9136,7 @@ def test_update_channel_rest_required_fields( jsonified_request["validateOnly"] = True unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_channel._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8749,7 +9152,7 @@ def test_update_channel_rest_required_fields( assert jsonified_request["validateOnly"] == True client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8795,7 +9198,7 @@ def test_update_channel_rest_required_fields( def test_update_channel_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_channel._get_unset_required_fields({}) @@ -8813,7 +9216,7 @@ def test_update_channel_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_channel_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -8869,7 +9272,7 @@ def test_update_channel_rest_bad_request( transport: str = "rest", request_type=eventarc.UpdateChannelRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8893,7 +9296,7 @@ def test_update_channel_rest_bad_request( def test_update_channel_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8936,7 +9339,7 @@ def test_update_channel_rest_flattened(): def test_update_channel_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8952,7 +9355,7 @@ def test_update_channel_rest_flattened_error(transport: str = "rest"): def test_update_channel_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8965,7 +9368,7 @@ def test_update_channel_rest_error(): ) def test_delete_channel_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9013,7 +9416,7 @@ def test_delete_channel_rest_required_fields( assert "validateOnly" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_channel._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9025,7 +9428,7 @@ def test_delete_channel_rest_required_fields( jsonified_request["validateOnly"] = True unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_channel._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("validate_only",)) @@ -9038,7 +9441,7 @@ def test_delete_channel_rest_required_fields( assert jsonified_request["validateOnly"] == True client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9083,7 +9486,7 @@ def test_delete_channel_rest_required_fields( def test_delete_channel_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_channel._get_unset_required_fields({}) @@ -9101,7 +9504,7 @@ def test_delete_channel_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_channel_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -9157,7 +9560,7 @@ def test_delete_channel_rest_bad_request( transport: str = "rest", request_type=eventarc.DeleteChannelRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9179,7 +9582,7 @@ def test_delete_channel_rest_bad_request( def test_delete_channel_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9218,7 +9621,7 @@ def test_delete_channel_rest_flattened(): def test_delete_channel_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9233,7 +9636,7 @@ def test_delete_channel_rest_flattened_error(transport: str = "rest"): def test_delete_channel_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9246,7 +9649,7 @@ def test_delete_channel_rest_error(): ) def test_get_provider_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9297,7 +9700,7 @@ def test_get_provider_rest_required_fields(request_type=eventarc.GetProviderRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_provider._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9306,7 +9709,7 @@ def test_get_provider_rest_required_fields(request_type=eventarc.GetProviderRequ jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_provider._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9315,7 +9718,7 @@ def test_get_provider_rest_required_fields(request_type=eventarc.GetProviderRequ assert jsonified_request["name"] == "name_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9357,7 +9760,7 @@ def test_get_provider_rest_required_fields(request_type=eventarc.GetProviderRequ def test_get_provider_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_provider._get_unset_required_fields({}) @@ -9367,7 +9770,7 @@ def test_get_provider_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_provider_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -9419,7 +9822,7 @@ def test_get_provider_rest_bad_request( transport: str = "rest", request_type=eventarc.GetProviderRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9441,7 +9844,7 @@ def test_get_provider_rest_bad_request( def test_get_provider_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9484,7 +9887,7 @@ def test_get_provider_rest_flattened(): def test_get_provider_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9499,7 +9902,7 @@ def test_get_provider_rest_flattened_error(transport: str = "rest"): def test_get_provider_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9512,7 +9915,7 @@ def test_get_provider_rest_error(): ) def test_list_providers_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9565,7 +9968,7 @@ def test_list_providers_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_providers._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9574,7 +9977,7 @@ def test_list_providers_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_providers._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -9592,7 +9995,7 @@ def test_list_providers_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9634,7 +10037,7 @@ def test_list_providers_rest_required_fields( def test_list_providers_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_providers._get_unset_required_fields({}) @@ -9654,7 +10057,7 @@ def test_list_providers_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_providers_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -9708,7 +10111,7 @@ def test_list_providers_rest_bad_request( transport: str = "rest", request_type=eventarc.ListProvidersRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9730,7 +10133,7 @@ def test_list_providers_rest_bad_request( def test_list_providers_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9771,7 +10174,7 @@ def test_list_providers_rest_flattened(): def test_list_providers_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9786,7 +10189,7 @@ def test_list_providers_rest_flattened_error(transport: str = "rest"): def test_list_providers_rest_pager(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9854,7 +10257,7 @@ def test_list_providers_rest_pager(transport: str = "rest"): ) def test_get_channel_connection_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9913,7 +10316,7 @@ def test_get_channel_connection_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_channel_connection._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9922,7 +10325,7 @@ def test_get_channel_connection_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_channel_connection._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9931,7 +10334,7 @@ def test_get_channel_connection_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9973,7 +10376,7 @@ def test_get_channel_connection_rest_required_fields( def test_get_channel_connection_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_channel_connection._get_unset_required_fields({}) @@ -9983,7 +10386,7 @@ def test_get_channel_connection_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_channel_connection_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -10039,7 +10442,7 @@ def test_get_channel_connection_rest_bad_request( transport: str = "rest", request_type=eventarc.GetChannelConnectionRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10063,7 +10466,7 @@ def test_get_channel_connection_rest_bad_request( def test_get_channel_connection_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10107,7 +10510,7 @@ def test_get_channel_connection_rest_flattened(): def test_get_channel_connection_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10122,7 +10525,7 @@ def test_get_channel_connection_rest_flattened_error(transport: str = "rest"): def test_get_channel_connection_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10135,7 +10538,7 @@ def test_get_channel_connection_rest_error(): ) def test_list_channel_connections_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10188,7 +10591,7 @@ def test_list_channel_connections_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_channel_connections._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10197,7 +10600,7 @@ def test_list_channel_connections_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_channel_connections._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -10213,7 +10616,7 @@ def test_list_channel_connections_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10255,7 +10658,7 @@ def test_list_channel_connections_rest_required_fields( def test_list_channel_connections_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_channel_connections._get_unset_required_fields({}) @@ -10273,7 +10676,7 @@ def test_list_channel_connections_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_channel_connections_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -10329,7 +10732,7 @@ def test_list_channel_connections_rest_bad_request( transport: str = "rest", request_type=eventarc.ListChannelConnectionsRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10351,7 +10754,7 @@ def test_list_channel_connections_rest_bad_request( def test_list_channel_connections_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10393,7 +10796,7 @@ def test_list_channel_connections_rest_flattened(): def test_list_channel_connections_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10408,7 +10811,7 @@ def test_list_channel_connections_rest_flattened_error(transport: str = "rest"): def test_list_channel_connections_rest_pager(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10478,7 +10881,7 @@ def test_list_channel_connections_rest_pager(transport: str = "rest"): ) def test_create_channel_connection_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10603,7 +11006,7 @@ def test_create_channel_connection_rest_required_fields( assert "channelConnectionId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_channel_connection._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10618,7 +11021,7 @@ def test_create_channel_connection_rest_required_fields( jsonified_request["channelConnectionId"] = "channel_connection_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_channel_connection._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("channel_connection_id",)) @@ -10631,7 +11034,7 @@ def test_create_channel_connection_rest_required_fields( assert jsonified_request["channelConnectionId"] == "channel_connection_id_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10677,7 +11080,7 @@ def test_create_channel_connection_rest_required_fields( def test_create_channel_connection_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_channel_connection._get_unset_required_fields({}) @@ -10696,7 +11099,7 @@ def test_create_channel_connection_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_channel_connection_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -10754,7 +11157,7 @@ def test_create_channel_connection_rest_bad_request( transport: str = "rest", request_type=eventarc.CreateChannelConnectionRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10776,7 +11179,7 @@ def test_create_channel_connection_rest_bad_request( def test_create_channel_connection_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10820,7 +11223,7 @@ def test_create_channel_connection_rest_flattened(): def test_create_channel_connection_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10839,7 +11242,7 @@ def test_create_channel_connection_rest_flattened_error(transport: str = "rest") def test_create_channel_connection_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10852,7 +11255,7 @@ def test_create_channel_connection_rest_error(): ) def test_delete_channel_connection_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10900,7 +11303,7 @@ def test_delete_channel_connection_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_channel_connection._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10909,7 +11312,7 @@ def test_delete_channel_connection_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_channel_connection._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10918,7 +11321,7 @@ def test_delete_channel_connection_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10957,7 +11360,7 @@ def test_delete_channel_connection_rest_required_fields( def test_delete_channel_connection_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_channel_connection._get_unset_required_fields({}) @@ -10967,7 +11370,7 @@ def test_delete_channel_connection_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_channel_connection_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -11025,7 +11428,7 @@ def test_delete_channel_connection_rest_bad_request( transport: str = "rest", request_type=eventarc.DeleteChannelConnectionRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11049,7 +11452,7 @@ def test_delete_channel_connection_rest_bad_request( def test_delete_channel_connection_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11091,7 +11494,7 @@ def test_delete_channel_connection_rest_flattened(): def test_delete_channel_connection_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11106,7 +11509,7 @@ def test_delete_channel_connection_rest_flattened_error(transport: str = "rest") def test_delete_channel_connection_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11119,7 +11522,7 @@ def test_delete_channel_connection_rest_error(): ) def test_get_google_channel_config_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11172,7 +11575,7 @@ def test_get_google_channel_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_google_channel_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11181,7 +11584,7 @@ def test_get_google_channel_config_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_google_channel_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11190,7 +11593,7 @@ def test_get_google_channel_config_rest_required_fields( assert jsonified_request["name"] == "name_value" client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11232,7 +11635,7 @@ def test_get_google_channel_config_rest_required_fields( def test_get_google_channel_config_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_google_channel_config._get_unset_required_fields({}) @@ -11242,7 +11645,7 @@ def test_get_google_channel_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_google_channel_config_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -11298,7 +11701,7 @@ def test_get_google_channel_config_rest_bad_request( transport: str = "rest", request_type=eventarc.GetGoogleChannelConfigRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11320,7 +11723,7 @@ def test_get_google_channel_config_rest_bad_request( def test_get_google_channel_config_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11364,7 +11767,7 @@ def test_get_google_channel_config_rest_flattened(): def test_get_google_channel_config_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11379,7 +11782,7 @@ def test_get_google_channel_config_rest_flattened_error(transport: str = "rest") def test_get_google_channel_config_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11392,7 +11795,7 @@ def test_get_google_channel_config_rest_error(): ) def test_update_google_channel_config_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11524,14 +11927,14 @@ def test_update_google_channel_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_google_channel_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_google_channel_config._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -11540,7 +11943,7 @@ def test_update_google_channel_config_rest_required_fields( # verify required fields with non-default values are left alone client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11585,7 +11988,7 @@ def test_update_google_channel_config_rest_required_fields( def test_update_google_channel_config_rest_unset_required_fields(): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_google_channel_config._get_unset_required_fields({}) @@ -11595,7 +11998,7 @@ def test_update_google_channel_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_google_channel_config_rest_interceptors(null_interceptor): transport = transports.EventarcRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.EventarcRestInterceptor(), ) client = EventarcClient(transport=transport) @@ -11653,7 +12056,7 @@ def test_update_google_channel_config_rest_bad_request( transport: str = "rest", request_type=eventarc.UpdateGoogleChannelConfigRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11679,7 +12082,7 @@ def test_update_google_channel_config_rest_bad_request( def test_update_google_channel_config_rest_flattened(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11728,7 +12131,7 @@ def test_update_google_channel_config_rest_flattened(): def test_update_google_channel_config_rest_flattened_error(transport: str = "rest"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11746,24 +12149,24 @@ def test_update_google_channel_config_rest_flattened_error(transport: str = "res def test_update_google_channel_config_rest_error(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.EventarcGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.EventarcGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EventarcClient( @@ -11773,7 +12176,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.EventarcGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -11784,16 +12187,17 @@ 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 = EventarcClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.EventarcGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = EventarcClient( @@ -11805,7 +12209,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.EventarcGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = EventarcClient(transport=transport) assert client.transport is transport @@ -11814,13 +12218,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.EventarcGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.EventarcGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -11837,7 +12241,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -11851,7 +12255,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = EventarcClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -11859,7 +12263,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -11871,7 +12275,7 @@ def test_eventarc_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.EventarcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -11883,7 +12287,7 @@ def test_eventarc_base_transport(): ) as Transport: Transport.return_value = None transport = transports.EventarcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -11946,7 +12350,7 @@ def test_eventarc_base_transport_with_credentials_file(): "google.cloud.eventarc_v1.services.eventarc.transports.EventarcTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EventarcTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -11965,7 +12369,7 @@ def test_eventarc_base_transport_with_adc(): "google.cloud.eventarc_v1.services.eventarc.transports.EventarcTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.EventarcTransport() adc.assert_called_once() @@ -11973,7 +12377,7 @@ def test_eventarc_base_transport_with_adc(): def test_eventarc_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) EventarcClient() adc.assert_called_once_with( scopes=None, @@ -11993,7 +12397,7 @@ def test_eventarc_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -12040,7 +12444,7 @@ def test_eventarc_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12065,7 +12469,7 @@ def test_eventarc_transport_create_channel(transport_class, grpc_helpers): [transports.EventarcGrpcTransport, transports.EventarcGrpcAsyncIOTransport], ) def test_eventarc_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -12103,7 +12507,7 @@ def test_eventarc_grpc_transport_client_cert_source_for_mtls(transport_class): def test_eventarc_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -12115,7 +12519,7 @@ def test_eventarc_http_transport_client_cert_source_for_mtls(): def test_eventarc_rest_lro_client(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -12140,7 +12544,7 @@ def test_eventarc_rest_lro_client(): ) def test_eventarc_host_no_port(transport_name): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="eventarc.googleapis.com" ), @@ -12163,7 +12567,7 @@ def test_eventarc_host_no_port(transport_name): ) def test_eventarc_host_with_port(transport_name): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="eventarc.googleapis.com:8000" ), @@ -12183,8 +12587,8 @@ def test_eventarc_host_with_port(transport_name): ], ) def test_eventarc_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = EventarcClient( credentials=creds1, transport=transport_name, @@ -12294,7 +12698,7 @@ def test_eventarc_transport_channel_mtls_with_client_cert_source(transport_class mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -12369,7 +12773,7 @@ def test_eventarc_transport_channel_mtls_with_adc(transport_class): def test_eventarc_grpc_lro_client(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -12386,7 +12790,7 @@ def test_eventarc_grpc_lro_client(): def test_eventarc_grpc_lro_async_client(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -12759,7 +13163,7 @@ def test_client_with_default_client_info(): transports.EventarcTransport, "_prep_wrapped_messages" ) as prep: client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -12769,7 +13173,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = EventarcClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -12778,7 +13182,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -12793,7 +13197,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12823,7 +13227,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -12851,7 +13255,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12879,7 +13283,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -12907,7 +13311,7 @@ def test_get_iam_policy_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12937,7 +13341,7 @@ def test_get_iam_policy_rest_bad_request( ) def test_get_iam_policy_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"resource": "projects/sample1/locations/sample2/triggers/sample3"} @@ -12965,7 +13369,7 @@ def test_set_iam_policy_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12995,7 +13399,7 @@ def test_set_iam_policy_rest_bad_request( ) def test_set_iam_policy_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"resource": "projects/sample1/locations/sample2/triggers/sample3"} @@ -13023,7 +13427,7 @@ def test_test_iam_permissions_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.TestIamPermissionsRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13053,7 +13457,7 @@ def test_test_iam_permissions_rest_bad_request( ) def test_test_iam_permissions_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"resource": "projects/sample1/locations/sample2/triggers/sample3"} @@ -13081,7 +13485,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13111,7 +13515,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -13139,7 +13543,7 @@ def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13169,7 +13573,7 @@ def test_delete_operation_rest_bad_request( ) def test_delete_operation_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -13197,7 +13601,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13227,7 +13631,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -13255,7 +13659,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13285,7 +13689,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -13311,7 +13715,7 @@ def test_list_operations_rest(request_type): def test_delete_operation(transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13336,7 +13740,7 @@ def test_delete_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_delete_operation_async(transport: str = "grpc_asyncio"): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13360,7 +13764,7 @@ async def test_delete_operation_async(transport: str = "grpc_asyncio"): def test_delete_operation_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13389,7 +13793,7 @@ def test_delete_operation_field_headers(): @pytest.mark.asyncio async def test_delete_operation_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13416,7 +13820,7 @@ async def test_delete_operation_field_headers_async(): def test_delete_operation_from_dict(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -13434,7 +13838,7 @@ def test_delete_operation_from_dict(): @pytest.mark.asyncio async def test_delete_operation_from_dict_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -13450,7 +13854,7 @@ async def test_delete_operation_from_dict_async(): def test_cancel_operation(transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13475,7 +13879,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13499,7 +13903,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13528,7 +13932,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13555,7 +13959,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -13573,7 +13977,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -13589,7 +13993,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13614,7 +14018,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13640,7 +14044,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13669,7 +14073,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13698,7 +14102,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -13716,7 +14120,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -13734,7 +14138,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13759,7 +14163,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13785,7 +14189,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13814,7 +14218,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13843,7 +14247,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -13861,7 +14265,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -13879,7 +14283,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13904,7 +14308,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13930,7 +14334,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13959,7 +14363,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13988,7 +14392,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -14006,7 +14410,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -14024,7 +14428,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14049,7 +14453,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14074,7 +14478,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = EventarcClient(credentials=ga_credentials.AnonymousCredentials()) + client = EventarcClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -14101,7 +14505,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = EventarcAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = EventarcAsyncClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -14129,7 +14533,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -14147,7 +14551,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -14165,7 +14569,7 @@ async def test_get_location_from_dict_async(): def test_set_iam_policy(transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14198,7 +14602,7 @@ def test_set_iam_policy(transport: str = "grpc"): @pytest.mark.asyncio async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14233,7 +14637,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): def test_set_iam_policy_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14263,7 +14667,7 @@ def test_set_iam_policy_field_headers(): @pytest.mark.asyncio async def test_set_iam_policy_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14292,7 +14696,7 @@ async def test_set_iam_policy_field_headers_async(): def test_set_iam_policy_from_dict(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -14311,7 +14715,7 @@ def test_set_iam_policy_from_dict(): @pytest.mark.asyncio async def test_set_iam_policy_from_dict_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -14329,7 +14733,7 @@ async def test_set_iam_policy_from_dict_async(): def test_get_iam_policy(transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14364,7 +14768,7 @@ def test_get_iam_policy(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14400,7 +14804,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): def test_get_iam_policy_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14430,7 +14834,7 @@ def test_get_iam_policy_field_headers(): @pytest.mark.asyncio async def test_get_iam_policy_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14459,7 +14863,7 @@ async def test_get_iam_policy_field_headers_async(): def test_get_iam_policy_from_dict(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -14478,7 +14882,7 @@ def test_get_iam_policy_from_dict(): @pytest.mark.asyncio async def test_get_iam_policy_from_dict_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -14496,7 +14900,7 @@ async def test_get_iam_policy_from_dict_async(): def test_test_iam_permissions(transport: str = "grpc"): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14530,7 +14934,7 @@ def test_test_iam_permissions(transport: str = "grpc"): @pytest.mark.asyncio async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14565,7 +14969,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): def test_test_iam_permissions_field_headers(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14597,7 +15001,7 @@ def test_test_iam_permissions_field_headers(): @pytest.mark.asyncio async def test_test_iam_permissions_field_headers_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -14630,7 +15034,7 @@ async def test_test_iam_permissions_field_headers_async(): def test_test_iam_permissions_from_dict(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -14651,7 +15055,7 @@ def test_test_iam_permissions_from_dict(): @pytest.mark.asyncio async def test_test_iam_permissions_from_dict_async(): client = EventarcAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -14679,7 +15083,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -14696,7 +15100,7 @@ def test_client_ctx(): ] for transport in transports: client = EventarcClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -14727,7 +15131,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, diff --git a/packages/google-cloud-filestore/google/cloud/filestore/gapic_version.py b/packages/google-cloud-filestore/google/cloud/filestore/gapic_version.py index 97c03305daf2..360a0d13ebdd 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore/gapic_version.py +++ b/packages/google-cloud-filestore/google/cloud/filestore/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.8.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/gapic_version.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/gapic_version.py index 97c03305daf2..360a0d13ebdd 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/gapic_version.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.8.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py index 8b67a54f1e26..1c11bfb97829 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/async_client.py @@ -38,9 +38,9 @@ from google.cloud.filestore_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -88,8 +88,12 @@ class CloudFilestoreManagerAsyncClient: _client: CloudFilestoreManagerClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = CloudFilestoreManagerClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = CloudFilestoreManagerClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = CloudFilestoreManagerClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = CloudFilestoreManagerClient._DEFAULT_UNIVERSE backup_path = staticmethod(CloudFilestoreManagerClient.backup_path) parse_backup_path = staticmethod(CloudFilestoreManagerClient.parse_backup_path) @@ -202,6 +206,25 @@ def transport(self) -> CloudFilestoreManagerTransport: """ 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(CloudFilestoreManagerClient).get_transport_class, type(CloudFilestoreManagerClient), @@ -215,7 +238,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the cloud filestore manager client. + """Instantiates the cloud filestore manager async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -226,23 +249,38 @@ def __init__( transport (Union[str, ~.CloudFilestoreManagerTransport]): 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. @@ -364,6 +402,9 @@ async def sample_list_instances(): 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, @@ -484,6 +525,9 @@ async def sample_get_instance(): 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, @@ -623,6 +667,9 @@ async def sample_create_instance(): 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, @@ -756,6 +803,9 @@ async def sample_update_instance(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -860,6 +910,9 @@ async def sample_restore_instance(): 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, @@ -960,6 +1013,9 @@ async def sample_revert_instance(): 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, @@ -1086,6 +1142,9 @@ async def sample_delete_instance(): 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, @@ -1203,6 +1262,9 @@ async def sample_list_snapshots(): 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, @@ -1314,6 +1376,9 @@ async def sample_get_snapshot(): 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, @@ -1451,6 +1516,9 @@ async def sample_create_snapshot(): 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, @@ -1577,6 +1645,9 @@ async def sample_delete_snapshot(): 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, @@ -1707,6 +1778,9 @@ async def sample_update_snapshot(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1836,6 +1910,9 @@ async def sample_list_backups(): 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, @@ -1954,6 +2031,9 @@ async def sample_get_backup(): 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, @@ -2093,6 +2173,9 @@ async def sample_create_backup(): 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, @@ -2218,6 +2301,9 @@ async def sample_delete_backup(): 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, @@ -2349,6 +2435,9 @@ async def sample_update_backup(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2411,6 +2500,9 @@ async def list_operations( 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, @@ -2465,6 +2557,9 @@ async def get_operation( 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, @@ -2523,6 +2618,9 @@ async def delete_operation( 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, @@ -2577,6 +2675,9 @@ async def cancel_operation( 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, @@ -2628,6 +2729,9 @@ async def get_location( 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, @@ -2682,6 +2786,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py index 8a7a47ca95ac..c0c7a42823f7 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.filestore_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -158,11 +159,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 = "file.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "file.{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 @@ -359,7 +364,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 @@ -389,6 +394,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") @@ -422,6 +432,177 @@ 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 + + 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 + + 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 = CloudFilestoreManagerClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = CloudFilestoreManagerClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + CloudFilestoreManagerClient._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 = CloudFilestoreManagerClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = CloudFilestoreManagerClient._DEFAULT_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 CloudFilestoreManagerClient._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, *, @@ -441,22 +622,32 @@ def __init__( transport (Union[str, CloudFilestoreManagerTransport]): 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. @@ -467,17 +658,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, + ) = CloudFilestoreManagerClient._read_environment_variables() + self._client_cert_source = CloudFilestoreManagerClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = CloudFilestoreManagerClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -486,20 +694,33 @@ 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, CloudFilestoreManagerTransport): + transport_provided = isinstance(transport, CloudFilestoreManagerTransport) + if transport_provided: # transport is a CloudFilestoreManagerTransport 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(CloudFilestoreManagerTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or CloudFilestoreManagerClient._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( @@ -509,17 +730,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_instances( @@ -623,6 +844,9 @@ def sample_list_instances(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -734,6 +958,9 @@ def sample_get_instance(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -873,6 +1100,9 @@ def sample_create_instance(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1006,6 +1236,9 @@ def sample_update_instance(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1111,6 +1344,9 @@ def sample_restore_instance(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1212,6 +1448,9 @@ def sample_revert_instance(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1338,6 +1577,9 @@ def sample_delete_instance(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1455,6 +1697,9 @@ def sample_list_snapshots(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1566,6 +1811,9 @@ def sample_get_snapshot(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1703,6 +1951,9 @@ def sample_create_snapshot(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1829,6 +2080,9 @@ def sample_delete_snapshot(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1959,6 +2213,9 @@ def sample_update_snapshot(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2079,6 +2336,9 @@ def sample_list_backups(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2188,6 +2448,9 @@ def sample_get_backup(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2327,6 +2590,9 @@ def sample_create_backup(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2452,6 +2718,9 @@ def sample_delete_backup(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2583,6 +2852,9 @@ def sample_update_backup(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2658,6 +2930,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2712,6 +2987,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2770,6 +3048,9 @@ def delete_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -2824,6 +3105,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -2875,6 +3159,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2929,6 +3216,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py index 4d7e7e482131..56daa50fcde5 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'file.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 @@ -121,6 +121,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-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py index 4d9ef2e3caa2..10dcd8b19686 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc.py @@ -87,7 +87,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'file.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-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py index 1d4995dbf16e..aa10fba50bfd 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/grpc_asyncio.py @@ -132,7 +132,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'file.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-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py index 5c77a9512e22..a74776ea0bfa 100644 --- a/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py +++ b/packages/google-cloud-filestore/google/cloud/filestore_v1/services/cloud_filestore_manager/transports/rest.py @@ -38,9 +38,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -817,7 +817,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'file.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-filestore/noxfile.py b/packages/google-cloud-filestore/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-filestore/noxfile.py +++ b/packages/google-cloud-filestore/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-filestore/samples/generated_samples/snippet_metadata_google.cloud.filestore.v1.json b/packages/google-cloud-filestore/samples/generated_samples/snippet_metadata_google.cloud.filestore.v1.json index fe35f2993fd9..a9b41ceec6d9 100644 --- a/packages/google-cloud-filestore/samples/generated_samples/snippet_metadata_google.cloud.filestore.v1.json +++ b/packages/google-cloud-filestore/samples/generated_samples/snippet_metadata_google.cloud.filestore.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-filestore", - "version": "1.8.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py b/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py index 6d383c1339ba..d4d5c43c5940 100644 --- a/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py +++ b/packages/google-cloud-filestore/tests/unit/gapic/filestore_v1/test_cloud_filestore_manager.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -82,6 +82,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -112,6 +135,291 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert CloudFilestoreManagerClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert CloudFilestoreManagerClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert CloudFilestoreManagerClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + CloudFilestoreManagerClient._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 CloudFilestoreManagerClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert CloudFilestoreManagerClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert CloudFilestoreManagerClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + CloudFilestoreManagerClient._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 CloudFilestoreManagerClient._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 CloudFilestoreManagerClient._get_client_cert_source(None, False) is None + assert ( + CloudFilestoreManagerClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + CloudFilestoreManagerClient._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 ( + CloudFilestoreManagerClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + CloudFilestoreManagerClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + CloudFilestoreManagerClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFilestoreManagerClient), +) +@mock.patch.object( + CloudFilestoreManagerAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFilestoreManagerAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = CloudFilestoreManagerClient._DEFAULT_UNIVERSE + default_endpoint = CloudFilestoreManagerClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CloudFilestoreManagerClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + CloudFilestoreManagerClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + CloudFilestoreManagerClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == CloudFilestoreManagerClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CloudFilestoreManagerClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + CloudFilestoreManagerClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == CloudFilestoreManagerClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CloudFilestoreManagerClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == CloudFilestoreManagerClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CloudFilestoreManagerClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + CloudFilestoreManagerClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + CloudFilestoreManagerClient._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 ( + CloudFilestoreManagerClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + CloudFilestoreManagerClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + CloudFilestoreManagerClient._get_universe_domain(None, None) + == CloudFilestoreManagerClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + CloudFilestoreManagerClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + CloudFilestoreManagerClient, + transports.CloudFilestoreManagerGrpcTransport, + "grpc", + ), + ( + CloudFilestoreManagerClient, + transports.CloudFilestoreManagerRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -123,7 +431,7 @@ def test__get_default_mtls_endpoint(): def test_cloud_filestore_manager_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -177,7 +485,7 @@ def test_cloud_filestore_manager_client_service_account_always_use_jwt( def test_cloud_filestore_manager_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -235,20 +543,22 @@ def test_cloud_filestore_manager_client_get_transport_class(): ) @mock.patch.object( CloudFilestoreManagerClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CloudFilestoreManagerClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFilestoreManagerClient), ) @mock.patch.object( CloudFilestoreManagerAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CloudFilestoreManagerAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFilestoreManagerAsyncClient), ) def test_cloud_filestore_manager_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CloudFilestoreManagerClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -283,7 +593,9 @@ def test_cloud_filestore_manager_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, @@ -313,15 +625,23 @@ def test_cloud_filestore_manager_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") @@ -331,7 +651,9 @@ def test_cloud_filestore_manager_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", @@ -349,7 +671,9 @@ def test_cloud_filestore_manager_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, @@ -402,13 +726,13 @@ def test_cloud_filestore_manager_client_client_options( ) @mock.patch.object( CloudFilestoreManagerClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CloudFilestoreManagerClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFilestoreManagerClient), ) @mock.patch.object( CloudFilestoreManagerAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CloudFilestoreManagerAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFilestoreManagerAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_cloud_filestore_manager_client_mtls_env_auto( @@ -431,7 +755,9 @@ def test_cloud_filestore_manager_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 @@ -463,7 +789,9 @@ def test_cloud_filestore_manager_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 @@ -497,7 +825,9 @@ def test_cloud_filestore_manager_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, @@ -587,6 +917,118 @@ def test_cloud_filestore_manager_client_get_mtls_endpoint_and_cert_source(client 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", [CloudFilestoreManagerClient, CloudFilestoreManagerAsyncClient] +) +@mock.patch.object( + CloudFilestoreManagerClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFilestoreManagerClient), +) +@mock.patch.object( + CloudFilestoreManagerAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFilestoreManagerAsyncClient), +) +def test_cloud_filestore_manager_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = CloudFilestoreManagerClient._DEFAULT_UNIVERSE + default_endpoint = CloudFilestoreManagerClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CloudFilestoreManagerClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -621,7 +1063,9 @@ def test_cloud_filestore_manager_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, @@ -666,7 +1110,9 @@ def test_cloud_filestore_manager_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, @@ -726,7 +1172,9 @@ def test_cloud_filestore_manager_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, @@ -743,8 +1191,8 @@ def test_cloud_filestore_manager_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -773,7 +1221,7 @@ def test_cloud_filestore_manager_client_create_channel_credentials_file( ) def test_list_instances(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -805,7 +1253,7 @@ def test_list_instances_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -823,7 +1271,7 @@ async def test_list_instances_async( request_type=cloud_filestore_service.ListInstancesRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -860,7 +1308,7 @@ async def test_list_instances_async_from_dict(): def test_list_instances_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -890,7 +1338,7 @@ def test_list_instances_field_headers(): @pytest.mark.asyncio async def test_list_instances_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -921,7 +1369,7 @@ async def test_list_instances_field_headers_async(): def test_list_instances_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -945,7 +1393,7 @@ def test_list_instances_flattened(): def test_list_instances_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -960,7 +1408,7 @@ def test_list_instances_flattened_error(): @pytest.mark.asyncio async def test_list_instances_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -989,7 +1437,7 @@ async def test_list_instances_flattened_async(): @pytest.mark.asyncio async def test_list_instances_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1003,7 +1451,7 @@ async def test_list_instances_flattened_error_async(): def test_list_instances_pager(transport_name: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1053,7 +1501,7 @@ def test_list_instances_pager(transport_name: str = "grpc"): def test_list_instances_pages(transport_name: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1095,7 +1543,7 @@ def test_list_instances_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_instances_async_pager(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1145,7 +1593,7 @@ async def test_list_instances_async_pager(): @pytest.mark.asyncio async def test_list_instances_async_pages(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1200,7 +1648,7 @@ async def test_list_instances_async_pages(): ) def test_get_instance(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1250,7 +1698,7 @@ def test_get_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1268,7 +1716,7 @@ async def test_get_instance_async( request_type=cloud_filestore_service.GetInstanceRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1323,7 +1771,7 @@ async def test_get_instance_async_from_dict(): def test_get_instance_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1353,7 +1801,7 @@ def test_get_instance_field_headers(): @pytest.mark.asyncio async def test_get_instance_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1384,7 +1832,7 @@ async def test_get_instance_field_headers_async(): def test_get_instance_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1408,7 +1856,7 @@ def test_get_instance_flattened(): def test_get_instance_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1423,7 +1871,7 @@ def test_get_instance_flattened_error(): @pytest.mark.asyncio async def test_get_instance_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1452,7 +1900,7 @@ async def test_get_instance_flattened_async(): @pytest.mark.asyncio async def test_get_instance_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1473,7 +1921,7 @@ async def test_get_instance_flattened_error_async(): ) def test_create_instance(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1500,7 +1948,7 @@ def test_create_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1518,7 +1966,7 @@ async def test_create_instance_async( request_type=cloud_filestore_service.CreateInstanceRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1550,7 +1998,7 @@ async def test_create_instance_async_from_dict(): def test_create_instance_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1580,7 +2028,7 @@ def test_create_instance_field_headers(): @pytest.mark.asyncio async def test_create_instance_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1611,7 +2059,7 @@ async def test_create_instance_field_headers_async(): def test_create_instance_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1643,7 +2091,7 @@ def test_create_instance_flattened(): def test_create_instance_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1660,7 +2108,7 @@ def test_create_instance_flattened_error(): @pytest.mark.asyncio async def test_create_instance_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1697,7 +2145,7 @@ async def test_create_instance_flattened_async(): @pytest.mark.asyncio async def test_create_instance_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1720,7 +2168,7 @@ async def test_create_instance_flattened_error_async(): ) def test_update_instance(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1747,7 +2195,7 @@ def test_update_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1765,7 +2213,7 @@ async def test_update_instance_async( request_type=cloud_filestore_service.UpdateInstanceRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1797,7 +2245,7 @@ async def test_update_instance_async_from_dict(): def test_update_instance_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1827,7 +2275,7 @@ def test_update_instance_field_headers(): @pytest.mark.asyncio async def test_update_instance_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1858,7 +2306,7 @@ async def test_update_instance_field_headers_async(): def test_update_instance_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1886,7 +2334,7 @@ def test_update_instance_flattened(): def test_update_instance_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1902,7 +2350,7 @@ def test_update_instance_flattened_error(): @pytest.mark.asyncio async def test_update_instance_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1935,7 +2383,7 @@ async def test_update_instance_flattened_async(): @pytest.mark.asyncio async def test_update_instance_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1957,7 +2405,7 @@ async def test_update_instance_flattened_error_async(): ) def test_restore_instance(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1984,7 +2432,7 @@ def test_restore_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2002,7 +2450,7 @@ async def test_restore_instance_async( request_type=cloud_filestore_service.RestoreInstanceRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2034,7 +2482,7 @@ async def test_restore_instance_async_from_dict(): def test_restore_instance_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2064,7 +2512,7 @@ def test_restore_instance_field_headers(): @pytest.mark.asyncio async def test_restore_instance_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2102,7 +2550,7 @@ async def test_restore_instance_field_headers_async(): ) def test_revert_instance(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2129,7 +2577,7 @@ def test_revert_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2147,7 +2595,7 @@ async def test_revert_instance_async( request_type=cloud_filestore_service.RevertInstanceRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2179,7 +2627,7 @@ async def test_revert_instance_async_from_dict(): def test_revert_instance_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2209,7 +2657,7 @@ def test_revert_instance_field_headers(): @pytest.mark.asyncio async def test_revert_instance_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2247,7 +2695,7 @@ async def test_revert_instance_field_headers_async(): ) def test_delete_instance(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2274,7 +2722,7 @@ def test_delete_instance_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2292,7 +2740,7 @@ async def test_delete_instance_async( request_type=cloud_filestore_service.DeleteInstanceRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2324,7 +2772,7 @@ async def test_delete_instance_async_from_dict(): def test_delete_instance_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2354,7 +2802,7 @@ def test_delete_instance_field_headers(): @pytest.mark.asyncio async def test_delete_instance_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2385,7 +2833,7 @@ async def test_delete_instance_field_headers_async(): def test_delete_instance_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2409,7 +2857,7 @@ def test_delete_instance_flattened(): def test_delete_instance_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2424,7 +2872,7 @@ def test_delete_instance_flattened_error(): @pytest.mark.asyncio async def test_delete_instance_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2453,7 +2901,7 @@ async def test_delete_instance_flattened_async(): @pytest.mark.asyncio async def test_delete_instance_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2474,7 +2922,7 @@ async def test_delete_instance_flattened_error_async(): ) def test_list_snapshots(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2504,7 +2952,7 @@ def test_list_snapshots_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2522,7 +2970,7 @@ async def test_list_snapshots_async( request_type=cloud_filestore_service.ListSnapshotsRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2557,7 +3005,7 @@ async def test_list_snapshots_async_from_dict(): def test_list_snapshots_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2587,7 +3035,7 @@ def test_list_snapshots_field_headers(): @pytest.mark.asyncio async def test_list_snapshots_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2618,7 +3066,7 @@ async def test_list_snapshots_field_headers_async(): def test_list_snapshots_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2642,7 +3090,7 @@ def test_list_snapshots_flattened(): def test_list_snapshots_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2657,7 +3105,7 @@ def test_list_snapshots_flattened_error(): @pytest.mark.asyncio async def test_list_snapshots_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2686,7 +3134,7 @@ async def test_list_snapshots_flattened_async(): @pytest.mark.asyncio async def test_list_snapshots_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2700,7 +3148,7 @@ async def test_list_snapshots_flattened_error_async(): def test_list_snapshots_pager(transport_name: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2750,7 +3198,7 @@ def test_list_snapshots_pager(transport_name: str = "grpc"): def test_list_snapshots_pages(transport_name: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2792,7 +3240,7 @@ def test_list_snapshots_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_snapshots_async_pager(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2842,7 +3290,7 @@ async def test_list_snapshots_async_pager(): @pytest.mark.asyncio async def test_list_snapshots_async_pages(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2897,7 +3345,7 @@ async def test_list_snapshots_async_pages(): ) def test_get_snapshot(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2933,7 +3381,7 @@ def test_get_snapshot_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2951,7 +3399,7 @@ async def test_get_snapshot_async( request_type=cloud_filestore_service.GetSnapshotRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2992,7 +3440,7 @@ async def test_get_snapshot_async_from_dict(): def test_get_snapshot_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3022,7 +3470,7 @@ def test_get_snapshot_field_headers(): @pytest.mark.asyncio async def test_get_snapshot_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3053,7 +3501,7 @@ async def test_get_snapshot_field_headers_async(): def test_get_snapshot_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3077,7 +3525,7 @@ def test_get_snapshot_flattened(): def test_get_snapshot_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3092,7 +3540,7 @@ def test_get_snapshot_flattened_error(): @pytest.mark.asyncio async def test_get_snapshot_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3121,7 +3569,7 @@ async def test_get_snapshot_flattened_async(): @pytest.mark.asyncio async def test_get_snapshot_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3142,7 +3590,7 @@ async def test_get_snapshot_flattened_error_async(): ) def test_create_snapshot(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3169,7 +3617,7 @@ def test_create_snapshot_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3187,7 +3635,7 @@ async def test_create_snapshot_async( request_type=cloud_filestore_service.CreateSnapshotRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3219,7 +3667,7 @@ async def test_create_snapshot_async_from_dict(): def test_create_snapshot_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3249,7 +3697,7 @@ def test_create_snapshot_field_headers(): @pytest.mark.asyncio async def test_create_snapshot_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3280,7 +3728,7 @@ async def test_create_snapshot_field_headers_async(): def test_create_snapshot_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3312,7 +3760,7 @@ def test_create_snapshot_flattened(): def test_create_snapshot_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3329,7 +3777,7 @@ def test_create_snapshot_flattened_error(): @pytest.mark.asyncio async def test_create_snapshot_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3366,7 +3814,7 @@ async def test_create_snapshot_flattened_async(): @pytest.mark.asyncio async def test_create_snapshot_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3389,7 +3837,7 @@ async def test_create_snapshot_flattened_error_async(): ) def test_delete_snapshot(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3416,7 +3864,7 @@ def test_delete_snapshot_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3434,7 +3882,7 @@ async def test_delete_snapshot_async( request_type=cloud_filestore_service.DeleteSnapshotRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3466,7 +3914,7 @@ async def test_delete_snapshot_async_from_dict(): def test_delete_snapshot_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3496,7 +3944,7 @@ def test_delete_snapshot_field_headers(): @pytest.mark.asyncio async def test_delete_snapshot_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3527,7 +3975,7 @@ async def test_delete_snapshot_field_headers_async(): def test_delete_snapshot_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3551,7 +3999,7 @@ def test_delete_snapshot_flattened(): def test_delete_snapshot_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3566,7 +4014,7 @@ def test_delete_snapshot_flattened_error(): @pytest.mark.asyncio async def test_delete_snapshot_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3595,7 +4043,7 @@ async def test_delete_snapshot_flattened_async(): @pytest.mark.asyncio async def test_delete_snapshot_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3616,7 +4064,7 @@ async def test_delete_snapshot_flattened_error_async(): ) def test_update_snapshot(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3643,7 +4091,7 @@ def test_update_snapshot_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3661,7 +4109,7 @@ async def test_update_snapshot_async( request_type=cloud_filestore_service.UpdateSnapshotRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3693,7 +4141,7 @@ async def test_update_snapshot_async_from_dict(): def test_update_snapshot_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3723,7 +4171,7 @@ def test_update_snapshot_field_headers(): @pytest.mark.asyncio async def test_update_snapshot_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3754,7 +4202,7 @@ async def test_update_snapshot_field_headers_async(): def test_update_snapshot_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3782,7 +4230,7 @@ def test_update_snapshot_flattened(): def test_update_snapshot_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3798,7 +4246,7 @@ def test_update_snapshot_flattened_error(): @pytest.mark.asyncio async def test_update_snapshot_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3831,7 +4279,7 @@ async def test_update_snapshot_flattened_async(): @pytest.mark.asyncio async def test_update_snapshot_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3853,7 +4301,7 @@ async def test_update_snapshot_flattened_error_async(): ) def test_list_backups(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3885,7 +4333,7 @@ def test_list_backups_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3903,7 +4351,7 @@ async def test_list_backups_async( request_type=cloud_filestore_service.ListBackupsRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3940,7 +4388,7 @@ async def test_list_backups_async_from_dict(): def test_list_backups_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3970,7 +4418,7 @@ def test_list_backups_field_headers(): @pytest.mark.asyncio async def test_list_backups_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4001,7 +4449,7 @@ async def test_list_backups_field_headers_async(): def test_list_backups_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4025,7 +4473,7 @@ def test_list_backups_flattened(): def test_list_backups_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4040,7 +4488,7 @@ def test_list_backups_flattened_error(): @pytest.mark.asyncio async def test_list_backups_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4069,7 +4517,7 @@ async def test_list_backups_flattened_async(): @pytest.mark.asyncio async def test_list_backups_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4083,7 +4531,7 @@ async def test_list_backups_flattened_error_async(): def test_list_backups_pager(transport_name: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4133,7 +4581,7 @@ def test_list_backups_pager(transport_name: str = "grpc"): def test_list_backups_pages(transport_name: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4175,7 +4623,7 @@ def test_list_backups_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_backups_async_pager(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4225,7 +4673,7 @@ async def test_list_backups_async_pager(): @pytest.mark.asyncio async def test_list_backups_async_pages(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4280,7 +4728,7 @@ async def test_list_backups_async_pages(): ) def test_get_backup(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4332,7 +4780,7 @@ def test_get_backup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4350,7 +4798,7 @@ async def test_get_backup_async( request_type=cloud_filestore_service.GetBackupRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4407,7 +4855,7 @@ async def test_get_backup_async_from_dict(): def test_get_backup_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4437,7 +4885,7 @@ def test_get_backup_field_headers(): @pytest.mark.asyncio async def test_get_backup_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4468,7 +4916,7 @@ async def test_get_backup_field_headers_async(): def test_get_backup_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4492,7 +4940,7 @@ def test_get_backup_flattened(): def test_get_backup_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4507,7 +4955,7 @@ def test_get_backup_flattened_error(): @pytest.mark.asyncio async def test_get_backup_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4536,7 +4984,7 @@ async def test_get_backup_flattened_async(): @pytest.mark.asyncio async def test_get_backup_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4557,7 +5005,7 @@ async def test_get_backup_flattened_error_async(): ) def test_create_backup(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4584,7 +5032,7 @@ def test_create_backup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4602,7 +5050,7 @@ async def test_create_backup_async( request_type=cloud_filestore_service.CreateBackupRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4634,7 +5082,7 @@ async def test_create_backup_async_from_dict(): def test_create_backup_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4664,7 +5112,7 @@ def test_create_backup_field_headers(): @pytest.mark.asyncio async def test_create_backup_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4695,7 +5143,7 @@ async def test_create_backup_field_headers_async(): def test_create_backup_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4727,7 +5175,7 @@ def test_create_backup_flattened(): def test_create_backup_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4744,7 +5192,7 @@ def test_create_backup_flattened_error(): @pytest.mark.asyncio async def test_create_backup_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4781,7 +5229,7 @@ async def test_create_backup_flattened_async(): @pytest.mark.asyncio async def test_create_backup_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4804,7 +5252,7 @@ async def test_create_backup_flattened_error_async(): ) def test_delete_backup(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4831,7 +5279,7 @@ def test_delete_backup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4849,7 +5297,7 @@ async def test_delete_backup_async( request_type=cloud_filestore_service.DeleteBackupRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4881,7 +5329,7 @@ async def test_delete_backup_async_from_dict(): def test_delete_backup_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4911,7 +5359,7 @@ def test_delete_backup_field_headers(): @pytest.mark.asyncio async def test_delete_backup_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4942,7 +5390,7 @@ async def test_delete_backup_field_headers_async(): def test_delete_backup_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4966,7 +5414,7 @@ def test_delete_backup_flattened(): def test_delete_backup_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4981,7 +5429,7 @@ def test_delete_backup_flattened_error(): @pytest.mark.asyncio async def test_delete_backup_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5010,7 +5458,7 @@ async def test_delete_backup_flattened_async(): @pytest.mark.asyncio async def test_delete_backup_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5031,7 +5479,7 @@ async def test_delete_backup_flattened_error_async(): ) def test_update_backup(request_type, transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5058,7 +5506,7 @@ def test_update_backup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5076,7 +5524,7 @@ async def test_update_backup_async( request_type=cloud_filestore_service.UpdateBackupRequest, ): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5108,7 +5556,7 @@ async def test_update_backup_async_from_dict(): def test_update_backup_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5138,7 +5586,7 @@ def test_update_backup_field_headers(): @pytest.mark.asyncio async def test_update_backup_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5169,7 +5617,7 @@ async def test_update_backup_field_headers_async(): def test_update_backup_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5197,7 +5645,7 @@ def test_update_backup_flattened(): def test_update_backup_flattened_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5213,7 +5661,7 @@ def test_update_backup_flattened_error(): @pytest.mark.asyncio async def test_update_backup_flattened_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5246,7 +5694,7 @@ async def test_update_backup_flattened_async(): @pytest.mark.asyncio async def test_update_backup_flattened_error_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5268,7 +5716,7 @@ async def test_update_backup_flattened_error_async(): ) def test_list_instances_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5321,7 +5769,7 @@ def test_list_instances_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_instances._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5330,7 +5778,7 @@ def test_list_instances_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_instances._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5348,7 +5796,7 @@ def test_list_instances_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5392,7 +5840,7 @@ def test_list_instances_rest_required_fields( def test_list_instances_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_instances._get_unset_required_fields({}) @@ -5412,7 +5860,7 @@ def test_list_instances_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_instances_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -5472,7 +5920,7 @@ def test_list_instances_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.ListInstancesRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5494,7 +5942,7 @@ def test_list_instances_rest_bad_request( def test_list_instances_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5535,7 +5983,7 @@ def test_list_instances_rest_flattened(): def test_list_instances_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5550,7 +5998,7 @@ def test_list_instances_rest_flattened_error(transport: str = "rest"): def test_list_instances_rest_pager(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5620,7 +6068,7 @@ def test_list_instances_rest_pager(transport: str = "rest"): ) def test_get_instance_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5691,7 +6139,7 @@ def test_get_instance_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_instance._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5700,7 +6148,7 @@ def test_get_instance_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_instance._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5709,7 +6157,7 @@ def test_get_instance_rest_required_fields( assert jsonified_request["name"] == "name_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5751,7 +6199,7 @@ def test_get_instance_rest_required_fields( def test_get_instance_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_instance._get_unset_required_fields({}) @@ -5761,7 +6209,7 @@ def test_get_instance_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_instance_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -5819,7 +6267,7 @@ def test_get_instance_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.GetInstanceRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5841,7 +6289,7 @@ def test_get_instance_rest_bad_request( def test_get_instance_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5884,7 +6332,7 @@ def test_get_instance_rest_flattened(): def test_get_instance_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5899,7 +6347,7 @@ def test_get_instance_rest_flattened_error(transport: str = "rest"): def test_get_instance_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5912,7 +6360,7 @@ def test_get_instance_rest_error(): ) def test_create_instance_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6066,7 +6514,7 @@ def test_create_instance_rest_required_fields( assert "instanceId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_instance._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6078,7 +6526,7 @@ def test_create_instance_rest_required_fields( jsonified_request["instanceId"] = "instance_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_instance._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("instance_id",)) @@ -6091,7 +6539,7 @@ def test_create_instance_rest_required_fields( assert jsonified_request["instanceId"] == "instance_id_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6137,7 +6585,7 @@ def test_create_instance_rest_required_fields( def test_create_instance_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_instance._get_unset_required_fields({}) @@ -6156,7 +6604,7 @@ def test_create_instance_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_instance_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -6216,7 +6664,7 @@ def test_create_instance_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.CreateInstanceRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6238,7 +6686,7 @@ def test_create_instance_rest_bad_request( def test_create_instance_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6279,7 +6727,7 @@ def test_create_instance_rest_flattened(): def test_create_instance_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6296,7 +6744,7 @@ def test_create_instance_rest_flattened_error(transport: str = "rest"): def test_create_instance_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6309,7 +6757,7 @@ def test_create_instance_rest_error(): ) def test_update_instance_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6446,7 +6894,7 @@ def get_message_fields(field): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_instance_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -6506,7 +6954,7 @@ def test_update_instance_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.UpdateInstanceRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6530,7 +6978,7 @@ def test_update_instance_rest_bad_request( def test_update_instance_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6573,7 +7021,7 @@ def test_update_instance_rest_flattened(): def test_update_instance_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6589,7 +7037,7 @@ def test_update_instance_rest_flattened_error(transport: str = "rest"): def test_update_instance_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6602,7 +7050,7 @@ def test_update_instance_rest_error(): ) def test_restore_instance_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6649,7 +7097,7 @@ def test_restore_instance_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).restore_instance._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6659,7 +7107,7 @@ def test_restore_instance_rest_required_fields( jsonified_request["fileShare"] = "file_share_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).restore_instance._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6670,7 +7118,7 @@ def test_restore_instance_rest_required_fields( assert jsonified_request["fileShare"] == "file_share_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6710,7 +7158,7 @@ def test_restore_instance_rest_required_fields( def test_restore_instance_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.restore_instance._get_unset_required_fields({}) @@ -6728,7 +7176,7 @@ def test_restore_instance_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_restore_instance_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -6788,7 +7236,7 @@ def test_restore_instance_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.RestoreInstanceRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6810,7 +7258,7 @@ def test_restore_instance_rest_bad_request( def test_restore_instance_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6823,7 +7271,7 @@ def test_restore_instance_rest_error(): ) def test_revert_instance_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6870,7 +7318,7 @@ def test_revert_instance_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).revert_instance._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6880,7 +7328,7 @@ def test_revert_instance_rest_required_fields( jsonified_request["targetSnapshotId"] = "target_snapshot_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).revert_instance._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6891,7 +7339,7 @@ def test_revert_instance_rest_required_fields( assert jsonified_request["targetSnapshotId"] == "target_snapshot_id_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6931,7 +7379,7 @@ def test_revert_instance_rest_required_fields( def test_revert_instance_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.revert_instance._get_unset_required_fields({}) @@ -6949,7 +7397,7 @@ def test_revert_instance_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_revert_instance_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -7009,7 +7457,7 @@ def test_revert_instance_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.RevertInstanceRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7031,7 +7479,7 @@ def test_revert_instance_rest_bad_request( def test_revert_instance_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7044,7 +7492,7 @@ def test_revert_instance_rest_error(): ) def test_delete_instance_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7090,7 +7538,7 @@ def test_delete_instance_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_instance._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7099,7 +7547,7 @@ def test_delete_instance_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_instance._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("force",)) @@ -7110,7 +7558,7 @@ def test_delete_instance_rest_required_fields( assert jsonified_request["name"] == "name_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7149,7 +7597,7 @@ def test_delete_instance_rest_required_fields( def test_delete_instance_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_instance._get_unset_required_fields({}) @@ -7159,7 +7607,7 @@ def test_delete_instance_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_instance_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -7219,7 +7667,7 @@ def test_delete_instance_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.DeleteInstanceRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7241,7 +7689,7 @@ def test_delete_instance_rest_bad_request( def test_delete_instance_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7282,7 +7730,7 @@ def test_delete_instance_rest_flattened(): def test_delete_instance_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7297,7 +7745,7 @@ def test_delete_instance_rest_flattened_error(transport: str = "rest"): def test_delete_instance_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7310,7 +7758,7 @@ def test_delete_instance_rest_error(): ) def test_list_snapshots_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7361,7 +7809,7 @@ def test_list_snapshots_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_snapshots._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7370,7 +7818,7 @@ def test_list_snapshots_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_snapshots._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7388,7 +7836,7 @@ def test_list_snapshots_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7432,7 +7880,7 @@ def test_list_snapshots_rest_required_fields( def test_list_snapshots_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_snapshots._get_unset_required_fields({}) @@ -7452,7 +7900,7 @@ def test_list_snapshots_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_snapshots_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -7512,7 +7960,7 @@ def test_list_snapshots_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.ListSnapshotsRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7534,7 +7982,7 @@ def test_list_snapshots_rest_bad_request( def test_list_snapshots_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7578,7 +8026,7 @@ def test_list_snapshots_rest_flattened(): def test_list_snapshots_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7593,7 +8041,7 @@ def test_list_snapshots_rest_flattened_error(transport: str = "rest"): def test_list_snapshots_rest_pager(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7665,7 +8113,7 @@ def test_list_snapshots_rest_pager(transport: str = "rest"): ) def test_get_snapshot_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7724,7 +8172,7 @@ def test_get_snapshot_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7733,7 +8181,7 @@ def test_get_snapshot_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7742,7 +8190,7 @@ def test_get_snapshot_rest_required_fields( assert jsonified_request["name"] == "name_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7784,7 +8232,7 @@ def test_get_snapshot_rest_required_fields( def test_get_snapshot_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_snapshot._get_unset_required_fields({}) @@ -7794,7 +8242,7 @@ def test_get_snapshot_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_snapshot_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -7852,7 +8300,7 @@ def test_get_snapshot_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.GetSnapshotRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7876,7 +8324,7 @@ def test_get_snapshot_rest_bad_request( def test_get_snapshot_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7920,7 +8368,7 @@ def test_get_snapshot_rest_flattened(): def test_get_snapshot_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7935,7 +8383,7 @@ def test_get_snapshot_rest_flattened_error(transport: str = "rest"): def test_get_snapshot_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7948,7 +8396,7 @@ def test_get_snapshot_rest_error(): ) def test_create_snapshot_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8071,7 +8519,7 @@ def test_create_snapshot_rest_required_fields( assert "snapshotId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8083,7 +8531,7 @@ def test_create_snapshot_rest_required_fields( jsonified_request["snapshotId"] = "snapshot_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_snapshot._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("snapshot_id",)) @@ -8096,7 +8544,7 @@ def test_create_snapshot_rest_required_fields( assert jsonified_request["snapshotId"] == "snapshot_id_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8142,7 +8590,7 @@ def test_create_snapshot_rest_required_fields( def test_create_snapshot_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_snapshot._get_unset_required_fields({}) @@ -8161,7 +8609,7 @@ def test_create_snapshot_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_snapshot_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -8221,7 +8669,7 @@ def test_create_snapshot_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.CreateSnapshotRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8243,7 +8691,7 @@ def test_create_snapshot_rest_bad_request( def test_create_snapshot_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8287,7 +8735,7 @@ def test_create_snapshot_rest_flattened(): def test_create_snapshot_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8304,7 +8752,7 @@ def test_create_snapshot_rest_flattened_error(transport: str = "rest"): def test_create_snapshot_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8317,7 +8765,7 @@ def test_create_snapshot_rest_error(): ) def test_delete_snapshot_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8365,7 +8813,7 @@ def test_delete_snapshot_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8374,7 +8822,7 @@ def test_delete_snapshot_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8383,7 +8831,7 @@ def test_delete_snapshot_rest_required_fields( assert jsonified_request["name"] == "name_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8422,7 +8870,7 @@ def test_delete_snapshot_rest_required_fields( def test_delete_snapshot_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_snapshot._get_unset_required_fields({}) @@ -8432,7 +8880,7 @@ def test_delete_snapshot_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_snapshot_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -8492,7 +8940,7 @@ def test_delete_snapshot_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.DeleteSnapshotRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8516,7 +8964,7 @@ def test_delete_snapshot_rest_bad_request( def test_delete_snapshot_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8558,7 +9006,7 @@ def test_delete_snapshot_rest_flattened(): def test_delete_snapshot_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8573,7 +9021,7 @@ def test_delete_snapshot_rest_flattened_error(transport: str = "rest"): def test_delete_snapshot_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8586,7 +9034,7 @@ def test_delete_snapshot_rest_error(): ) def test_update_snapshot_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8710,14 +9158,14 @@ def test_update_snapshot_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_snapshot._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_snapshot._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -8726,7 +9174,7 @@ def test_update_snapshot_rest_required_fields( # verify required fields with non-default values are left alone client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8766,7 +9214,7 @@ def test_update_snapshot_rest_required_fields( def test_update_snapshot_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_snapshot._get_unset_required_fields({}) @@ -8784,7 +9232,7 @@ def test_update_snapshot_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_snapshot_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -8844,7 +9292,7 @@ def test_update_snapshot_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.UpdateSnapshotRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8870,7 +9318,7 @@ def test_update_snapshot_rest_bad_request( def test_update_snapshot_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8915,7 +9363,7 @@ def test_update_snapshot_rest_flattened(): def test_update_snapshot_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8931,7 +9379,7 @@ def test_update_snapshot_rest_flattened_error(transport: str = "rest"): def test_update_snapshot_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8944,7 +9392,7 @@ def test_update_snapshot_rest_error(): ) def test_list_backups_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8997,7 +9445,7 @@ def test_list_backups_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_backups._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9006,7 +9454,7 @@ def test_list_backups_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_backups._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -9024,7 +9472,7 @@ def test_list_backups_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9066,7 +9514,7 @@ def test_list_backups_rest_required_fields( def test_list_backups_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_backups._get_unset_required_fields({}) @@ -9086,7 +9534,7 @@ def test_list_backups_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_backups_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -9144,7 +9592,7 @@ def test_list_backups_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.ListBackupsRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9166,7 +9614,7 @@ def test_list_backups_rest_bad_request( def test_list_backups_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9207,7 +9655,7 @@ def test_list_backups_rest_flattened(): def test_list_backups_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9222,7 +9670,7 @@ def test_list_backups_rest_flattened_error(transport: str = "rest"): def test_list_backups_rest_pager(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9292,7 +9740,7 @@ def test_list_backups_rest_pager(transport: str = "rest"): ) def test_get_backup_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9365,7 +9813,7 @@ def test_get_backup_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9374,7 +9822,7 @@ def test_get_backup_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9383,7 +9831,7 @@ def test_get_backup_rest_required_fields( assert jsonified_request["name"] == "name_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9425,7 +9873,7 @@ def test_get_backup_rest_required_fields( def test_get_backup_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_backup._get_unset_required_fields({}) @@ -9435,7 +9883,7 @@ def test_get_backup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_backup_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -9493,7 +9941,7 @@ def test_get_backup_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.GetBackupRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9515,7 +9963,7 @@ def test_get_backup_rest_bad_request( def test_get_backup_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9556,7 +10004,7 @@ def test_get_backup_rest_flattened(): def test_get_backup_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9571,7 +10019,7 @@ def test_get_backup_rest_flattened_error(transport: str = "rest"): def test_get_backup_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9584,7 +10032,7 @@ def test_get_backup_rest_error(): ) def test_create_backup_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9715,7 +10163,7 @@ def test_create_backup_rest_required_fields( assert "backupId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9727,7 +10175,7 @@ def test_create_backup_rest_required_fields( jsonified_request["backupId"] = "backup_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_backup._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("backup_id",)) @@ -9740,7 +10188,7 @@ def test_create_backup_rest_required_fields( assert jsonified_request["backupId"] == "backup_id_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9786,7 +10234,7 @@ def test_create_backup_rest_required_fields( def test_create_backup_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_backup._get_unset_required_fields({}) @@ -9805,7 +10253,7 @@ def test_create_backup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_backup_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -9865,7 +10313,7 @@ def test_create_backup_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.CreateBackupRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9887,7 +10335,7 @@ def test_create_backup_rest_bad_request( def test_create_backup_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9928,7 +10376,7 @@ def test_create_backup_rest_flattened(): def test_create_backup_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9945,7 +10393,7 @@ def test_create_backup_rest_flattened_error(transport: str = "rest"): def test_create_backup_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9958,7 +10406,7 @@ def test_create_backup_rest_error(): ) def test_delete_backup_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10004,7 +10452,7 @@ def test_delete_backup_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10013,7 +10461,7 @@ def test_delete_backup_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10022,7 +10470,7 @@ def test_delete_backup_rest_required_fields( assert jsonified_request["name"] == "name_value" client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10061,7 +10509,7 @@ def test_delete_backup_rest_required_fields( def test_delete_backup_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_backup._get_unset_required_fields({}) @@ -10071,7 +10519,7 @@ def test_delete_backup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_backup_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -10131,7 +10579,7 @@ def test_delete_backup_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.DeleteBackupRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10153,7 +10601,7 @@ def test_delete_backup_rest_bad_request( def test_delete_backup_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10192,7 +10640,7 @@ def test_delete_backup_rest_flattened(): def test_delete_backup_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10207,7 +10655,7 @@ def test_delete_backup_rest_flattened_error(transport: str = "rest"): def test_delete_backup_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10220,7 +10668,7 @@ def test_delete_backup_rest_error(): ) def test_update_backup_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10350,14 +10798,14 @@ def test_update_backup_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_backup._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -10366,7 +10814,7 @@ def test_update_backup_rest_required_fields( # verify required fields with non-default values are left alone client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10406,7 +10854,7 @@ def test_update_backup_rest_required_fields( def test_update_backup_rest_unset_required_fields(): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_backup._get_unset_required_fields({}) @@ -10424,7 +10872,7 @@ def test_update_backup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_backup_rest_interceptors(null_interceptor): transport = transports.CloudFilestoreManagerRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFilestoreManagerRestInterceptor(), @@ -10484,7 +10932,7 @@ def test_update_backup_rest_bad_request( transport: str = "rest", request_type=cloud_filestore_service.UpdateBackupRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10508,7 +10956,7 @@ def test_update_backup_rest_bad_request( def test_update_backup_rest_flattened(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10551,7 +10999,7 @@ def test_update_backup_rest_flattened(): def test_update_backup_rest_flattened_error(transport: str = "rest"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10567,24 +11015,24 @@ def test_update_backup_rest_flattened_error(transport: str = "rest"): def test_update_backup_rest_error(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CloudFilestoreManagerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.CloudFilestoreManagerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CloudFilestoreManagerClient( @@ -10594,7 +11042,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.CloudFilestoreManagerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -10605,16 +11053,17 @@ 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 = CloudFilestoreManagerClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.CloudFilestoreManagerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CloudFilestoreManagerClient( @@ -10626,7 +11075,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CloudFilestoreManagerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = CloudFilestoreManagerClient(transport=transport) assert client.transport is transport @@ -10635,13 +11084,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CloudFilestoreManagerGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.CloudFilestoreManagerGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -10658,7 +11107,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -10672,7 +11121,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = CloudFilestoreManagerClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -10680,7 +11129,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -10692,7 +11141,7 @@ def test_cloud_filestore_manager_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.CloudFilestoreManagerTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -10704,7 +11153,7 @@ def test_cloud_filestore_manager_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CloudFilestoreManagerTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -10763,7 +11212,7 @@ def test_cloud_filestore_manager_base_transport_with_credentials_file(): "google.cloud.filestore_v1.services.cloud_filestore_manager.transports.CloudFilestoreManagerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CloudFilestoreManagerTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -10782,7 +11231,7 @@ def test_cloud_filestore_manager_base_transport_with_adc(): "google.cloud.filestore_v1.services.cloud_filestore_manager.transports.CloudFilestoreManagerTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CloudFilestoreManagerTransport() adc.assert_called_once() @@ -10790,7 +11239,7 @@ def test_cloud_filestore_manager_base_transport_with_adc(): def test_cloud_filestore_manager_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) CloudFilestoreManagerClient() adc.assert_called_once_with( scopes=None, @@ -10810,7 +11259,7 @@ def test_cloud_filestore_manager_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -10859,7 +11308,7 @@ def test_cloud_filestore_manager_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10889,7 +11338,7 @@ def test_cloud_filestore_manager_transport_create_channel( def test_cloud_filestore_manager_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -10927,7 +11376,7 @@ def test_cloud_filestore_manager_grpc_transport_client_cert_source_for_mtls( def test_cloud_filestore_manager_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -10939,7 +11388,7 @@ def test_cloud_filestore_manager_http_transport_client_cert_source_for_mtls(): def test_cloud_filestore_manager_rest_lro_client(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -10964,7 +11413,7 @@ def test_cloud_filestore_manager_rest_lro_client(): ) def test_cloud_filestore_manager_host_no_port(transport_name): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions(api_endpoint="file.googleapis.com"), transport=transport_name, ) @@ -10985,7 +11434,7 @@ def test_cloud_filestore_manager_host_no_port(transport_name): ) def test_cloud_filestore_manager_host_with_port(transport_name): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="file.googleapis.com:8000" ), @@ -11005,8 +11454,8 @@ def test_cloud_filestore_manager_host_with_port(transport_name): ], ) def test_cloud_filestore_manager_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = CloudFilestoreManagerClient( credentials=creds1, transport=transport_name, @@ -11118,7 +11567,7 @@ def test_cloud_filestore_manager_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -11196,7 +11645,7 @@ def test_cloud_filestore_manager_transport_channel_mtls_with_adc(transport_class def test_cloud_filestore_manager_grpc_lro_client(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -11213,7 +11662,7 @@ def test_cloud_filestore_manager_grpc_lro_client(): def test_cloud_filestore_manager_grpc_lro_async_client(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -11421,7 +11870,7 @@ def test_client_with_default_client_info(): transports.CloudFilestoreManagerTransport, "_prep_wrapped_messages" ) as prep: client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -11431,7 +11880,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = CloudFilestoreManagerClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -11440,7 +11889,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -11455,7 +11904,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11485,7 +11934,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -11513,7 +11962,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11541,7 +11990,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -11569,7 +12018,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11599,7 +12048,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -11627,7 +12076,7 @@ def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11657,7 +12106,7 @@ def test_delete_operation_rest_bad_request( ) def test_delete_operation_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -11685,7 +12134,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11715,7 +12164,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -11743,7 +12192,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11773,7 +12222,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -11799,7 +12248,7 @@ def test_list_operations_rest(request_type): def test_delete_operation(transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11824,7 +12273,7 @@ def test_delete_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_delete_operation_async(transport: str = "grpc_asyncio"): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11848,7 +12297,7 @@ async def test_delete_operation_async(transport: str = "grpc_asyncio"): def test_delete_operation_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11877,7 +12326,7 @@ def test_delete_operation_field_headers(): @pytest.mark.asyncio async def test_delete_operation_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11904,7 +12353,7 @@ async def test_delete_operation_field_headers_async(): def test_delete_operation_from_dict(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -11922,7 +12371,7 @@ def test_delete_operation_from_dict(): @pytest.mark.asyncio async def test_delete_operation_from_dict_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -11938,7 +12387,7 @@ async def test_delete_operation_from_dict_async(): def test_cancel_operation(transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11963,7 +12412,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11987,7 +12436,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12016,7 +12465,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12043,7 +12492,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -12061,7 +12510,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -12077,7 +12526,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12102,7 +12551,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12128,7 +12577,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12157,7 +12606,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12186,7 +12635,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -12204,7 +12653,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -12222,7 +12671,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12247,7 +12696,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12273,7 +12722,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12302,7 +12751,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12331,7 +12780,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -12349,7 +12798,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -12367,7 +12816,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12392,7 +12841,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12418,7 +12867,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12447,7 +12896,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12476,7 +12925,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12494,7 +12943,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12512,7 +12961,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12537,7 +12986,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12563,7 +13012,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12592,7 +13041,7 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -12621,7 +13070,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12639,7 +13088,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = CloudFilestoreManagerAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -12663,7 +13112,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -12680,7 +13129,7 @@ def test_client_ctx(): ] for transport in transports: client = CloudFilestoreManagerClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -12714,7 +13163,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, diff --git a/packages/google-cloud-functions/google/cloud/functions/gapic_version.py b/packages/google-cloud-functions/google/cloud/functions/gapic_version.py index ae06408a02c4..360a0d13ebdd 100644 --- a/packages/google-cloud-functions/google/cloud/functions/gapic_version.py +++ b/packages/google-cloud-functions/google/cloud/functions/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.15.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/gapic_version.py b/packages/google-cloud-functions/google/cloud/functions_v1/gapic_version.py index ae06408a02c4..360a0d13ebdd 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/gapic_version.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.15.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/async_client.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/async_client.py index 181e648e8a45..85d501b55526 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/async_client.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.functions_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -67,8 +67,12 @@ class CloudFunctionsServiceAsyncClient: _client: CloudFunctionsServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = CloudFunctionsServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = CloudFunctionsServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = CloudFunctionsServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = CloudFunctionsServiceClient._DEFAULT_UNIVERSE cloud_function_path = staticmethod(CloudFunctionsServiceClient.cloud_function_path) parse_cloud_function_path = staticmethod( @@ -187,6 +191,25 @@ def transport(self) -> CloudFunctionsServiceTransport: """ 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(CloudFunctionsServiceClient).get_transport_class, type(CloudFunctionsServiceClient), @@ -200,7 +223,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the cloud functions service client. + """Instantiates the cloud functions service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -211,23 +234,38 @@ def __init__( transport (Union[str, ~.CloudFunctionsServiceTransport]): 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. @@ -320,6 +358,9 @@ async def sample_list_functions(): 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, @@ -443,6 +484,9 @@ async def sample_get_function(): 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, @@ -566,6 +610,9 @@ async def sample_create_function(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -697,6 +744,9 @@ async def sample_update_function(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -833,6 +883,9 @@ async def sample_delete_function(): 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, @@ -954,6 +1007,9 @@ async def sample_call_function(): 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, @@ -1057,6 +1113,9 @@ async def sample_generate_upload_url(): 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, @@ -1139,6 +1198,9 @@ async def sample_generate_download_url(): 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, @@ -1251,6 +1313,9 @@ async def sample_set_iam_policy(): gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1364,6 +1429,9 @@ async def sample_get_iam_policy(): gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1448,6 +1516,9 @@ async def sample_test_iam_permissions(): gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1502,6 +1573,9 @@ async def list_operations( 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, @@ -1556,6 +1630,9 @@ async def get_operation( 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, @@ -1610,6 +1687,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/client.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/client.py index e0e17d67f39d..67b1631bd0dd 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/client.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.functions_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -137,11 +138,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 = "cloudfunctions.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "cloudfunctions.{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 @@ -340,7 +345,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 @@ -370,6 +375,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") @@ -403,6 +413,177 @@ 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 + + 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 + + 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 = CloudFunctionsServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = CloudFunctionsServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = ( + CloudFunctionsServiceClient._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 = CloudFunctionsServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = CloudFunctionsServiceClient._DEFAULT_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 CloudFunctionsServiceClient._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, *, @@ -422,22 +603,32 @@ def __init__( transport (Union[str, CloudFunctionsServiceTransport]): 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. @@ -448,17 +639,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, + ) = CloudFunctionsServiceClient._read_environment_variables() + self._client_cert_source = CloudFunctionsServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = CloudFunctionsServiceClient._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" @@ -467,20 +675,33 @@ 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, CloudFunctionsServiceTransport): + transport_provided = isinstance(transport, CloudFunctionsServiceTransport) + if transport_provided: # transport is a CloudFunctionsServiceTransport 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(CloudFunctionsServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or CloudFunctionsServiceClient._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( @@ -490,17 +711,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_functions( @@ -575,6 +796,9 @@ def sample_list_functions(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -688,6 +912,9 @@ def sample_get_function(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -811,6 +1038,9 @@ def sample_create_function(): gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -932,6 +1162,9 @@ def sample_update_function(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1058,6 +1291,9 @@ def sample_delete_function(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1179,6 +1415,9 @@ def sample_call_function(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1283,6 +1522,9 @@ def sample_generate_upload_url(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1366,6 +1608,9 @@ def sample_generate_download_url(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1477,6 +1722,9 @@ def sample_set_iam_policy(): gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1589,6 +1837,9 @@ def sample_get_iam_policy(): gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1672,6 +1923,9 @@ def sample_test_iam_permissions(): gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1739,6 +1993,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1793,6 +2050,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1847,6 +2107,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py index 6fbee7294033..8e5167049b7f 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/base.py @@ -60,7 +60,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'cloudfunctions.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 @@ -123,6 +123,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-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py index dcffa3341a74..19dc8e676e2f 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc.py @@ -68,7 +68,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'cloudfunctions.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-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py index 785aba359d86..68be98dfca59 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/grpc_asyncio.py @@ -113,7 +113,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'cloudfunctions.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-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/rest.py b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/rest.py index 9d5a77ba1a78..d85637362eba 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/rest.py +++ b/packages/google-cloud-functions/google/cloud/functions_v1/services/cloud_functions_service/transports/rest.py @@ -40,9 +40,9 @@ from requests import __version__ as requests_version 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.iam.v1 import iam_policy_pb2 # type: ignore @@ -527,7 +527,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'cloudfunctions.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-functions/google/cloud/functions_v2/gapic_version.py b/packages/google-cloud-functions/google/cloud/functions_v2/gapic_version.py index ae06408a02c4..360a0d13ebdd 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/gapic_version.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.15.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/async_client.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/async_client.py index 661a8054d761..0cc681d768d6 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/async_client.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.functions_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -71,8 +71,12 @@ class FunctionServiceAsyncClient: _client: FunctionServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = FunctionServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = FunctionServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = FunctionServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = FunctionServiceClient._DEFAULT_UNIVERSE build_path = staticmethod(FunctionServiceClient.build_path) parse_build_path = staticmethod(FunctionServiceClient.parse_build_path) @@ -197,6 +201,25 @@ def transport(self) -> FunctionServiceTransport: """ 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(FunctionServiceClient).get_transport_class, type(FunctionServiceClient) ) @@ -209,7 +232,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the function service client. + """Instantiates the function service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -220,23 +243,38 @@ def __init__( transport (Union[str, ~.FunctionServiceTransport]): 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. @@ -341,6 +379,9 @@ async def sample_get_function(): 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, @@ -452,6 +493,9 @@ async def sample_list_functions(): 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, @@ -593,6 +637,9 @@ async def sample_create_function(): 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, @@ -722,6 +769,9 @@ async def sample_update_function(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -848,6 +898,9 @@ async def sample_delete_function(): 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, @@ -958,6 +1011,9 @@ async def sample_generate_upload_url(): 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, @@ -1041,6 +1097,9 @@ async def sample_generate_download_url(): 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, @@ -1142,6 +1201,9 @@ async def sample_list_runtimes(): 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, @@ -1196,6 +1258,9 @@ async def list_operations( 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, @@ -1250,6 +1315,9 @@ async def get_operation( 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, @@ -1370,6 +1438,9 @@ async def set_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1491,6 +1562,9 @@ async def get_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1550,6 +1624,9 @@ async def test_iam_permissions( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1604,6 +1681,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/client.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/client.py index 9c2afa1c8e79..abc0ae7deb21 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/client.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.functions_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -141,11 +142,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 = "cloudfunctions.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "cloudfunctions.{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 @@ -495,7 +500,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 @@ -525,6 +530,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") @@ -558,6 +568,175 @@ 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 + + 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 + + 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 = FunctionServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = FunctionServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = FunctionServiceClient._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 = FunctionServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = FunctionServiceClient._DEFAULT_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 FunctionServiceClient._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, *, @@ -577,22 +756,32 @@ def __init__( transport (Union[str, FunctionServiceTransport]): 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. @@ -603,17 +792,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, + ) = FunctionServiceClient._read_environment_variables() + self._client_cert_source = FunctionServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = FunctionServiceClient._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" @@ -622,20 +828,33 @@ 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, FunctionServiceTransport): + transport_provided = isinstance(transport, FunctionServiceTransport) + if transport_provided: # transport is a FunctionServiceTransport 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(FunctionServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or FunctionServiceClient._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( @@ -645,17 +864,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 get_function( @@ -751,6 +970,9 @@ def sample_get_function(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -862,6 +1084,9 @@ def sample_list_functions(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1003,6 +1228,9 @@ def sample_create_function(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1132,6 +1360,9 @@ def sample_update_function(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1258,6 +1489,9 @@ def sample_delete_function(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1369,6 +1603,9 @@ def sample_generate_upload_url(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1453,6 +1690,9 @@ def sample_generate_download_url(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1554,6 +1794,9 @@ def sample_list_runtimes(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1621,6 +1864,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1675,6 +1921,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1795,6 +2044,9 @@ def set_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1916,6 +2168,9 @@ def get_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1975,6 +2230,9 @@ def test_iam_permissions( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2029,6 +2287,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/base.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/base.py index c88b956f13a7..06834d787a95 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/base.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/base.py @@ -60,7 +60,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'cloudfunctions.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 @@ -123,6 +123,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-functions/google/cloud/functions_v2/services/function_service/transports/grpc.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc.py index 5b18566a3a9a..4e4de2791bba 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc.py @@ -72,7 +72,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'cloudfunctions.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-functions/google/cloud/functions_v2/services/function_service/transports/grpc_asyncio.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc_asyncio.py index 6e4901bc1fd3..9a1d91a727c4 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/grpc_asyncio.py @@ -117,7 +117,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'cloudfunctions.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-functions/google/cloud/functions_v2/services/function_service/transports/rest.py b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/rest.py index a9f83621991a..aa896ee93099 100644 --- a/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/rest.py +++ b/packages/google-cloud-functions/google/cloud/functions_v2/services/function_service/transports/rest.py @@ -40,9 +40,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -503,7 +503,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'cloudfunctions.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-functions/samples/generated_samples/snippet_metadata_google.cloud.functions.v1.json b/packages/google-cloud-functions/samples/generated_samples/snippet_metadata_google.cloud.functions.v1.json index 1cf26eb30175..3a16e5fca57c 100644 --- a/packages/google-cloud-functions/samples/generated_samples/snippet_metadata_google.cloud.functions.v1.json +++ b/packages/google-cloud-functions/samples/generated_samples/snippet_metadata_google.cloud.functions.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-functions", - "version": "1.15.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-functions/samples/generated_samples/snippet_metadata_google.cloud.functions.v2.json b/packages/google-cloud-functions/samples/generated_samples/snippet_metadata_google.cloud.functions.v2.json index 36d43d148ffa..0dbb0a2efac1 100644 --- a/packages/google-cloud-functions/samples/generated_samples/snippet_metadata_google.cloud.functions.v2.json +++ b/packages/google-cloud-functions/samples/generated_samples/snippet_metadata_google.cloud.functions.v2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-functions", - "version": "1.15.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-functions/tests/unit/gapic/functions_v1/test_cloud_functions_service.py b/packages/google-cloud-functions/tests/unit/gapic/functions_v1/test_cloud_functions_service.py index 87de2216f376..d76d86904441 100644 --- a/packages/google-cloud-functions/tests/unit/gapic/functions_v1/test_cloud_functions_service.py +++ b/packages/google-cloud-functions/tests/unit/gapic/functions_v1/test_cloud_functions_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -85,6 +85,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -115,6 +138,291 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert CloudFunctionsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert CloudFunctionsServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert CloudFunctionsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + CloudFunctionsServiceClient._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 CloudFunctionsServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert CloudFunctionsServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert CloudFunctionsServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + CloudFunctionsServiceClient._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 CloudFunctionsServiceClient._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 CloudFunctionsServiceClient._get_client_cert_source(None, False) is None + assert ( + CloudFunctionsServiceClient._get_client_cert_source( + mock_provided_cert_source, False + ) + is None + ) + assert ( + CloudFunctionsServiceClient._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 ( + CloudFunctionsServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + CloudFunctionsServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + CloudFunctionsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFunctionsServiceClient), +) +@mock.patch.object( + CloudFunctionsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFunctionsServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = CloudFunctionsServiceClient._DEFAULT_UNIVERSE + default_endpoint = CloudFunctionsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CloudFunctionsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + CloudFunctionsServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + CloudFunctionsServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == CloudFunctionsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CloudFunctionsServiceClient._get_api_endpoint( + None, None, default_universe, "auto" + ) + == default_endpoint + ) + assert ( + CloudFunctionsServiceClient._get_api_endpoint( + None, None, default_universe, "always" + ) + == CloudFunctionsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CloudFunctionsServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == CloudFunctionsServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + CloudFunctionsServiceClient._get_api_endpoint( + None, None, mock_universe, "never" + ) + == mock_endpoint + ) + assert ( + CloudFunctionsServiceClient._get_api_endpoint( + None, None, default_universe, "never" + ) + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + CloudFunctionsServiceClient._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 ( + CloudFunctionsServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + CloudFunctionsServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + CloudFunctionsServiceClient._get_universe_domain(None, None) + == CloudFunctionsServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + CloudFunctionsServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + CloudFunctionsServiceClient, + transports.CloudFunctionsServiceGrpcTransport, + "grpc", + ), + ( + CloudFunctionsServiceClient, + transports.CloudFunctionsServiceRestTransport, + "rest", + ), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -126,7 +434,7 @@ def test__get_default_mtls_endpoint(): def test_cloud_functions_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -180,7 +488,7 @@ def test_cloud_functions_service_client_service_account_always_use_jwt( def test_cloud_functions_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -238,20 +546,22 @@ def test_cloud_functions_service_client_get_transport_class(): ) @mock.patch.object( CloudFunctionsServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CloudFunctionsServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFunctionsServiceClient), ) @mock.patch.object( CloudFunctionsServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CloudFunctionsServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFunctionsServiceAsyncClient), ) def test_cloud_functions_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(CloudFunctionsServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -286,7 +596,9 @@ def test_cloud_functions_service_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, @@ -316,15 +628,23 @@ def test_cloud_functions_service_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") @@ -334,7 +654,9 @@ def test_cloud_functions_service_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", @@ -352,7 +674,9 @@ def test_cloud_functions_service_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, @@ -405,13 +729,13 @@ def test_cloud_functions_service_client_client_options( ) @mock.patch.object( CloudFunctionsServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CloudFunctionsServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFunctionsServiceClient), ) @mock.patch.object( CloudFunctionsServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(CloudFunctionsServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFunctionsServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_cloud_functions_service_client_mtls_env_auto( @@ -434,7 +758,9 @@ def test_cloud_functions_service_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 @@ -466,7 +792,9 @@ def test_cloud_functions_service_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 @@ -500,7 +828,9 @@ def test_cloud_functions_service_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, @@ -590,6 +920,118 @@ def test_cloud_functions_service_client_get_mtls_endpoint_and_cert_source(client 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", [CloudFunctionsServiceClient, CloudFunctionsServiceAsyncClient] +) +@mock.patch.object( + CloudFunctionsServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFunctionsServiceClient), +) +@mock.patch.object( + CloudFunctionsServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(CloudFunctionsServiceAsyncClient), +) +def test_cloud_functions_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = CloudFunctionsServiceClient._DEFAULT_UNIVERSE + default_endpoint = CloudFunctionsServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = CloudFunctionsServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -624,7 +1066,9 @@ def test_cloud_functions_service_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, @@ -669,7 +1113,9 @@ def test_cloud_functions_service_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, @@ -729,7 +1175,9 @@ def test_cloud_functions_service_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, @@ -746,8 +1194,8 @@ def test_cloud_functions_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -776,7 +1224,7 @@ def test_cloud_functions_service_client_create_channel_credentials_file( ) def test_list_functions(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -808,7 +1256,7 @@ def test_list_functions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -825,7 +1273,7 @@ async def test_list_functions_async( transport: str = "grpc_asyncio", request_type=functions.ListFunctionsRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -862,7 +1310,7 @@ async def test_list_functions_async_from_dict(): def test_list_functions_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -892,7 +1340,7 @@ def test_list_functions_field_headers(): @pytest.mark.asyncio async def test_list_functions_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -923,7 +1371,7 @@ async def test_list_functions_field_headers_async(): def test_list_functions_pager(transport_name: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -973,7 +1421,7 @@ def test_list_functions_pager(transport_name: str = "grpc"): def test_list_functions_pages(transport_name: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1015,7 +1463,7 @@ def test_list_functions_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_functions_async_pager(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1065,7 +1513,7 @@ async def test_list_functions_async_pager(): @pytest.mark.asyncio async def test_list_functions_async_pages(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1120,7 +1568,7 @@ async def test_list_functions_async_pages(): ) def test_get_function(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1199,7 +1647,7 @@ def test_get_function_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1216,7 +1664,7 @@ async def test_get_function_async( transport: str = "grpc_asyncio", request_type=functions.GetFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1299,7 +1747,7 @@ async def test_get_function_async_from_dict(): def test_get_function_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1329,7 +1777,7 @@ def test_get_function_field_headers(): @pytest.mark.asyncio async def test_get_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1360,7 +1808,7 @@ async def test_get_function_field_headers_async(): def test_get_function_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1384,7 +1832,7 @@ def test_get_function_flattened(): def test_get_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1399,7 +1847,7 @@ def test_get_function_flattened_error(): @pytest.mark.asyncio async def test_get_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1428,7 +1876,7 @@ async def test_get_function_flattened_async(): @pytest.mark.asyncio async def test_get_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1449,7 +1897,7 @@ async def test_get_function_flattened_error_async(): ) def test_create_function(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1476,7 +1924,7 @@ def test_create_function_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1493,7 +1941,7 @@ async def test_create_function_async( transport: str = "grpc_asyncio", request_type=functions.CreateFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1525,7 +1973,7 @@ async def test_create_function_async_from_dict(): def test_create_function_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1555,7 +2003,7 @@ def test_create_function_field_headers(): @pytest.mark.asyncio async def test_create_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1586,7 +2034,7 @@ async def test_create_function_field_headers_async(): def test_create_function_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1614,7 +2062,7 @@ def test_create_function_flattened(): def test_create_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1630,7 +2078,7 @@ def test_create_function_flattened_error(): @pytest.mark.asyncio async def test_create_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1663,7 +2111,7 @@ async def test_create_function_flattened_async(): @pytest.mark.asyncio async def test_create_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1685,7 +2133,7 @@ async def test_create_function_flattened_error_async(): ) def test_update_function(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1712,7 +2160,7 @@ def test_update_function_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1729,7 +2177,7 @@ async def test_update_function_async( transport: str = "grpc_asyncio", request_type=functions.UpdateFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1761,7 +2209,7 @@ async def test_update_function_async_from_dict(): def test_update_function_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1791,7 +2239,7 @@ def test_update_function_field_headers(): @pytest.mark.asyncio async def test_update_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1822,7 +2270,7 @@ async def test_update_function_field_headers_async(): def test_update_function_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1846,7 +2294,7 @@ def test_update_function_flattened(): def test_update_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1861,7 +2309,7 @@ def test_update_function_flattened_error(): @pytest.mark.asyncio async def test_update_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1890,7 +2338,7 @@ async def test_update_function_flattened_async(): @pytest.mark.asyncio async def test_update_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1911,7 +2359,7 @@ async def test_update_function_flattened_error_async(): ) def test_delete_function(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1938,7 +2386,7 @@ def test_delete_function_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1955,7 +2403,7 @@ async def test_delete_function_async( transport: str = "grpc_asyncio", request_type=functions.DeleteFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1987,7 +2435,7 @@ async def test_delete_function_async_from_dict(): def test_delete_function_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2017,7 +2465,7 @@ def test_delete_function_field_headers(): @pytest.mark.asyncio async def test_delete_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2048,7 +2496,7 @@ async def test_delete_function_field_headers_async(): def test_delete_function_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2072,7 +2520,7 @@ def test_delete_function_flattened(): def test_delete_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2087,7 +2535,7 @@ def test_delete_function_flattened_error(): @pytest.mark.asyncio async def test_delete_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2116,7 +2564,7 @@ async def test_delete_function_flattened_async(): @pytest.mark.asyncio async def test_delete_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2137,7 +2585,7 @@ async def test_delete_function_flattened_error_async(): ) def test_call_function(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2171,7 +2619,7 @@ def test_call_function_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2188,7 +2636,7 @@ async def test_call_function_async( transport: str = "grpc_asyncio", request_type=functions.CallFunctionRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2227,7 +2675,7 @@ async def test_call_function_async_from_dict(): def test_call_function_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2257,7 +2705,7 @@ def test_call_function_field_headers(): @pytest.mark.asyncio async def test_call_function_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2288,7 +2736,7 @@ async def test_call_function_field_headers_async(): def test_call_function_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2316,7 +2764,7 @@ def test_call_function_flattened(): def test_call_function_flattened_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2332,7 +2780,7 @@ def test_call_function_flattened_error(): @pytest.mark.asyncio async def test_call_function_flattened_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2365,7 +2813,7 @@ async def test_call_function_flattened_async(): @pytest.mark.asyncio async def test_call_function_flattened_error_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2387,7 +2835,7 @@ async def test_call_function_flattened_error_async(): ) def test_generate_upload_url(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2419,7 +2867,7 @@ def test_generate_upload_url_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2438,7 +2886,7 @@ async def test_generate_upload_url_async( transport: str = "grpc_asyncio", request_type=functions.GenerateUploadUrlRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2475,7 +2923,7 @@ async def test_generate_upload_url_async_from_dict(): def test_generate_upload_url_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2507,7 +2955,7 @@ def test_generate_upload_url_field_headers(): @pytest.mark.asyncio async def test_generate_upload_url_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2547,7 +2995,7 @@ async def test_generate_upload_url_field_headers_async(): ) def test_generate_download_url(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2579,7 +3027,7 @@ def test_generate_download_url_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2598,7 +3046,7 @@ async def test_generate_download_url_async( transport: str = "grpc_asyncio", request_type=functions.GenerateDownloadUrlRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2635,7 +3083,7 @@ async def test_generate_download_url_async_from_dict(): def test_generate_download_url_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2667,7 +3115,7 @@ def test_generate_download_url_field_headers(): @pytest.mark.asyncio async def test_generate_download_url_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2707,7 +3155,7 @@ async def test_generate_download_url_field_headers_async(): ) def test_set_iam_policy(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2739,7 +3187,7 @@ def test_set_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2756,7 +3204,7 @@ async def test_set_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2793,7 +3241,7 @@ async def test_set_iam_policy_async_from_dict(): def test_set_iam_policy_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2823,7 +3271,7 @@ def test_set_iam_policy_field_headers(): @pytest.mark.asyncio async def test_set_iam_policy_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2852,7 +3300,7 @@ async def test_set_iam_policy_field_headers_async(): def test_set_iam_policy_from_dict_foreign(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -2877,7 +3325,7 @@ def test_set_iam_policy_from_dict_foreign(): ) def test_get_iam_policy(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2909,7 +3357,7 @@ def test_get_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2926,7 +3374,7 @@ async def test_get_iam_policy_async( transport: str = "grpc_asyncio", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2963,7 +3411,7 @@ async def test_get_iam_policy_async_from_dict(): def test_get_iam_policy_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2993,7 +3441,7 @@ def test_get_iam_policy_field_headers(): @pytest.mark.asyncio async def test_get_iam_policy_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3022,7 +3470,7 @@ async def test_get_iam_policy_field_headers_async(): def test_get_iam_policy_from_dict_foreign(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -3046,7 +3494,7 @@ def test_get_iam_policy_from_dict_foreign(): ) def test_test_iam_permissions(request_type, transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3078,7 +3526,7 @@ def test_test_iam_permissions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3098,7 +3546,7 @@ async def test_test_iam_permissions_async( request_type=iam_policy_pb2.TestIamPermissionsRequest, ): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3135,7 +3583,7 @@ async def test_test_iam_permissions_async_from_dict(): def test_test_iam_permissions_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3167,7 +3615,7 @@ def test_test_iam_permissions_field_headers(): @pytest.mark.asyncio async def test_test_iam_permissions_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3200,7 +3648,7 @@ async def test_test_iam_permissions_field_headers_async(): def test_test_iam_permissions_from_dict_foreign(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3226,7 +3674,7 @@ def test_test_iam_permissions_from_dict_foreign(): ) def test_list_functions_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3262,7 +3710,7 @@ def test_list_functions_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_functions_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -3318,7 +3766,7 @@ def test_list_functions_rest_bad_request( transport: str = "rest", request_type=functions.ListFunctionsRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3340,7 +3788,7 @@ def test_list_functions_rest_bad_request( def test_list_functions_rest_pager(transport: str = "rest"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3408,7 +3856,7 @@ def test_list_functions_rest_pager(transport: str = "rest"): ) def test_get_function_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3506,7 +3954,7 @@ def test_get_function_rest_required_fields(request_type=functions.GetFunctionReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3515,7 +3963,7 @@ def test_get_function_rest_required_fields(request_type=functions.GetFunctionReq jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_function._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("version_id",)) @@ -3526,7 +3974,7 @@ def test_get_function_rest_required_fields(request_type=functions.GetFunctionReq assert jsonified_request["name"] == "name_value" client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3568,7 +4016,7 @@ def test_get_function_rest_required_fields(request_type=functions.GetFunctionReq def test_get_function_rest_unset_required_fields(): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_function._get_unset_required_fields({}) @@ -3578,7 +4026,7 @@ def test_get_function_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_function_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -3634,7 +4082,7 @@ def test_get_function_rest_bad_request( transport: str = "rest", request_type=functions.GetFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3656,7 +4104,7 @@ def test_get_function_rest_bad_request( def test_get_function_rest_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3699,7 +4147,7 @@ def test_get_function_rest_flattened(): def test_get_function_rest_flattened_error(transport: str = "rest"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3714,7 +4162,7 @@ def test_get_function_rest_flattened_error(transport: str = "rest"): def test_get_function_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3727,7 +4175,7 @@ def test_get_function_rest_error(): ) def test_create_function_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3896,7 +4344,7 @@ def test_create_function_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3905,7 +4353,7 @@ def test_create_function_rest_required_fields( jsonified_request["location"] = "location_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3914,7 +4362,7 @@ def test_create_function_rest_required_fields( assert jsonified_request["location"] == "location_value" client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3954,7 +4402,7 @@ def test_create_function_rest_required_fields( def test_create_function_rest_unset_required_fields(): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_function._get_unset_required_fields({}) @@ -3972,7 +4420,7 @@ def test_create_function_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_function_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -4032,7 +4480,7 @@ def test_create_function_rest_bad_request( transport: str = "rest", request_type=functions.CreateFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4054,7 +4502,7 @@ def test_create_function_rest_bad_request( def test_create_function_rest_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4095,7 +4543,7 @@ def test_create_function_rest_flattened(): def test_create_function_rest_flattened_error(transport: str = "rest"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4111,7 +4559,7 @@ def test_create_function_rest_flattened_error(transport: str = "rest"): def test_create_function_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4124,7 +4572,7 @@ def test_create_function_rest_error(): ) def test_update_function_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4294,14 +4742,14 @@ def test_update_function_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_function._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -4310,7 +4758,7 @@ def test_update_function_rest_required_fields( # verify required fields with non-default values are left alone client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4350,7 +4798,7 @@ def test_update_function_rest_required_fields( def test_update_function_rest_unset_required_fields(): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_function._get_unset_required_fields({}) @@ -4360,7 +4808,7 @@ def test_update_function_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_function_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -4420,7 +4868,7 @@ def test_update_function_rest_bad_request( transport: str = "rest", request_type=functions.UpdateFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4444,7 +4892,7 @@ def test_update_function_rest_bad_request( def test_update_function_rest_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4486,7 +4934,7 @@ def test_update_function_rest_flattened(): def test_update_function_rest_flattened_error(transport: str = "rest"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4501,7 +4949,7 @@ def test_update_function_rest_flattened_error(transport: str = "rest"): def test_update_function_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4514,7 +4962,7 @@ def test_update_function_rest_error(): ) def test_delete_function_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4560,7 +5008,7 @@ def test_delete_function_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4569,7 +5017,7 @@ def test_delete_function_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4578,7 +5026,7 @@ def test_delete_function_rest_required_fields( assert jsonified_request["name"] == "name_value" client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4617,7 +5065,7 @@ def test_delete_function_rest_required_fields( def test_delete_function_rest_unset_required_fields(): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_function._get_unset_required_fields({}) @@ -4627,7 +5075,7 @@ def test_delete_function_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_function_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -4687,7 +5135,7 @@ def test_delete_function_rest_bad_request( transport: str = "rest", request_type=functions.DeleteFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4709,7 +5157,7 @@ def test_delete_function_rest_bad_request( def test_delete_function_rest_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4750,7 +5198,7 @@ def test_delete_function_rest_flattened(): def test_delete_function_rest_flattened_error(transport: str = "rest"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4765,7 +5213,7 @@ def test_delete_function_rest_flattened_error(transport: str = "rest"): def test_delete_function_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4778,7 +5226,7 @@ def test_delete_function_rest_error(): ) def test_call_function_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4832,7 +5280,7 @@ def test_call_function_rest_required_fields(request_type=functions.CallFunctionR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).call_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4842,7 +5290,7 @@ def test_call_function_rest_required_fields(request_type=functions.CallFunctionR jsonified_request["data"] = "data_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).call_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4853,7 +5301,7 @@ def test_call_function_rest_required_fields(request_type=functions.CallFunctionR assert jsonified_request["data"] == "data_value" client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4896,7 +5344,7 @@ def test_call_function_rest_required_fields(request_type=functions.CallFunctionR def test_call_function_rest_unset_required_fields(): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.call_function._get_unset_required_fields({}) @@ -4914,7 +5362,7 @@ def test_call_function_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_call_function_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -4970,7 +5418,7 @@ def test_call_function_rest_bad_request( transport: str = "rest", request_type=functions.CallFunctionRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4992,7 +5440,7 @@ def test_call_function_rest_bad_request( def test_call_function_rest_flattened(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5037,7 +5485,7 @@ def test_call_function_rest_flattened(): def test_call_function_rest_flattened_error(transport: str = "rest"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5053,7 +5501,7 @@ def test_call_function_rest_flattened_error(transport: str = "rest"): def test_call_function_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5066,7 +5514,7 @@ def test_call_function_rest_error(): ) def test_generate_upload_url_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5100,7 +5548,7 @@ def test_generate_upload_url_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_upload_url_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -5158,7 +5606,7 @@ def test_generate_upload_url_rest_bad_request( transport: str = "rest", request_type=functions.GenerateUploadUrlRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5180,7 +5628,7 @@ def test_generate_upload_url_rest_bad_request( def test_generate_upload_url_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5193,7 +5641,7 @@ def test_generate_upload_url_rest_error(): ) def test_generate_download_url_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5227,7 +5675,7 @@ def test_generate_download_url_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_download_url_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -5285,7 +5733,7 @@ def test_generate_download_url_rest_bad_request( transport: str = "rest", request_type=functions.GenerateDownloadUrlRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5307,7 +5755,7 @@ def test_generate_download_url_rest_bad_request( def test_generate_download_url_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5320,7 +5768,7 @@ def test_generate_download_url_rest_error(): ) def test_set_iam_policy_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5371,7 +5819,7 @@ def test_set_iam_policy_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_iam_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5380,7 +5828,7 @@ def test_set_iam_policy_rest_required_fields( jsonified_request["resource"] = "resource_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).set_iam_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5389,7 +5837,7 @@ def test_set_iam_policy_rest_required_fields( assert jsonified_request["resource"] == "resource_value" client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5430,7 +5878,7 @@ def test_set_iam_policy_rest_required_fields( def test_set_iam_policy_rest_unset_required_fields(): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.set_iam_policy._get_unset_required_fields({}) @@ -5448,7 +5896,7 @@ def test_set_iam_policy_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_set_iam_policy_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -5502,7 +5950,7 @@ def test_set_iam_policy_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5524,7 +5972,7 @@ def test_set_iam_policy_rest_bad_request( def test_set_iam_policy_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5537,7 +5985,7 @@ def test_set_iam_policy_rest_error(): ) def test_get_iam_policy_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5588,7 +6036,7 @@ def test_get_iam_policy_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_iam_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5597,7 +6045,7 @@ def test_get_iam_policy_rest_required_fields( jsonified_request["resource"] = "resource_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_iam_policy._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("options",)) @@ -5608,7 +6056,7 @@ def test_get_iam_policy_rest_required_fields( assert jsonified_request["resource"] == "resource_value" client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5648,7 +6096,7 @@ def test_get_iam_policy_rest_required_fields( def test_get_iam_policy_rest_unset_required_fields(): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_iam_policy._get_unset_required_fields({}) @@ -5658,7 +6106,7 @@ def test_get_iam_policy_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_iam_policy_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -5712,7 +6160,7 @@ def test_get_iam_policy_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5734,7 +6182,7 @@ def test_get_iam_policy_rest_bad_request( def test_get_iam_policy_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5747,7 +6195,7 @@ def test_get_iam_policy_rest_error(): ) def test_test_iam_permissions_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5797,7 +6245,7 @@ def test_test_iam_permissions_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).test_iam_permissions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5807,7 +6255,7 @@ def test_test_iam_permissions_rest_required_fields( jsonified_request["permissions"] = "permissions_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).test_iam_permissions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5818,7 +6266,7 @@ def test_test_iam_permissions_rest_required_fields( assert jsonified_request["permissions"] == "permissions_value" client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5859,7 +6307,7 @@ def test_test_iam_permissions_rest_required_fields( def test_test_iam_permissions_rest_unset_required_fields(): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.test_iam_permissions._get_unset_required_fields({}) @@ -5877,7 +6325,7 @@ def test_test_iam_permissions_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_test_iam_permissions_rest_interceptors(null_interceptor): transport = transports.CloudFunctionsServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.CloudFunctionsServiceRestInterceptor(), @@ -5933,7 +6381,7 @@ def test_test_iam_permissions_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.TestIamPermissionsRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5955,24 +6403,24 @@ def test_test_iam_permissions_rest_bad_request( def test_test_iam_permissions_rest_error(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CloudFunctionsServiceClient( @@ -5982,7 +6430,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5993,16 +6441,17 @@ 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 = CloudFunctionsServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = CloudFunctionsServiceClient( @@ -6014,7 +6463,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = CloudFunctionsServiceClient(transport=transport) assert client.transport is transport @@ -6023,13 +6472,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.CloudFunctionsServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.CloudFunctionsServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -6046,7 +6495,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -6060,7 +6509,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = CloudFunctionsServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -6068,7 +6517,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -6080,7 +6529,7 @@ def test_cloud_functions_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.CloudFunctionsServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -6092,7 +6541,7 @@ def test_cloud_functions_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.CloudFunctionsServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6142,7 +6591,7 @@ def test_cloud_functions_service_base_transport_with_credentials_file(): "google.cloud.functions_v1.services.cloud_functions_service.transports.CloudFunctionsServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CloudFunctionsServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6161,7 +6610,7 @@ def test_cloud_functions_service_base_transport_with_adc(): "google.cloud.functions_v1.services.cloud_functions_service.transports.CloudFunctionsServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.CloudFunctionsServiceTransport() adc.assert_called_once() @@ -6169,7 +6618,7 @@ def test_cloud_functions_service_base_transport_with_adc(): def test_cloud_functions_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) CloudFunctionsServiceClient() adc.assert_called_once_with( scopes=None, @@ -6189,7 +6638,7 @@ def test_cloud_functions_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -6238,7 +6687,7 @@ def test_cloud_functions_service_transport_create_channel( ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6268,7 +6717,7 @@ def test_cloud_functions_service_transport_create_channel( def test_cloud_functions_service_grpc_transport_client_cert_source_for_mtls( transport_class, ): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6306,7 +6755,7 @@ def test_cloud_functions_service_grpc_transport_client_cert_source_for_mtls( def test_cloud_functions_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -6318,7 +6767,7 @@ def test_cloud_functions_service_http_transport_client_cert_source_for_mtls(): def test_cloud_functions_service_rest_lro_client(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -6343,7 +6792,7 @@ def test_cloud_functions_service_rest_lro_client(): ) def test_cloud_functions_service_host_no_port(transport_name): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="cloudfunctions.googleapis.com" ), @@ -6366,7 +6815,7 @@ def test_cloud_functions_service_host_no_port(transport_name): ) def test_cloud_functions_service_host_with_port(transport_name): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="cloudfunctions.googleapis.com:8000" ), @@ -6386,8 +6835,8 @@ def test_cloud_functions_service_host_with_port(transport_name): ], ) def test_cloud_functions_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = CloudFunctionsServiceClient( credentials=creds1, transport=transport_name, @@ -6481,7 +6930,7 @@ def test_cloud_functions_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6559,7 +7008,7 @@ def test_cloud_functions_service_transport_channel_mtls_with_adc(transport_class def test_cloud_functions_service_grpc_lro_client(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -6576,7 +7025,7 @@ def test_cloud_functions_service_grpc_lro_client(): def test_cloud_functions_service_grpc_lro_async_client(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -6788,7 +7237,7 @@ def test_client_with_default_client_info(): transports.CloudFunctionsServiceTransport, "_prep_wrapped_messages" ) as prep: client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6798,7 +7247,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = CloudFunctionsServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6807,7 +7256,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6822,7 +7271,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6850,7 +7299,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6878,7 +7327,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6906,7 +7355,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "operations/sample1"} @@ -6934,7 +7383,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6962,7 +7411,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {} @@ -6988,7 +7437,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7013,7 +7462,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7039,7 +7488,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7068,7 +7517,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7097,7 +7546,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7115,7 +7564,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7133,7 +7582,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7158,7 +7607,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7184,7 +7633,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7213,7 +7662,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7242,7 +7691,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7260,7 +7709,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7278,7 +7727,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7303,7 +7752,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7329,7 +7778,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7358,7 +7807,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7387,7 +7836,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7405,7 +7854,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = CloudFunctionsServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -7429,7 +7878,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7446,7 +7895,7 @@ def test_client_ctx(): ] for transport in transports: client = CloudFunctionsServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7480,7 +7929,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, diff --git a/packages/google-cloud-functions/tests/unit/gapic/functions_v2/test_function_service.py b/packages/google-cloud-functions/tests/unit/gapic/functions_v2/test_function_service.py index e8003da27a69..f7afae097840 100644 --- a/packages/google-cloud-functions/tests/unit/gapic/functions_v2/test_function_service.py +++ b/packages/google-cloud-functions/tests/unit/gapic/functions_v2/test_function_service.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -83,6 +83,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -112,6 +135,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert FunctionServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert FunctionServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert FunctionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + FunctionServiceClient._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 FunctionServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert FunctionServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert FunctionServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + FunctionServiceClient._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 FunctionServiceClient._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 FunctionServiceClient._get_client_cert_source(None, False) is None + assert ( + FunctionServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + FunctionServiceClient._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 ( + FunctionServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + FunctionServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + FunctionServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FunctionServiceClient), +) +@mock.patch.object( + FunctionServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FunctionServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = FunctionServiceClient._DEFAULT_UNIVERSE + default_endpoint = FunctionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = FunctionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + FunctionServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + FunctionServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == FunctionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + FunctionServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + FunctionServiceClient._get_api_endpoint(None, None, default_universe, "always") + == FunctionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + FunctionServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == FunctionServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + FunctionServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + FunctionServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + FunctionServiceClient._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 ( + FunctionServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + FunctionServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + FunctionServiceClient._get_universe_domain(None, None) + == FunctionServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + FunctionServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (FunctionServiceClient, transports.FunctionServiceGrpcTransport, "grpc"), + (FunctionServiceClient, transports.FunctionServiceRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -123,7 +407,7 @@ def test__get_default_mtls_endpoint(): def test_function_service_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -177,7 +461,7 @@ def test_function_service_client_service_account_always_use_jwt( def test_function_service_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -227,20 +511,22 @@ def test_function_service_client_get_transport_class(): ) @mock.patch.object( FunctionServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(FunctionServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FunctionServiceClient), ) @mock.patch.object( FunctionServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(FunctionServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FunctionServiceAsyncClient), ) def test_function_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(FunctionServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -275,7 +561,9 @@ def test_function_service_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, @@ -305,15 +593,23 @@ def test_function_service_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") @@ -323,7 +619,9 @@ def test_function_service_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", @@ -341,7 +639,9 @@ def test_function_service_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, @@ -394,13 +694,13 @@ def test_function_service_client_client_options( ) @mock.patch.object( FunctionServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(FunctionServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FunctionServiceClient), ) @mock.patch.object( FunctionServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(FunctionServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FunctionServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_function_service_client_mtls_env_auto( @@ -423,7 +723,9 @@ def test_function_service_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 @@ -455,7 +757,9 @@ def test_function_service_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 @@ -489,7 +793,9 @@ def test_function_service_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, @@ -579,6 +885,118 @@ def test_function_service_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", [FunctionServiceClient, FunctionServiceAsyncClient] +) +@mock.patch.object( + FunctionServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FunctionServiceClient), +) +@mock.patch.object( + FunctionServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(FunctionServiceAsyncClient), +) +def test_function_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = FunctionServiceClient._DEFAULT_UNIVERSE + default_endpoint = FunctionServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = FunctionServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -605,7 +1023,9 @@ def test_function_service_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, @@ -645,7 +1065,9 @@ def test_function_service_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, @@ -705,7 +1127,9 @@ def test_function_service_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, @@ -722,8 +1146,8 @@ def test_function_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -752,7 +1176,7 @@ def test_function_service_client_create_channel_credentials_file( ) def test_get_function(request_type, transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -792,7 +1216,7 @@ def test_get_function_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -809,7 +1233,7 @@ async def test_get_function_async( transport: str = "grpc_asyncio", request_type=functions.GetFunctionRequest ): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -854,7 +1278,7 @@ async def test_get_function_async_from_dict(): def test_get_function_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -884,7 +1308,7 @@ def test_get_function_field_headers(): @pytest.mark.asyncio async def test_get_function_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -913,7 +1337,7 @@ async def test_get_function_field_headers_async(): def test_get_function_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -937,7 +1361,7 @@ def test_get_function_flattened(): def test_get_function_flattened_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -952,7 +1376,7 @@ def test_get_function_flattened_error(): @pytest.mark.asyncio async def test_get_function_flattened_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -979,7 +1403,7 @@ async def test_get_function_flattened_async(): @pytest.mark.asyncio async def test_get_function_flattened_error_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1000,7 +1424,7 @@ async def test_get_function_flattened_error_async(): ) def test_list_functions(request_type, transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1032,7 +1456,7 @@ def test_list_functions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1049,7 +1473,7 @@ async def test_list_functions_async( transport: str = "grpc_asyncio", request_type=functions.ListFunctionsRequest ): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1086,7 +1510,7 @@ async def test_list_functions_async_from_dict(): def test_list_functions_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1116,7 +1540,7 @@ def test_list_functions_field_headers(): @pytest.mark.asyncio async def test_list_functions_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1147,7 +1571,7 @@ async def test_list_functions_field_headers_async(): def test_list_functions_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1171,7 +1595,7 @@ def test_list_functions_flattened(): def test_list_functions_flattened_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1186,7 +1610,7 @@ def test_list_functions_flattened_error(): @pytest.mark.asyncio async def test_list_functions_flattened_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1215,7 +1639,7 @@ async def test_list_functions_flattened_async(): @pytest.mark.asyncio async def test_list_functions_flattened_error_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1229,7 +1653,7 @@ async def test_list_functions_flattened_error_async(): def test_list_functions_pager(transport_name: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1279,7 +1703,7 @@ def test_list_functions_pager(transport_name: str = "grpc"): def test_list_functions_pages(transport_name: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1321,7 +1745,7 @@ def test_list_functions_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_functions_async_pager(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1371,7 +1795,7 @@ async def test_list_functions_async_pager(): @pytest.mark.asyncio async def test_list_functions_async_pages(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1426,7 +1850,7 @@ async def test_list_functions_async_pages(): ) def test_create_function(request_type, transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1453,7 +1877,7 @@ def test_create_function_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1470,7 +1894,7 @@ async def test_create_function_async( transport: str = "grpc_asyncio", request_type=functions.CreateFunctionRequest ): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1502,7 +1926,7 @@ async def test_create_function_async_from_dict(): def test_create_function_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1532,7 +1956,7 @@ def test_create_function_field_headers(): @pytest.mark.asyncio async def test_create_function_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1563,7 +1987,7 @@ async def test_create_function_field_headers_async(): def test_create_function_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1595,7 +2019,7 @@ def test_create_function_flattened(): def test_create_function_flattened_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1612,7 +2036,7 @@ def test_create_function_flattened_error(): @pytest.mark.asyncio async def test_create_function_flattened_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1649,7 +2073,7 @@ async def test_create_function_flattened_async(): @pytest.mark.asyncio async def test_create_function_flattened_error_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1672,7 +2096,7 @@ async def test_create_function_flattened_error_async(): ) def test_update_function(request_type, transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1699,7 +2123,7 @@ def test_update_function_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1716,7 +2140,7 @@ async def test_update_function_async( transport: str = "grpc_asyncio", request_type=functions.UpdateFunctionRequest ): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1748,7 +2172,7 @@ async def test_update_function_async_from_dict(): def test_update_function_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1778,7 +2202,7 @@ def test_update_function_field_headers(): @pytest.mark.asyncio async def test_update_function_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1809,7 +2233,7 @@ async def test_update_function_field_headers_async(): def test_update_function_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1837,7 +2261,7 @@ def test_update_function_flattened(): def test_update_function_flattened_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1853,7 +2277,7 @@ def test_update_function_flattened_error(): @pytest.mark.asyncio async def test_update_function_flattened_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1886,7 +2310,7 @@ async def test_update_function_flattened_async(): @pytest.mark.asyncio async def test_update_function_flattened_error_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1908,7 +2332,7 @@ async def test_update_function_flattened_error_async(): ) def test_delete_function(request_type, transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1935,7 +2359,7 @@ def test_delete_function_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1952,7 +2376,7 @@ async def test_delete_function_async( transport: str = "grpc_asyncio", request_type=functions.DeleteFunctionRequest ): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1984,7 +2408,7 @@ async def test_delete_function_async_from_dict(): def test_delete_function_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2014,7 +2438,7 @@ def test_delete_function_field_headers(): @pytest.mark.asyncio async def test_delete_function_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2045,7 +2469,7 @@ async def test_delete_function_field_headers_async(): def test_delete_function_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2069,7 +2493,7 @@ def test_delete_function_flattened(): def test_delete_function_flattened_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2084,7 +2508,7 @@ def test_delete_function_flattened_error(): @pytest.mark.asyncio async def test_delete_function_flattened_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2113,7 +2537,7 @@ async def test_delete_function_flattened_async(): @pytest.mark.asyncio async def test_delete_function_flattened_error_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2134,7 +2558,7 @@ async def test_delete_function_flattened_error_async(): ) def test_generate_upload_url(request_type, transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2166,7 +2590,7 @@ def test_generate_upload_url_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2185,7 +2609,7 @@ async def test_generate_upload_url_async( transport: str = "grpc_asyncio", request_type=functions.GenerateUploadUrlRequest ): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2222,7 +2646,7 @@ async def test_generate_upload_url_async_from_dict(): def test_generate_upload_url_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2254,7 +2678,7 @@ def test_generate_upload_url_field_headers(): @pytest.mark.asyncio async def test_generate_upload_url_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2294,7 +2718,7 @@ async def test_generate_upload_url_field_headers_async(): ) def test_generate_download_url(request_type, transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2326,7 +2750,7 @@ def test_generate_download_url_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2345,7 +2769,7 @@ async def test_generate_download_url_async( transport: str = "grpc_asyncio", request_type=functions.GenerateDownloadUrlRequest ): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2382,7 +2806,7 @@ async def test_generate_download_url_async_from_dict(): def test_generate_download_url_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2414,7 +2838,7 @@ def test_generate_download_url_field_headers(): @pytest.mark.asyncio async def test_generate_download_url_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2454,7 +2878,7 @@ async def test_generate_download_url_field_headers_async(): ) def test_list_runtimes(request_type, transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2481,7 +2905,7 @@ def test_list_runtimes_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2498,7 +2922,7 @@ async def test_list_runtimes_async( transport: str = "grpc_asyncio", request_type=functions.ListRuntimesRequest ): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2530,7 +2954,7 @@ async def test_list_runtimes_async_from_dict(): def test_list_runtimes_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2560,7 +2984,7 @@ def test_list_runtimes_field_headers(): @pytest.mark.asyncio async def test_list_runtimes_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2591,7 +3015,7 @@ async def test_list_runtimes_field_headers_async(): def test_list_runtimes_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2615,7 +3039,7 @@ def test_list_runtimes_flattened(): def test_list_runtimes_flattened_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2630,7 +3054,7 @@ def test_list_runtimes_flattened_error(): @pytest.mark.asyncio async def test_list_runtimes_flattened_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2659,7 +3083,7 @@ async def test_list_runtimes_flattened_async(): @pytest.mark.asyncio async def test_list_runtimes_flattened_error_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2680,7 +3104,7 @@ async def test_list_runtimes_flattened_error_async(): ) def test_get_function_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2739,7 +3163,7 @@ def test_get_function_rest_required_fields(request_type=functions.GetFunctionReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2748,7 +3172,7 @@ def test_get_function_rest_required_fields(request_type=functions.GetFunctionReq jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2757,7 +3181,7 @@ def test_get_function_rest_required_fields(request_type=functions.GetFunctionReq assert jsonified_request["name"] == "name_value" client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2799,7 +3223,7 @@ def test_get_function_rest_required_fields(request_type=functions.GetFunctionReq def test_get_function_rest_unset_required_fields(): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_function._get_unset_required_fields({}) @@ -2809,7 +3233,7 @@ def test_get_function_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_function_rest_interceptors(null_interceptor): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FunctionServiceRestInterceptor(), @@ -2863,7 +3287,7 @@ def test_get_function_rest_bad_request( transport: str = "rest", request_type=functions.GetFunctionRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2885,7 +3309,7 @@ def test_get_function_rest_bad_request( def test_get_function_rest_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2928,7 +3352,7 @@ def test_get_function_rest_flattened(): def test_get_function_rest_flattened_error(transport: str = "rest"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2943,7 +3367,7 @@ def test_get_function_rest_flattened_error(transport: str = "rest"): def test_get_function_rest_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2956,7 +3380,7 @@ def test_get_function_rest_error(): ) def test_list_functions_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3009,7 +3433,7 @@ def test_list_functions_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_functions._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3018,7 +3442,7 @@ def test_list_functions_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_functions._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3036,7 +3460,7 @@ def test_list_functions_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3078,7 +3502,7 @@ def test_list_functions_rest_required_fields( def test_list_functions_rest_unset_required_fields(): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_functions._get_unset_required_fields({}) @@ -3098,7 +3522,7 @@ def test_list_functions_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_functions_rest_interceptors(null_interceptor): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FunctionServiceRestInterceptor(), @@ -3154,7 +3578,7 @@ def test_list_functions_rest_bad_request( transport: str = "rest", request_type=functions.ListFunctionsRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3176,7 +3600,7 @@ def test_list_functions_rest_bad_request( def test_list_functions_rest_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3217,7 +3641,7 @@ def test_list_functions_rest_flattened(): def test_list_functions_rest_flattened_error(transport: str = "rest"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3232,7 +3656,7 @@ def test_list_functions_rest_flattened_error(transport: str = "rest"): def test_list_functions_rest_pager(transport: str = "rest"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3300,7 +3724,7 @@ def test_list_functions_rest_pager(transport: str = "rest"): ) def test_create_function_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3505,7 +3929,7 @@ def test_create_function_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3514,7 +3938,7 @@ def test_create_function_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_function._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("function_id",)) @@ -3525,7 +3949,7 @@ def test_create_function_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3565,7 +3989,7 @@ def test_create_function_rest_required_fields( def test_create_function_rest_unset_required_fields(): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_function._get_unset_required_fields({}) @@ -3583,7 +4007,7 @@ def test_create_function_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_function_rest_interceptors(null_interceptor): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FunctionServiceRestInterceptor(), @@ -3643,7 +4067,7 @@ def test_create_function_rest_bad_request( transport: str = "rest", request_type=functions.CreateFunctionRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3665,7 +4089,7 @@ def test_create_function_rest_bad_request( def test_create_function_rest_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3706,7 +4130,7 @@ def test_create_function_rest_flattened(): def test_create_function_rest_flattened_error(transport: str = "rest"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3723,7 +4147,7 @@ def test_create_function_rest_flattened_error(transport: str = "rest"): def test_create_function_rest_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3736,7 +4160,7 @@ def test_create_function_rest_error(): ) def test_update_function_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3942,14 +4366,14 @@ def test_update_function_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_function._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -3958,7 +4382,7 @@ def test_update_function_rest_required_fields( # verify required fields with non-default values are left alone client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3998,7 +4422,7 @@ def test_update_function_rest_required_fields( def test_update_function_rest_unset_required_fields(): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_function._get_unset_required_fields({}) @@ -4008,7 +4432,7 @@ def test_update_function_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_function_rest_interceptors(null_interceptor): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FunctionServiceRestInterceptor(), @@ -4068,7 +4492,7 @@ def test_update_function_rest_bad_request( transport: str = "rest", request_type=functions.UpdateFunctionRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4092,7 +4516,7 @@ def test_update_function_rest_bad_request( def test_update_function_rest_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4135,7 +4559,7 @@ def test_update_function_rest_flattened(): def test_update_function_rest_flattened_error(transport: str = "rest"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4151,7 +4575,7 @@ def test_update_function_rest_flattened_error(transport: str = "rest"): def test_update_function_rest_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4164,7 +4588,7 @@ def test_update_function_rest_error(): ) def test_delete_function_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4210,7 +4634,7 @@ def test_delete_function_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4219,7 +4643,7 @@ def test_delete_function_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_function._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4228,7 +4652,7 @@ def test_delete_function_rest_required_fields( assert jsonified_request["name"] == "name_value" client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4267,7 +4691,7 @@ def test_delete_function_rest_required_fields( def test_delete_function_rest_unset_required_fields(): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_function._get_unset_required_fields({}) @@ -4277,7 +4701,7 @@ def test_delete_function_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_function_rest_interceptors(null_interceptor): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FunctionServiceRestInterceptor(), @@ -4337,7 +4761,7 @@ def test_delete_function_rest_bad_request( transport: str = "rest", request_type=functions.DeleteFunctionRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4359,7 +4783,7 @@ def test_delete_function_rest_bad_request( def test_delete_function_rest_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4400,7 +4824,7 @@ def test_delete_function_rest_flattened(): def test_delete_function_rest_flattened_error(transport: str = "rest"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4415,7 +4839,7 @@ def test_delete_function_rest_flattened_error(transport: str = "rest"): def test_delete_function_rest_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4428,7 +4852,7 @@ def test_delete_function_rest_error(): ) def test_generate_upload_url_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4479,7 +4903,7 @@ def test_generate_upload_url_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_upload_url._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4488,7 +4912,7 @@ def test_generate_upload_url_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_upload_url._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4497,7 +4921,7 @@ def test_generate_upload_url_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4540,7 +4964,7 @@ def test_generate_upload_url_rest_required_fields( def test_generate_upload_url_rest_unset_required_fields(): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_upload_url._get_unset_required_fields({}) @@ -4550,7 +4974,7 @@ def test_generate_upload_url_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_upload_url_rest_interceptors(null_interceptor): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FunctionServiceRestInterceptor(), @@ -4608,7 +5032,7 @@ def test_generate_upload_url_rest_bad_request( transport: str = "rest", request_type=functions.GenerateUploadUrlRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4630,7 +5054,7 @@ def test_generate_upload_url_rest_bad_request( def test_generate_upload_url_rest_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4643,7 +5067,7 @@ def test_generate_upload_url_rest_error(): ) def test_generate_download_url_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4694,7 +5118,7 @@ def test_generate_download_url_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_download_url._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4703,7 +5127,7 @@ def test_generate_download_url_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_download_url._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4712,7 +5136,7 @@ def test_generate_download_url_rest_required_fields( assert jsonified_request["name"] == "name_value" client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4755,7 +5179,7 @@ def test_generate_download_url_rest_required_fields( def test_generate_download_url_rest_unset_required_fields(): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_download_url._get_unset_required_fields({}) @@ -4765,7 +5189,7 @@ def test_generate_download_url_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_download_url_rest_interceptors(null_interceptor): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FunctionServiceRestInterceptor(), @@ -4823,7 +5247,7 @@ def test_generate_download_url_rest_bad_request( transport: str = "rest", request_type=functions.GenerateDownloadUrlRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4845,7 +5269,7 @@ def test_generate_download_url_rest_bad_request( def test_generate_download_url_rest_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4858,7 +5282,7 @@ def test_generate_download_url_rest_error(): ) def test_list_runtimes_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4904,7 +5328,7 @@ def test_list_runtimes_rest_required_fields(request_type=functions.ListRuntimesR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_runtimes._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4913,7 +5337,7 @@ def test_list_runtimes_rest_required_fields(request_type=functions.ListRuntimesR jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_runtimes._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("filter",)) @@ -4924,7 +5348,7 @@ def test_list_runtimes_rest_required_fields(request_type=functions.ListRuntimesR assert jsonified_request["parent"] == "parent_value" client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4966,7 +5390,7 @@ def test_list_runtimes_rest_required_fields(request_type=functions.ListRuntimesR def test_list_runtimes_rest_unset_required_fields(): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_runtimes._get_unset_required_fields({}) @@ -4976,7 +5400,7 @@ def test_list_runtimes_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_runtimes_rest_interceptors(null_interceptor): transport = transports.FunctionServiceRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.FunctionServiceRestInterceptor(), @@ -5032,7 +5456,7 @@ def test_list_runtimes_rest_bad_request( transport: str = "rest", request_type=functions.ListRuntimesRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5054,7 +5478,7 @@ def test_list_runtimes_rest_bad_request( def test_list_runtimes_rest_flattened(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5095,7 +5519,7 @@ def test_list_runtimes_rest_flattened(): def test_list_runtimes_rest_flattened_error(transport: str = "rest"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5110,24 +5534,24 @@ def test_list_runtimes_rest_flattened_error(transport: str = "rest"): def test_list_runtimes_rest_error(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.FunctionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.FunctionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = FunctionServiceClient( @@ -5137,7 +5561,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.FunctionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5148,16 +5572,17 @@ 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 = FunctionServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.FunctionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = FunctionServiceClient( @@ -5169,7 +5594,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.FunctionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = FunctionServiceClient(transport=transport) assert client.transport is transport @@ -5178,13 +5603,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.FunctionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.FunctionServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -5201,7 +5626,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -5215,7 +5640,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = FunctionServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -5223,7 +5648,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -5235,7 +5660,7 @@ def test_function_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.FunctionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -5247,7 +5672,7 @@ def test_function_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.FunctionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -5297,7 +5722,7 @@ def test_function_service_base_transport_with_credentials_file(): "google.cloud.functions_v2.services.function_service.transports.FunctionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.FunctionServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -5316,7 +5741,7 @@ def test_function_service_base_transport_with_adc(): "google.cloud.functions_v2.services.function_service.transports.FunctionServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.FunctionServiceTransport() adc.assert_called_once() @@ -5324,7 +5749,7 @@ def test_function_service_base_transport_with_adc(): def test_function_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) FunctionServiceClient() adc.assert_called_once_with( scopes=None, @@ -5344,7 +5769,7 @@ def test_function_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -5391,7 +5816,7 @@ def test_function_service_transport_create_channel(transport_class, grpc_helpers ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -5419,7 +5844,7 @@ def test_function_service_transport_create_channel(transport_class, grpc_helpers ], ) def test_function_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -5457,7 +5882,7 @@ def test_function_service_grpc_transport_client_cert_source_for_mtls(transport_c def test_function_service_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -5469,7 +5894,7 @@ def test_function_service_http_transport_client_cert_source_for_mtls(): def test_function_service_rest_lro_client(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -5494,7 +5919,7 @@ def test_function_service_rest_lro_client(): ) def test_function_service_host_no_port(transport_name): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="cloudfunctions.googleapis.com" ), @@ -5517,7 +5942,7 @@ def test_function_service_host_no_port(transport_name): ) def test_function_service_host_with_port(transport_name): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="cloudfunctions.googleapis.com:8000" ), @@ -5537,8 +5962,8 @@ def test_function_service_host_with_port(transport_name): ], ) def test_function_service_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = FunctionServiceClient( credentials=creds1, transport=transport_name, @@ -5623,7 +6048,7 @@ def test_function_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -5701,7 +6126,7 @@ def test_function_service_transport_channel_mtls_with_adc(transport_class): def test_function_service_grpc_lro_client(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -5718,7 +6143,7 @@ def test_function_service_grpc_lro_client(): def test_function_service_grpc_lro_async_client(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -6109,7 +6534,7 @@ def test_client_with_default_client_info(): transports.FunctionServiceTransport, "_prep_wrapped_messages" ) as prep: client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6119,7 +6544,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = FunctionServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6128,7 +6553,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6143,7 +6568,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6171,7 +6596,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -6199,7 +6624,7 @@ def test_get_iam_policy_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6229,7 +6654,7 @@ def test_get_iam_policy_rest_bad_request( ) def test_get_iam_policy_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"resource": "projects/sample1/locations/sample2/functions/sample3"} @@ -6257,7 +6682,7 @@ def test_set_iam_policy_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6287,7 +6712,7 @@ def test_set_iam_policy_rest_bad_request( ) def test_set_iam_policy_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"resource": "projects/sample1/locations/sample2/functions/sample3"} @@ -6315,7 +6740,7 @@ def test_test_iam_permissions_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.TestIamPermissionsRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6345,7 +6770,7 @@ def test_test_iam_permissions_rest_bad_request( ) def test_test_iam_permissions_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"resource": "projects/sample1/locations/sample2/functions/sample3"} @@ -6373,7 +6798,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6403,7 +6828,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -6431,7 +6856,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6461,7 +6886,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -6487,7 +6912,7 @@ def test_list_operations_rest(request_type): def test_get_operation(transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6512,7 +6937,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6538,7 +6963,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6567,7 +6992,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6596,7 +7021,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6614,7 +7039,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -6632,7 +7057,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6657,7 +7082,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6683,7 +7108,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6712,7 +7137,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6741,7 +7166,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6759,7 +7184,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -6777,7 +7202,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6802,7 +7227,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6828,7 +7253,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6857,7 +7282,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6886,7 +7311,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6904,7 +7329,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -6922,7 +7347,7 @@ async def test_list_locations_from_dict_async(): def test_set_iam_policy(transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6955,7 +7380,7 @@ def test_set_iam_policy(transport: str = "grpc"): @pytest.mark.asyncio async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6990,7 +7415,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): def test_set_iam_policy_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7020,7 +7445,7 @@ def test_set_iam_policy_field_headers(): @pytest.mark.asyncio async def test_set_iam_policy_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7049,7 +7474,7 @@ async def test_set_iam_policy_field_headers_async(): def test_set_iam_policy_from_dict(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -7068,7 +7493,7 @@ def test_set_iam_policy_from_dict(): @pytest.mark.asyncio async def test_set_iam_policy_from_dict_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -7086,7 +7511,7 @@ async def test_set_iam_policy_from_dict_async(): def test_get_iam_policy(transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7121,7 +7546,7 @@ def test_get_iam_policy(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7157,7 +7582,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): def test_get_iam_policy_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7187,7 +7612,7 @@ def test_get_iam_policy_field_headers(): @pytest.mark.asyncio async def test_get_iam_policy_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7216,7 +7641,7 @@ async def test_get_iam_policy_field_headers_async(): def test_get_iam_policy_from_dict(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -7235,7 +7660,7 @@ def test_get_iam_policy_from_dict(): @pytest.mark.asyncio async def test_get_iam_policy_from_dict_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -7253,7 +7678,7 @@ async def test_get_iam_policy_from_dict_async(): def test_test_iam_permissions(transport: str = "grpc"): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7287,7 +7712,7 @@ def test_test_iam_permissions(transport: str = "grpc"): @pytest.mark.asyncio async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7322,7 +7747,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): def test_test_iam_permissions_field_headers(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7354,7 +7779,7 @@ def test_test_iam_permissions_field_headers(): @pytest.mark.asyncio async def test_test_iam_permissions_field_headers_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7387,7 +7812,7 @@ async def test_test_iam_permissions_field_headers_async(): def test_test_iam_permissions_from_dict(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7408,7 +7833,7 @@ def test_test_iam_permissions_from_dict(): @pytest.mark.asyncio async def test_test_iam_permissions_from_dict_async(): client = FunctionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7436,7 +7861,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7453,7 +7878,7 @@ def test_client_ctx(): ] for transport in transports: client = FunctionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7484,7 +7909,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, diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup/gapic_version.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup/gapic_version.py index 7951a72dc56f..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup/gapic_version.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.5.3" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/gapic_version.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/gapic_version.py index 7951a72dc56f..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/gapic_version.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.5.3" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/async_client.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/async_client.py index 0c913d3d8253..22108cc99df7 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/async_client.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/async_client.py @@ -38,9 +38,9 @@ from google.cloud.gke_backup_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -77,8 +77,12 @@ class BackupForGKEAsyncClient: _client: BackupForGKEClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = BackupForGKEClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = BackupForGKEClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = BackupForGKEClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = BackupForGKEClient._DEFAULT_UNIVERSE backup_path = staticmethod(BackupForGKEClient.backup_path) parse_backup_path = staticmethod(BackupForGKEClient.parse_backup_path) @@ -197,6 +201,25 @@ def transport(self) -> BackupForGKETransport: """ 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(BackupForGKEClient).get_transport_class, type(BackupForGKEClient) ) @@ -209,7 +232,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the backup for gke client. + """Instantiates the backup for gke async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -220,23 +243,38 @@ def __init__( transport (Union[str, ~.BackupForGKETransport]): 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. @@ -381,6 +419,9 @@ async def sample_create_backup_plan(): 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, @@ -503,6 +544,9 @@ async def sample_list_backup_plans(): 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, @@ -622,6 +666,9 @@ async def sample_get_backup_plan(): 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, @@ -756,6 +803,9 @@ async def sample_update_backup_plan(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -879,6 +929,9 @@ async def sample_delete_backup_plan(): 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, @@ -1024,6 +1077,9 @@ async def sample_create_backup(): 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, @@ -1146,6 +1202,9 @@ async def sample_list_backups(): 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, @@ -1271,6 +1330,9 @@ async def sample_get_backup(): 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, @@ -1404,6 +1466,9 @@ async def sample_update_backup(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1527,6 +1592,9 @@ async def sample_delete_backup(): 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, @@ -1651,6 +1719,9 @@ async def sample_list_volume_backups(): 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, @@ -1775,6 +1846,9 @@ async def sample_get_volume_backup(): 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, @@ -1921,6 +1995,9 @@ async def sample_create_restore_plan(): 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, @@ -2043,6 +2120,9 @@ async def sample_list_restore_plans(): 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, @@ -2164,6 +2244,9 @@ async def sample_get_restore_plan(): 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, @@ -2299,6 +2382,9 @@ async def sample_update_restore_plan(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2423,6 +2509,9 @@ async def sample_delete_restore_plan(): 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, @@ -2575,6 +2664,9 @@ async def sample_create_restore(): 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, @@ -2697,6 +2789,9 @@ async def sample_list_restores(): 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, @@ -2818,6 +2913,9 @@ async def sample_get_restore(): 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, @@ -2949,6 +3047,9 @@ async def sample_update_restore(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -3072,6 +3173,9 @@ async def sample_delete_restore(): 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, @@ -3196,6 +3300,9 @@ async def sample_list_volume_restores(): 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, @@ -3317,6 +3424,9 @@ async def sample_get_volume_restore(): 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, @@ -3371,6 +3481,9 @@ async def list_operations( 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, @@ -3425,6 +3538,9 @@ async def get_operation( 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, @@ -3483,6 +3599,9 @@ async def delete_operation( 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, @@ -3537,6 +3656,9 @@ async def cancel_operation( 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, @@ -3654,6 +3776,9 @@ async def set_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -3775,6 +3900,9 @@ async def get_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -3834,6 +3962,9 @@ async def test_iam_permissions( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -3888,6 +4019,9 @@ async def get_location( 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, @@ -3942,6 +4076,9 @@ async def list_locations( 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, diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/client.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/client.py index 25068b7d07d9..b4d38dee59f4 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/client.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.gke_backup_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -145,11 +146,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 = "gkebackup.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "gkebackup.{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 @@ -470,7 +475,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 @@ -500,6 +505,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") @@ -533,6 +543,175 @@ 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 + + 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 + + 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 = BackupForGKEClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = BackupForGKEClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = BackupForGKEClient._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 = BackupForGKEClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = BackupForGKEClient._DEFAULT_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 BackupForGKEClient._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, *, @@ -552,22 +731,32 @@ def __init__( transport (Union[str, BackupForGKETransport]): 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. @@ -578,17 +767,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, + ) = BackupForGKEClient._read_environment_variables() + self._client_cert_source = BackupForGKEClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = BackupForGKEClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -597,20 +803,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, BackupForGKETransport): + transport_provided = isinstance(transport, BackupForGKETransport) + if transport_provided: # transport is a BackupForGKETransport 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(BackupForGKETransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or BackupForGKEClient._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( @@ -620,17 +836,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 create_backup_plan( @@ -766,6 +982,9 @@ def sample_create_backup_plan(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -879,6 +1098,9 @@ def sample_list_backup_plans(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -989,6 +1211,9 @@ def sample_get_backup_plan(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1123,6 +1348,9 @@ def sample_update_backup_plan(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1246,6 +1474,9 @@ def sample_delete_backup_plan(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1391,6 +1622,9 @@ def sample_create_backup(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1504,6 +1738,9 @@ def sample_list_backups(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1620,6 +1857,9 @@ def sample_get_backup(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1753,6 +1993,9 @@ def sample_update_backup(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1876,6 +2119,9 @@ def sample_delete_backup(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1991,6 +2237,9 @@ def sample_list_volume_backups(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2106,6 +2355,9 @@ def sample_get_volume_backup(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2252,6 +2504,9 @@ def sample_create_restore_plan(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2365,6 +2620,9 @@ def sample_list_restore_plans(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2477,6 +2735,9 @@ def sample_get_restore_plan(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2612,6 +2873,9 @@ def sample_update_restore_plan(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2736,6 +3000,9 @@ def sample_delete_restore_plan(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2888,6 +3155,9 @@ def sample_create_restore(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3001,6 +3271,9 @@ def sample_list_restores(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3113,6 +3386,9 @@ def sample_get_restore(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3244,6 +3520,9 @@ def sample_update_restore(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3367,6 +3646,9 @@ def sample_delete_restore(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3482,6 +3764,9 @@ def sample_list_volume_restores(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3594,6 +3879,9 @@ def sample_get_volume_restore(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3661,6 +3949,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3715,6 +4006,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3773,6 +4067,9 @@ def delete_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3827,6 +4124,9 @@ def cancel_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3944,6 +4244,9 @@ def set_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4065,6 +4368,9 @@ def get_iam_policy( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4124,6 +4430,9 @@ def test_iam_permissions( gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4178,6 +4487,9 @@ def get_location( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -4232,6 +4544,9 @@ def list_locations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/base.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/base.py index 639e7dd68bf0..7d54f1a96625 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/base.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/base.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkebackup.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 @@ -130,6 +130,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-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc.py index db04a6e69354..48ec336bcd9b 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc.py @@ -76,7 +76,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkebackup.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-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc_asyncio.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc_asyncio.py index f6263a681912..c783be132f69 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/grpc_asyncio.py @@ -121,7 +121,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkebackup.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-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/rest.py b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/rest.py index 6df00c2bf6e0..fdec760acc6e 100644 --- a/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/rest.py +++ b/packages/google-cloud-gke-backup/google/cloud/gke_backup_v1/services/backup_for_gke/transports/rest.py @@ -40,9 +40,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -1062,7 +1062,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkebackup.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-gke-backup/noxfile.py b/packages/google-cloud-gke-backup/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-gke-backup/noxfile.py +++ b/packages/google-cloud-gke-backup/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-gke-backup/samples/generated_samples/snippet_metadata_google.cloud.gkebackup.v1.json b/packages/google-cloud-gke-backup/samples/generated_samples/snippet_metadata_google.cloud.gkebackup.v1.json index 1139ae73c680..7a6f9c3719c1 100644 --- a/packages/google-cloud-gke-backup/samples/generated_samples/snippet_metadata_google.cloud.gkebackup.v1.json +++ b/packages/google-cloud-gke-backup/samples/generated_samples/snippet_metadata_google.cloud.gkebackup.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-gke-backup", - "version": "0.5.3" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-gke-backup/tests/unit/gapic/gke_backup_v1/test_backup_for_gke.py b/packages/google-cloud-gke-backup/tests/unit/gapic/gke_backup_v1/test_backup_for_gke.py index 4206fb1b1f45..5a5511da7768 100644 --- a/packages/google-cloud-gke-backup/tests/unit/gapic/gke_backup_v1/test_backup_for_gke.py +++ b/packages/google-cloud-gke-backup/tests/unit/gapic/gke_backup_v1/test_backup_for_gke.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -92,6 +92,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -118,6 +141,255 @@ def test__get_default_mtls_endpoint(): assert BackupForGKEClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert BackupForGKEClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert BackupForGKEClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert BackupForGKEClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + BackupForGKEClient._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 BackupForGKEClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert BackupForGKEClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert BackupForGKEClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + BackupForGKEClient._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 BackupForGKEClient._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 BackupForGKEClient._get_client_cert_source(None, False) is None + assert ( + BackupForGKEClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + BackupForGKEClient._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 ( + BackupForGKEClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + BackupForGKEClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + BackupForGKEClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(BackupForGKEClient), +) +@mock.patch.object( + BackupForGKEAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(BackupForGKEAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = BackupForGKEClient._DEFAULT_UNIVERSE + default_endpoint = BackupForGKEClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = BackupForGKEClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + BackupForGKEClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + BackupForGKEClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == BackupForGKEClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + BackupForGKEClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + BackupForGKEClient._get_api_endpoint(None, None, default_universe, "always") + == BackupForGKEClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + BackupForGKEClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == BackupForGKEClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + BackupForGKEClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + BackupForGKEClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + BackupForGKEClient._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 ( + BackupForGKEClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + BackupForGKEClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + BackupForGKEClient._get_universe_domain(None, None) + == BackupForGKEClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + BackupForGKEClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (BackupForGKEClient, transports.BackupForGKEGrpcTransport, "grpc"), + (BackupForGKEClient, transports.BackupForGKERestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -127,7 +399,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_backup_for_gke_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -179,7 +451,7 @@ def test_backup_for_gke_client_service_account_always_use_jwt( ], ) def test_backup_for_gke_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -228,19 +500,23 @@ def test_backup_for_gke_client_get_transport_class(): ], ) @mock.patch.object( - BackupForGKEClient, "DEFAULT_ENDPOINT", modify_default_endpoint(BackupForGKEClient) + BackupForGKEClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(BackupForGKEClient), ) @mock.patch.object( BackupForGKEAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(BackupForGKEAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(BackupForGKEAsyncClient), ) def test_backup_for_gke_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(BackupForGKEClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -275,7 +551,9 @@ def test_backup_for_gke_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, @@ -305,15 +583,23 @@ def test_backup_for_gke_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") @@ -323,7 +609,9 @@ def test_backup_for_gke_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", @@ -341,7 +629,9 @@ def test_backup_for_gke_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, @@ -373,12 +663,14 @@ def test_backup_for_gke_client_client_options( ], ) @mock.patch.object( - BackupForGKEClient, "DEFAULT_ENDPOINT", modify_default_endpoint(BackupForGKEClient) + BackupForGKEClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(BackupForGKEClient), ) @mock.patch.object( BackupForGKEAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(BackupForGKEAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(BackupForGKEAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_backup_for_gke_client_mtls_env_auto( @@ -401,7 +693,9 @@ def test_backup_for_gke_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 @@ -433,7 +727,9 @@ def test_backup_for_gke_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 @@ -467,7 +763,9 @@ def test_backup_for_gke_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, @@ -553,6 +851,116 @@ def test_backup_for_gke_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", [BackupForGKEClient, BackupForGKEAsyncClient]) +@mock.patch.object( + BackupForGKEClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(BackupForGKEClient), +) +@mock.patch.object( + BackupForGKEAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(BackupForGKEAsyncClient), +) +def test_backup_for_gke_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = BackupForGKEClient._DEFAULT_UNIVERSE + default_endpoint = BackupForGKEClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = BackupForGKEClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -579,7 +987,9 @@ def test_backup_for_gke_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, @@ -619,7 +1029,9 @@ def test_backup_for_gke_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, @@ -677,7 +1089,9 @@ def test_backup_for_gke_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, @@ -694,8 +1108,8 @@ def test_backup_for_gke_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -724,7 +1138,7 @@ def test_backup_for_gke_client_create_channel_credentials_file( ) def test_create_backup_plan(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -753,7 +1167,7 @@ def test_create_backup_plan_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -772,7 +1186,7 @@ async def test_create_backup_plan_async( transport: str = "grpc_asyncio", request_type=gkebackup.CreateBackupPlanRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -806,7 +1220,7 @@ async def test_create_backup_plan_async_from_dict(): def test_create_backup_plan_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -838,7 +1252,7 @@ def test_create_backup_plan_field_headers(): @pytest.mark.asyncio async def test_create_backup_plan_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -871,7 +1285,7 @@ async def test_create_backup_plan_field_headers_async(): def test_create_backup_plan_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -905,7 +1319,7 @@ def test_create_backup_plan_flattened(): def test_create_backup_plan_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -922,7 +1336,7 @@ def test_create_backup_plan_flattened_error(): @pytest.mark.asyncio async def test_create_backup_plan_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -961,7 +1375,7 @@ async def test_create_backup_plan_flattened_async(): @pytest.mark.asyncio async def test_create_backup_plan_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -984,7 +1398,7 @@ async def test_create_backup_plan_flattened_error_async(): ) def test_list_backup_plans(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1018,7 +1432,7 @@ def test_list_backup_plans_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1037,7 +1451,7 @@ async def test_list_backup_plans_async( transport: str = "grpc_asyncio", request_type=gkebackup.ListBackupPlansRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1076,7 +1490,7 @@ async def test_list_backup_plans_async_from_dict(): def test_list_backup_plans_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1108,7 +1522,7 @@ def test_list_backup_plans_field_headers(): @pytest.mark.asyncio async def test_list_backup_plans_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1141,7 +1555,7 @@ async def test_list_backup_plans_field_headers_async(): def test_list_backup_plans_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1167,7 +1581,7 @@ def test_list_backup_plans_flattened(): def test_list_backup_plans_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1182,7 +1596,7 @@ def test_list_backup_plans_flattened_error(): @pytest.mark.asyncio async def test_list_backup_plans_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1213,7 +1627,7 @@ async def test_list_backup_plans_flattened_async(): @pytest.mark.asyncio async def test_list_backup_plans_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1227,7 +1641,7 @@ async def test_list_backup_plans_flattened_error_async(): def test_list_backup_plans_pager(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1279,7 +1693,7 @@ def test_list_backup_plans_pager(transport_name: str = "grpc"): def test_list_backup_plans_pages(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1323,7 +1737,7 @@ def test_list_backup_plans_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_backup_plans_async_pager(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1375,7 +1789,7 @@ async def test_list_backup_plans_async_pager(): @pytest.mark.asyncio async def test_list_backup_plans_async_pages(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1432,7 +1846,7 @@ async def test_list_backup_plans_async_pages(): ) def test_get_backup_plan(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1478,7 +1892,7 @@ def test_get_backup_plan_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1495,7 +1909,7 @@ async def test_get_backup_plan_async( transport: str = "grpc_asyncio", request_type=gkebackup.GetBackupPlanRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1546,7 +1960,7 @@ async def test_get_backup_plan_async_from_dict(): def test_get_backup_plan_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1576,7 +1990,7 @@ def test_get_backup_plan_field_headers(): @pytest.mark.asyncio async def test_get_backup_plan_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1607,7 +2021,7 @@ async def test_get_backup_plan_field_headers_async(): def test_get_backup_plan_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1631,7 +2045,7 @@ def test_get_backup_plan_flattened(): def test_get_backup_plan_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1646,7 +2060,7 @@ def test_get_backup_plan_flattened_error(): @pytest.mark.asyncio async def test_get_backup_plan_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1675,7 +2089,7 @@ async def test_get_backup_plan_flattened_async(): @pytest.mark.asyncio async def test_get_backup_plan_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1696,7 +2110,7 @@ async def test_get_backup_plan_flattened_error_async(): ) def test_update_backup_plan(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1725,7 +2139,7 @@ def test_update_backup_plan_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1744,7 +2158,7 @@ async def test_update_backup_plan_async( transport: str = "grpc_asyncio", request_type=gkebackup.UpdateBackupPlanRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1778,7 +2192,7 @@ async def test_update_backup_plan_async_from_dict(): def test_update_backup_plan_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1810,7 +2224,7 @@ def test_update_backup_plan_field_headers(): @pytest.mark.asyncio async def test_update_backup_plan_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1843,7 +2257,7 @@ async def test_update_backup_plan_field_headers_async(): def test_update_backup_plan_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1873,7 +2287,7 @@ def test_update_backup_plan_flattened(): def test_update_backup_plan_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1889,7 +2303,7 @@ def test_update_backup_plan_flattened_error(): @pytest.mark.asyncio async def test_update_backup_plan_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1924,7 +2338,7 @@ async def test_update_backup_plan_flattened_async(): @pytest.mark.asyncio async def test_update_backup_plan_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1946,7 +2360,7 @@ async def test_update_backup_plan_flattened_error_async(): ) def test_delete_backup_plan(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1975,7 +2389,7 @@ def test_delete_backup_plan_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1994,7 +2408,7 @@ async def test_delete_backup_plan_async( transport: str = "grpc_asyncio", request_type=gkebackup.DeleteBackupPlanRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2028,7 +2442,7 @@ async def test_delete_backup_plan_async_from_dict(): def test_delete_backup_plan_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2060,7 +2474,7 @@ def test_delete_backup_plan_field_headers(): @pytest.mark.asyncio async def test_delete_backup_plan_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2093,7 +2507,7 @@ async def test_delete_backup_plan_field_headers_async(): def test_delete_backup_plan_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2119,7 +2533,7 @@ def test_delete_backup_plan_flattened(): def test_delete_backup_plan_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2134,7 +2548,7 @@ def test_delete_backup_plan_flattened_error(): @pytest.mark.asyncio async def test_delete_backup_plan_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2165,7 +2579,7 @@ async def test_delete_backup_plan_flattened_async(): @pytest.mark.asyncio async def test_delete_backup_plan_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2186,7 +2600,7 @@ async def test_delete_backup_plan_flattened_error_async(): ) def test_create_backup(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2213,7 +2627,7 @@ def test_create_backup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2230,7 +2644,7 @@ async def test_create_backup_async( transport: str = "grpc_asyncio", request_type=gkebackup.CreateBackupRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2262,7 +2676,7 @@ async def test_create_backup_async_from_dict(): def test_create_backup_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2292,7 +2706,7 @@ def test_create_backup_field_headers(): @pytest.mark.asyncio async def test_create_backup_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2323,7 +2737,7 @@ async def test_create_backup_field_headers_async(): def test_create_backup_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2355,7 +2769,7 @@ def test_create_backup_flattened(): def test_create_backup_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2372,7 +2786,7 @@ def test_create_backup_flattened_error(): @pytest.mark.asyncio async def test_create_backup_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2409,7 +2823,7 @@ async def test_create_backup_flattened_async(): @pytest.mark.asyncio async def test_create_backup_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2432,7 +2846,7 @@ async def test_create_backup_flattened_error_async(): ) def test_list_backups(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2462,7 +2876,7 @@ def test_list_backups_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2479,7 +2893,7 @@ async def test_list_backups_async( transport: str = "grpc_asyncio", request_type=gkebackup.ListBackupsRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2514,7 +2928,7 @@ async def test_list_backups_async_from_dict(): def test_list_backups_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2544,7 +2958,7 @@ def test_list_backups_field_headers(): @pytest.mark.asyncio async def test_list_backups_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2575,7 +2989,7 @@ async def test_list_backups_field_headers_async(): def test_list_backups_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2599,7 +3013,7 @@ def test_list_backups_flattened(): def test_list_backups_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2614,7 +3028,7 @@ def test_list_backups_flattened_error(): @pytest.mark.asyncio async def test_list_backups_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2643,7 +3057,7 @@ async def test_list_backups_flattened_async(): @pytest.mark.asyncio async def test_list_backups_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2657,7 +3071,7 @@ async def test_list_backups_flattened_error_async(): def test_list_backups_pager(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2707,7 +3121,7 @@ def test_list_backups_pager(transport_name: str = "grpc"): def test_list_backups_pages(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2749,7 +3163,7 @@ def test_list_backups_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_backups_async_pager(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2799,7 +3213,7 @@ async def test_list_backups_async_pager(): @pytest.mark.asyncio async def test_list_backups_async_pages(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2854,7 +3268,7 @@ async def test_list_backups_async_pages(): ) def test_get_backup(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2915,7 +3329,7 @@ def test_get_backup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2932,7 +3346,7 @@ async def test_get_backup_async( transport: str = "grpc_asyncio", request_type=gkebackup.GetBackupRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2997,7 +3411,7 @@ async def test_get_backup_async_from_dict(): def test_get_backup_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3027,7 +3441,7 @@ def test_get_backup_field_headers(): @pytest.mark.asyncio async def test_get_backup_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3056,7 +3470,7 @@ async def test_get_backup_field_headers_async(): def test_get_backup_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3080,7 +3494,7 @@ def test_get_backup_flattened(): def test_get_backup_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3095,7 +3509,7 @@ def test_get_backup_flattened_error(): @pytest.mark.asyncio async def test_get_backup_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3122,7 +3536,7 @@ async def test_get_backup_flattened_async(): @pytest.mark.asyncio async def test_get_backup_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3143,7 +3557,7 @@ async def test_get_backup_flattened_error_async(): ) def test_update_backup(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3170,7 +3584,7 @@ def test_update_backup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3187,7 +3601,7 @@ async def test_update_backup_async( transport: str = "grpc_asyncio", request_type=gkebackup.UpdateBackupRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3219,7 +3633,7 @@ async def test_update_backup_async_from_dict(): def test_update_backup_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3249,7 +3663,7 @@ def test_update_backup_field_headers(): @pytest.mark.asyncio async def test_update_backup_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3280,7 +3694,7 @@ async def test_update_backup_field_headers_async(): def test_update_backup_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3308,7 +3722,7 @@ def test_update_backup_flattened(): def test_update_backup_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3324,7 +3738,7 @@ def test_update_backup_flattened_error(): @pytest.mark.asyncio async def test_update_backup_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3357,7 +3771,7 @@ async def test_update_backup_flattened_async(): @pytest.mark.asyncio async def test_update_backup_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3379,7 +3793,7 @@ async def test_update_backup_flattened_error_async(): ) def test_delete_backup(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3406,7 +3820,7 @@ def test_delete_backup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3423,7 +3837,7 @@ async def test_delete_backup_async( transport: str = "grpc_asyncio", request_type=gkebackup.DeleteBackupRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3455,7 +3869,7 @@ async def test_delete_backup_async_from_dict(): def test_delete_backup_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3485,7 +3899,7 @@ def test_delete_backup_field_headers(): @pytest.mark.asyncio async def test_delete_backup_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3516,7 +3930,7 @@ async def test_delete_backup_field_headers_async(): def test_delete_backup_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3540,7 +3954,7 @@ def test_delete_backup_flattened(): def test_delete_backup_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3555,7 +3969,7 @@ def test_delete_backup_flattened_error(): @pytest.mark.asyncio async def test_delete_backup_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3584,7 +3998,7 @@ async def test_delete_backup_flattened_async(): @pytest.mark.asyncio async def test_delete_backup_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3605,7 +4019,7 @@ async def test_delete_backup_flattened_error_async(): ) def test_list_volume_backups(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3637,7 +4051,7 @@ def test_list_volume_backups_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3656,7 +4070,7 @@ async def test_list_volume_backups_async( transport: str = "grpc_asyncio", request_type=gkebackup.ListVolumeBackupsRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3693,7 +4107,7 @@ async def test_list_volume_backups_async_from_dict(): def test_list_volume_backups_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3725,7 +4139,7 @@ def test_list_volume_backups_field_headers(): @pytest.mark.asyncio async def test_list_volume_backups_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3758,7 +4172,7 @@ async def test_list_volume_backups_field_headers_async(): def test_list_volume_backups_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3784,7 +4198,7 @@ def test_list_volume_backups_flattened(): def test_list_volume_backups_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3799,7 +4213,7 @@ def test_list_volume_backups_flattened_error(): @pytest.mark.asyncio async def test_list_volume_backups_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3830,7 +4244,7 @@ async def test_list_volume_backups_flattened_async(): @pytest.mark.asyncio async def test_list_volume_backups_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3844,7 +4258,7 @@ async def test_list_volume_backups_flattened_error_async(): def test_list_volume_backups_pager(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3896,7 +4310,7 @@ def test_list_volume_backups_pager(transport_name: str = "grpc"): def test_list_volume_backups_pages(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3940,7 +4354,7 @@ def test_list_volume_backups_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_volume_backups_async_pager(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3992,7 +4406,7 @@ async def test_list_volume_backups_async_pager(): @pytest.mark.asyncio async def test_list_volume_backups_async_pages(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4049,7 +4463,7 @@ async def test_list_volume_backups_async_pages(): ) def test_get_volume_backup(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4099,7 +4513,7 @@ def test_get_volume_backup_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4118,7 +4532,7 @@ async def test_get_volume_backup_async( transport: str = "grpc_asyncio", request_type=gkebackup.GetVolumeBackupRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4173,7 +4587,7 @@ async def test_get_volume_backup_async_from_dict(): def test_get_volume_backup_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4205,7 +4619,7 @@ def test_get_volume_backup_field_headers(): @pytest.mark.asyncio async def test_get_volume_backup_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4236,7 +4650,7 @@ async def test_get_volume_backup_field_headers_async(): def test_get_volume_backup_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4262,7 +4676,7 @@ def test_get_volume_backup_flattened(): def test_get_volume_backup_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4277,7 +4691,7 @@ def test_get_volume_backup_flattened_error(): @pytest.mark.asyncio async def test_get_volume_backup_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4306,7 +4720,7 @@ async def test_get_volume_backup_flattened_async(): @pytest.mark.asyncio async def test_get_volume_backup_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4327,7 +4741,7 @@ async def test_get_volume_backup_flattened_error_async(): ) def test_create_restore_plan(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4356,7 +4770,7 @@ def test_create_restore_plan_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4375,7 +4789,7 @@ async def test_create_restore_plan_async( transport: str = "grpc_asyncio", request_type=gkebackup.CreateRestorePlanRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4409,7 +4823,7 @@ async def test_create_restore_plan_async_from_dict(): def test_create_restore_plan_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4441,7 +4855,7 @@ def test_create_restore_plan_field_headers(): @pytest.mark.asyncio async def test_create_restore_plan_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4474,7 +4888,7 @@ async def test_create_restore_plan_field_headers_async(): def test_create_restore_plan_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4508,7 +4922,7 @@ def test_create_restore_plan_flattened(): def test_create_restore_plan_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4525,7 +4939,7 @@ def test_create_restore_plan_flattened_error(): @pytest.mark.asyncio async def test_create_restore_plan_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4564,7 +4978,7 @@ async def test_create_restore_plan_flattened_async(): @pytest.mark.asyncio async def test_create_restore_plan_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4587,7 +5001,7 @@ async def test_create_restore_plan_flattened_error_async(): ) def test_list_restore_plans(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4621,7 +5035,7 @@ def test_list_restore_plans_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4640,7 +5054,7 @@ async def test_list_restore_plans_async( transport: str = "grpc_asyncio", request_type=gkebackup.ListRestorePlansRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4679,7 +5093,7 @@ async def test_list_restore_plans_async_from_dict(): def test_list_restore_plans_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4711,7 +5125,7 @@ def test_list_restore_plans_field_headers(): @pytest.mark.asyncio async def test_list_restore_plans_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4744,7 +5158,7 @@ async def test_list_restore_plans_field_headers_async(): def test_list_restore_plans_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4770,7 +5184,7 @@ def test_list_restore_plans_flattened(): def test_list_restore_plans_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4785,7 +5199,7 @@ def test_list_restore_plans_flattened_error(): @pytest.mark.asyncio async def test_list_restore_plans_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4816,7 +5230,7 @@ async def test_list_restore_plans_flattened_async(): @pytest.mark.asyncio async def test_list_restore_plans_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4830,7 +5244,7 @@ async def test_list_restore_plans_flattened_error_async(): def test_list_restore_plans_pager(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4882,7 +5296,7 @@ def test_list_restore_plans_pager(transport_name: str = "grpc"): def test_list_restore_plans_pages(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4926,7 +5340,7 @@ def test_list_restore_plans_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_restore_plans_async_pager(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4978,7 +5392,7 @@ async def test_list_restore_plans_async_pager(): @pytest.mark.asyncio async def test_list_restore_plans_async_pages(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5035,7 +5449,7 @@ async def test_list_restore_plans_async_pages(): ) def test_get_restore_plan(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5079,7 +5493,7 @@ def test_get_restore_plan_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5096,7 +5510,7 @@ async def test_get_restore_plan_async( transport: str = "grpc_asyncio", request_type=gkebackup.GetRestorePlanRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5145,7 +5559,7 @@ async def test_get_restore_plan_async_from_dict(): def test_get_restore_plan_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5175,7 +5589,7 @@ def test_get_restore_plan_field_headers(): @pytest.mark.asyncio async def test_get_restore_plan_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5206,7 +5620,7 @@ async def test_get_restore_plan_field_headers_async(): def test_get_restore_plan_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5230,7 +5644,7 @@ def test_get_restore_plan_flattened(): def test_get_restore_plan_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5245,7 +5659,7 @@ def test_get_restore_plan_flattened_error(): @pytest.mark.asyncio async def test_get_restore_plan_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5274,7 +5688,7 @@ async def test_get_restore_plan_flattened_async(): @pytest.mark.asyncio async def test_get_restore_plan_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5295,7 +5709,7 @@ async def test_get_restore_plan_flattened_error_async(): ) def test_update_restore_plan(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5324,7 +5738,7 @@ def test_update_restore_plan_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5343,7 +5757,7 @@ async def test_update_restore_plan_async( transport: str = "grpc_asyncio", request_type=gkebackup.UpdateRestorePlanRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5377,7 +5791,7 @@ async def test_update_restore_plan_async_from_dict(): def test_update_restore_plan_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5409,7 +5823,7 @@ def test_update_restore_plan_field_headers(): @pytest.mark.asyncio async def test_update_restore_plan_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5442,7 +5856,7 @@ async def test_update_restore_plan_field_headers_async(): def test_update_restore_plan_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5472,7 +5886,7 @@ def test_update_restore_plan_flattened(): def test_update_restore_plan_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5488,7 +5902,7 @@ def test_update_restore_plan_flattened_error(): @pytest.mark.asyncio async def test_update_restore_plan_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5523,7 +5937,7 @@ async def test_update_restore_plan_flattened_async(): @pytest.mark.asyncio async def test_update_restore_plan_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5545,7 +5959,7 @@ async def test_update_restore_plan_flattened_error_async(): ) def test_delete_restore_plan(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5574,7 +5988,7 @@ def test_delete_restore_plan_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5593,7 +6007,7 @@ async def test_delete_restore_plan_async( transport: str = "grpc_asyncio", request_type=gkebackup.DeleteRestorePlanRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5627,7 +6041,7 @@ async def test_delete_restore_plan_async_from_dict(): def test_delete_restore_plan_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5659,7 +6073,7 @@ def test_delete_restore_plan_field_headers(): @pytest.mark.asyncio async def test_delete_restore_plan_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5692,7 +6106,7 @@ async def test_delete_restore_plan_field_headers_async(): def test_delete_restore_plan_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5718,7 +6132,7 @@ def test_delete_restore_plan_flattened(): def test_delete_restore_plan_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5733,7 +6147,7 @@ def test_delete_restore_plan_flattened_error(): @pytest.mark.asyncio async def test_delete_restore_plan_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5764,7 +6178,7 @@ async def test_delete_restore_plan_flattened_async(): @pytest.mark.asyncio async def test_delete_restore_plan_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5785,7 +6199,7 @@ async def test_delete_restore_plan_flattened_error_async(): ) def test_create_restore(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5812,7 +6226,7 @@ def test_create_restore_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5829,7 +6243,7 @@ async def test_create_restore_async( transport: str = "grpc_asyncio", request_type=gkebackup.CreateRestoreRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5861,7 +6275,7 @@ async def test_create_restore_async_from_dict(): def test_create_restore_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5891,7 +6305,7 @@ def test_create_restore_field_headers(): @pytest.mark.asyncio async def test_create_restore_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5922,7 +6336,7 @@ async def test_create_restore_field_headers_async(): def test_create_restore_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5954,7 +6368,7 @@ def test_create_restore_flattened(): def test_create_restore_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5971,7 +6385,7 @@ def test_create_restore_flattened_error(): @pytest.mark.asyncio async def test_create_restore_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6008,7 +6422,7 @@ async def test_create_restore_flattened_async(): @pytest.mark.asyncio async def test_create_restore_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6031,7 +6445,7 @@ async def test_create_restore_flattened_error_async(): ) def test_list_restores(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6063,7 +6477,7 @@ def test_list_restores_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6080,7 +6494,7 @@ async def test_list_restores_async( transport: str = "grpc_asyncio", request_type=gkebackup.ListRestoresRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6117,7 +6531,7 @@ async def test_list_restores_async_from_dict(): def test_list_restores_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6147,7 +6561,7 @@ def test_list_restores_field_headers(): @pytest.mark.asyncio async def test_list_restores_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6178,7 +6592,7 @@ async def test_list_restores_field_headers_async(): def test_list_restores_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6202,7 +6616,7 @@ def test_list_restores_flattened(): def test_list_restores_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6217,7 +6631,7 @@ def test_list_restores_flattened_error(): @pytest.mark.asyncio async def test_list_restores_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6246,7 +6660,7 @@ async def test_list_restores_flattened_async(): @pytest.mark.asyncio async def test_list_restores_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6260,7 +6674,7 @@ async def test_list_restores_flattened_error_async(): def test_list_restores_pager(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6310,7 +6724,7 @@ def test_list_restores_pager(transport_name: str = "grpc"): def test_list_restores_pages(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -6352,7 +6766,7 @@ def test_list_restores_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_restores_async_pager(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6402,7 +6816,7 @@ async def test_list_restores_async_pager(): @pytest.mark.asyncio async def test_list_restores_async_pages(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6457,7 +6871,7 @@ async def test_list_restores_async_pages(): ) def test_get_restore(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6509,7 +6923,7 @@ def test_get_restore_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6526,7 +6940,7 @@ async def test_get_restore_async( transport: str = "grpc_asyncio", request_type=gkebackup.GetRestoreRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6583,7 +6997,7 @@ async def test_get_restore_async_from_dict(): def test_get_restore_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6613,7 +7027,7 @@ def test_get_restore_field_headers(): @pytest.mark.asyncio async def test_get_restore_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6642,7 +7056,7 @@ async def test_get_restore_field_headers_async(): def test_get_restore_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6666,7 +7080,7 @@ def test_get_restore_flattened(): def test_get_restore_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6681,7 +7095,7 @@ def test_get_restore_flattened_error(): @pytest.mark.asyncio async def test_get_restore_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6708,7 +7122,7 @@ async def test_get_restore_flattened_async(): @pytest.mark.asyncio async def test_get_restore_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6729,7 +7143,7 @@ async def test_get_restore_flattened_error_async(): ) def test_update_restore(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6756,7 +7170,7 @@ def test_update_restore_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -6773,7 +7187,7 @@ async def test_update_restore_async( transport: str = "grpc_asyncio", request_type=gkebackup.UpdateRestoreRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6805,7 +7219,7 @@ async def test_update_restore_async_from_dict(): def test_update_restore_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6835,7 +7249,7 @@ def test_update_restore_field_headers(): @pytest.mark.asyncio async def test_update_restore_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -6866,7 +7280,7 @@ async def test_update_restore_field_headers_async(): def test_update_restore_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6894,7 +7308,7 @@ def test_update_restore_flattened(): def test_update_restore_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6910,7 +7324,7 @@ def test_update_restore_flattened_error(): @pytest.mark.asyncio async def test_update_restore_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6943,7 +7357,7 @@ async def test_update_restore_flattened_async(): @pytest.mark.asyncio async def test_update_restore_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -6965,7 +7379,7 @@ async def test_update_restore_flattened_error_async(): ) def test_delete_restore(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6992,7 +7406,7 @@ def test_delete_restore_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7009,7 +7423,7 @@ async def test_delete_restore_async( transport: str = "grpc_asyncio", request_type=gkebackup.DeleteRestoreRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7041,7 +7455,7 @@ async def test_delete_restore_async_from_dict(): def test_delete_restore_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7071,7 +7485,7 @@ def test_delete_restore_field_headers(): @pytest.mark.asyncio async def test_delete_restore_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7102,7 +7516,7 @@ async def test_delete_restore_field_headers_async(): def test_delete_restore_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7126,7 +7540,7 @@ def test_delete_restore_flattened(): def test_delete_restore_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7141,7 +7555,7 @@ def test_delete_restore_flattened_error(): @pytest.mark.asyncio async def test_delete_restore_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7170,7 +7584,7 @@ async def test_delete_restore_flattened_async(): @pytest.mark.asyncio async def test_delete_restore_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7191,7 +7605,7 @@ async def test_delete_restore_flattened_error_async(): ) def test_list_volume_restores(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7223,7 +7637,7 @@ def test_list_volume_restores_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7242,7 +7656,7 @@ async def test_list_volume_restores_async( transport: str = "grpc_asyncio", request_type=gkebackup.ListVolumeRestoresRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7279,7 +7693,7 @@ async def test_list_volume_restores_async_from_dict(): def test_list_volume_restores_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7311,7 +7725,7 @@ def test_list_volume_restores_field_headers(): @pytest.mark.asyncio async def test_list_volume_restores_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7344,7 +7758,7 @@ async def test_list_volume_restores_field_headers_async(): def test_list_volume_restores_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7370,7 +7784,7 @@ def test_list_volume_restores_flattened(): def test_list_volume_restores_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7385,7 +7799,7 @@ def test_list_volume_restores_flattened_error(): @pytest.mark.asyncio async def test_list_volume_restores_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7416,7 +7830,7 @@ async def test_list_volume_restores_flattened_async(): @pytest.mark.asyncio async def test_list_volume_restores_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7430,7 +7844,7 @@ async def test_list_volume_restores_flattened_error_async(): def test_list_volume_restores_pager(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -7482,7 +7896,7 @@ def test_list_volume_restores_pager(transport_name: str = "grpc"): def test_list_volume_restores_pages(transport_name: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -7526,7 +7940,7 @@ def test_list_volume_restores_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_volume_restores_async_pager(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7578,7 +7992,7 @@ async def test_list_volume_restores_async_pager(): @pytest.mark.asyncio async def test_list_volume_restores_async_pages(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7635,7 +8049,7 @@ async def test_list_volume_restores_async_pages(): ) def test_get_volume_restore(request_type, transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7681,7 +8095,7 @@ def test_get_volume_restore_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -7700,7 +8114,7 @@ async def test_get_volume_restore_async( transport: str = "grpc_asyncio", request_type=gkebackup.GetVolumeRestoreRequest ): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7751,7 +8165,7 @@ async def test_get_volume_restore_async_from_dict(): def test_get_volume_restore_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7783,7 +8197,7 @@ def test_get_volume_restore_field_headers(): @pytest.mark.asyncio async def test_get_volume_restore_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7816,7 +8230,7 @@ async def test_get_volume_restore_field_headers_async(): def test_get_volume_restore_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7842,7 +8256,7 @@ def test_get_volume_restore_flattened(): def test_get_volume_restore_flattened_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7857,7 +8271,7 @@ def test_get_volume_restore_flattened_error(): @pytest.mark.asyncio async def test_get_volume_restore_flattened_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7888,7 +8302,7 @@ async def test_get_volume_restore_flattened_async(): @pytest.mark.asyncio async def test_get_volume_restore_flattened_error_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -7909,7 +8323,7 @@ async def test_get_volume_restore_flattened_error_async(): ) def test_create_backup_plan_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8060,7 +8474,7 @@ def test_create_backup_plan_rest_required_fields( assert "backupPlanId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_backup_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8072,7 +8486,7 @@ def test_create_backup_plan_rest_required_fields( jsonified_request["backupPlanId"] = "backup_plan_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_backup_plan._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("backup_plan_id",)) @@ -8085,7 +8499,7 @@ def test_create_backup_plan_rest_required_fields( assert jsonified_request["backupPlanId"] == "backup_plan_id_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8131,7 +8545,7 @@ def test_create_backup_plan_rest_required_fields( def test_create_backup_plan_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_backup_plan._get_unset_required_fields({}) @@ -8150,7 +8564,7 @@ def test_create_backup_plan_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_backup_plan_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -8210,7 +8624,7 @@ def test_create_backup_plan_rest_bad_request( transport: str = "rest", request_type=gkebackup.CreateBackupPlanRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8232,7 +8646,7 @@ def test_create_backup_plan_rest_bad_request( def test_create_backup_plan_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8274,7 +8688,7 @@ def test_create_backup_plan_rest_flattened(): def test_create_backup_plan_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8291,7 +8705,7 @@ def test_create_backup_plan_rest_flattened_error(transport: str = "rest"): def test_create_backup_plan_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8304,7 +8718,7 @@ def test_create_backup_plan_rest_error(): ) def test_list_backup_plans_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8357,7 +8771,7 @@ def test_list_backup_plans_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_backup_plans._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8366,7 +8780,7 @@ def test_list_backup_plans_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_backup_plans._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8384,7 +8798,7 @@ def test_list_backup_plans_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8426,7 +8840,7 @@ def test_list_backup_plans_rest_required_fields( def test_list_backup_plans_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_backup_plans._get_unset_required_fields({}) @@ -8446,7 +8860,7 @@ def test_list_backup_plans_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_backup_plans_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -8504,7 +8918,7 @@ def test_list_backup_plans_rest_bad_request( transport: str = "rest", request_type=gkebackup.ListBackupPlansRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8526,7 +8940,7 @@ def test_list_backup_plans_rest_bad_request( def test_list_backup_plans_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8568,7 +8982,7 @@ def test_list_backup_plans_rest_flattened(): def test_list_backup_plans_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8583,7 +8997,7 @@ def test_list_backup_plans_rest_flattened_error(transport: str = "rest"): def test_list_backup_plans_rest_pager(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8651,7 +9065,7 @@ def test_list_backup_plans_rest_pager(transport: str = "rest"): ) def test_get_backup_plan_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8718,7 +9132,7 @@ def test_get_backup_plan_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_backup_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8727,7 +9141,7 @@ def test_get_backup_plan_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_backup_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8736,7 +9150,7 @@ def test_get_backup_plan_rest_required_fields( assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8778,7 +9192,7 @@ def test_get_backup_plan_rest_required_fields( def test_get_backup_plan_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_backup_plan._get_unset_required_fields({}) @@ -8788,7 +9202,7 @@ def test_get_backup_plan_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_backup_plan_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -8844,7 +9258,7 @@ def test_get_backup_plan_rest_bad_request( transport: str = "rest", request_type=gkebackup.GetBackupPlanRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8866,7 +9280,7 @@ def test_get_backup_plan_rest_bad_request( def test_get_backup_plan_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8910,7 +9324,7 @@ def test_get_backup_plan_rest_flattened(): def test_get_backup_plan_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8925,7 +9339,7 @@ def test_get_backup_plan_rest_flattened_error(transport: str = "rest"): def test_get_backup_plan_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8938,7 +9352,7 @@ def test_get_backup_plan_rest_error(): ) def test_update_backup_plan_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9090,14 +9504,14 @@ def test_update_backup_plan_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_backup_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_backup_plan._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -9106,7 +9520,7 @@ def test_update_backup_plan_rest_required_fields( # verify required fields with non-default values are left alone client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9146,7 +9560,7 @@ def test_update_backup_plan_rest_required_fields( def test_update_backup_plan_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_backup_plan._get_unset_required_fields({}) @@ -9156,7 +9570,7 @@ def test_update_backup_plan_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_backup_plan_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -9216,7 +9630,7 @@ def test_update_backup_plan_rest_bad_request( transport: str = "rest", request_type=gkebackup.UpdateBackupPlanRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9242,7 +9656,7 @@ def test_update_backup_plan_rest_bad_request( def test_update_backup_plan_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9287,7 +9701,7 @@ def test_update_backup_plan_rest_flattened(): def test_update_backup_plan_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9303,7 +9717,7 @@ def test_update_backup_plan_rest_flattened_error(transport: str = "rest"): def test_update_backup_plan_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9316,7 +9730,7 @@ def test_update_backup_plan_rest_error(): ) def test_delete_backup_plan_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9362,7 +9776,7 @@ def test_delete_backup_plan_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_backup_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9371,7 +9785,7 @@ def test_delete_backup_plan_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_backup_plan._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("etag",)) @@ -9382,7 +9796,7 @@ def test_delete_backup_plan_rest_required_fields( assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9421,7 +9835,7 @@ def test_delete_backup_plan_rest_required_fields( def test_delete_backup_plan_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_backup_plan._get_unset_required_fields({}) @@ -9431,7 +9845,7 @@ def test_delete_backup_plan_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_backup_plan_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -9491,7 +9905,7 @@ def test_delete_backup_plan_rest_bad_request( transport: str = "rest", request_type=gkebackup.DeleteBackupPlanRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9513,7 +9927,7 @@ def test_delete_backup_plan_rest_bad_request( def test_delete_backup_plan_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9555,7 +9969,7 @@ def test_delete_backup_plan_rest_flattened(): def test_delete_backup_plan_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9570,7 +9984,7 @@ def test_delete_backup_plan_rest_flattened_error(transport: str = "rest"): def test_delete_backup_plan_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9583,7 +9997,7 @@ def test_delete_backup_plan_rest_error(): ) def test_create_backup_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9733,7 +10147,7 @@ def test_create_backup_rest_required_fields(request_type=gkebackup.CreateBackupR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9742,7 +10156,7 @@ def test_create_backup_rest_required_fields(request_type=gkebackup.CreateBackupR jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_backup._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("backup_id",)) @@ -9753,7 +10167,7 @@ def test_create_backup_rest_required_fields(request_type=gkebackup.CreateBackupR assert jsonified_request["parent"] == "parent_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9793,7 +10207,7 @@ def test_create_backup_rest_required_fields(request_type=gkebackup.CreateBackupR def test_create_backup_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_backup._get_unset_required_fields({}) @@ -9803,7 +10217,7 @@ def test_create_backup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_backup_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -9861,7 +10275,7 @@ def test_create_backup_rest_bad_request( transport: str = "rest", request_type=gkebackup.CreateBackupRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9883,7 +10297,7 @@ def test_create_backup_rest_bad_request( def test_create_backup_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9927,7 +10341,7 @@ def test_create_backup_rest_flattened(): def test_create_backup_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9944,7 +10358,7 @@ def test_create_backup_rest_flattened_error(transport: str = "rest"): def test_create_backup_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9957,7 +10371,7 @@ def test_create_backup_rest_error(): ) def test_list_backups_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10006,7 +10420,7 @@ def test_list_backups_rest_required_fields(request_type=gkebackup.ListBackupsReq # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_backups._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10015,7 +10429,7 @@ def test_list_backups_rest_required_fields(request_type=gkebackup.ListBackupsReq jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_backups._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -10033,7 +10447,7 @@ def test_list_backups_rest_required_fields(request_type=gkebackup.ListBackupsReq assert jsonified_request["parent"] == "parent_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10075,7 +10489,7 @@ def test_list_backups_rest_required_fields(request_type=gkebackup.ListBackupsReq def test_list_backups_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_backups._get_unset_required_fields({}) @@ -10095,7 +10509,7 @@ def test_list_backups_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_backups_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -10151,7 +10565,7 @@ def test_list_backups_rest_bad_request( transport: str = "rest", request_type=gkebackup.ListBackupsRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10173,7 +10587,7 @@ def test_list_backups_rest_bad_request( def test_list_backups_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10217,7 +10631,7 @@ def test_list_backups_rest_flattened(): def test_list_backups_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10232,7 +10646,7 @@ def test_list_backups_rest_flattened_error(transport: str = "rest"): def test_list_backups_rest_pager(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10302,7 +10716,7 @@ def test_list_backups_rest_pager(transport: str = "rest"): ) def test_get_backup_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10384,7 +10798,7 @@ def test_get_backup_rest_required_fields(request_type=gkebackup.GetBackupRequest # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10393,7 +10807,7 @@ def test_get_backup_rest_required_fields(request_type=gkebackup.GetBackupRequest jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10402,7 +10816,7 @@ def test_get_backup_rest_required_fields(request_type=gkebackup.GetBackupRequest assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10444,7 +10858,7 @@ def test_get_backup_rest_required_fields(request_type=gkebackup.GetBackupRequest def test_get_backup_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_backup._get_unset_required_fields({}) @@ -10454,7 +10868,7 @@ def test_get_backup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_backup_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -10508,7 +10922,7 @@ def test_get_backup_rest_bad_request( transport: str = "rest", request_type=gkebackup.GetBackupRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10532,7 +10946,7 @@ def test_get_backup_rest_bad_request( def test_get_backup_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10576,7 +10990,7 @@ def test_get_backup_rest_flattened(): def test_get_backup_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10591,7 +11005,7 @@ def test_get_backup_rest_flattened_error(transport: str = "rest"): def test_get_backup_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10604,7 +11018,7 @@ def test_get_backup_rest_error(): ) def test_update_backup_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10757,14 +11171,14 @@ def test_update_backup_rest_required_fields(request_type=gkebackup.UpdateBackupR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_backup._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -10773,7 +11187,7 @@ def test_update_backup_rest_required_fields(request_type=gkebackup.UpdateBackupR # verify required fields with non-default values are left alone client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10813,7 +11227,7 @@ def test_update_backup_rest_required_fields(request_type=gkebackup.UpdateBackupR def test_update_backup_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_backup._get_unset_required_fields({}) @@ -10823,7 +11237,7 @@ def test_update_backup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_backup_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -10881,7 +11295,7 @@ def test_update_backup_rest_bad_request( transport: str = "rest", request_type=gkebackup.UpdateBackupRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10907,7 +11321,7 @@ def test_update_backup_rest_bad_request( def test_update_backup_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10952,7 +11366,7 @@ def test_update_backup_rest_flattened(): def test_update_backup_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10968,7 +11382,7 @@ def test_update_backup_rest_flattened_error(transport: str = "rest"): def test_update_backup_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10981,7 +11395,7 @@ def test_update_backup_rest_error(): ) def test_delete_backup_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11027,7 +11441,7 @@ def test_delete_backup_rest_required_fields(request_type=gkebackup.DeleteBackupR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11036,7 +11450,7 @@ def test_delete_backup_rest_required_fields(request_type=gkebackup.DeleteBackupR jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_backup._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -11052,7 +11466,7 @@ def test_delete_backup_rest_required_fields(request_type=gkebackup.DeleteBackupR assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11091,7 +11505,7 @@ def test_delete_backup_rest_required_fields(request_type=gkebackup.DeleteBackupR def test_delete_backup_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_backup._get_unset_required_fields({}) @@ -11109,7 +11523,7 @@ def test_delete_backup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_backup_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -11167,7 +11581,7 @@ def test_delete_backup_rest_bad_request( transport: str = "rest", request_type=gkebackup.DeleteBackupRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11191,7 +11605,7 @@ def test_delete_backup_rest_bad_request( def test_delete_backup_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11233,7 +11647,7 @@ def test_delete_backup_rest_flattened(): def test_delete_backup_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11248,7 +11662,7 @@ def test_delete_backup_rest_flattened_error(transport: str = "rest"): def test_delete_backup_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11261,7 +11675,7 @@ def test_delete_backup_rest_error(): ) def test_list_volume_backups_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11314,7 +11728,7 @@ def test_list_volume_backups_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_volume_backups._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11323,7 +11737,7 @@ def test_list_volume_backups_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_volume_backups._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -11341,7 +11755,7 @@ def test_list_volume_backups_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11383,7 +11797,7 @@ def test_list_volume_backups_rest_required_fields( def test_list_volume_backups_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_volume_backups._get_unset_required_fields({}) @@ -11403,7 +11817,7 @@ def test_list_volume_backups_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_volume_backups_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -11461,7 +11875,7 @@ def test_list_volume_backups_rest_bad_request( transport: str = "rest", request_type=gkebackup.ListVolumeBackupsRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11485,7 +11899,7 @@ def test_list_volume_backups_rest_bad_request( def test_list_volume_backups_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11529,7 +11943,7 @@ def test_list_volume_backups_rest_flattened(): def test_list_volume_backups_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11544,7 +11958,7 @@ def test_list_volume_backups_rest_flattened_error(transport: str = "rest"): def test_list_volume_backups_rest_pager(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11616,7 +12030,7 @@ def test_list_volume_backups_rest_pager(transport: str = "rest"): ) def test_get_volume_backup_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11687,7 +12101,7 @@ def test_get_volume_backup_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_volume_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11696,7 +12110,7 @@ def test_get_volume_backup_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_volume_backup._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11705,7 +12119,7 @@ def test_get_volume_backup_rest_required_fields( assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11747,7 +12161,7 @@ def test_get_volume_backup_rest_required_fields( def test_get_volume_backup_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_volume_backup._get_unset_required_fields({}) @@ -11757,7 +12171,7 @@ def test_get_volume_backup_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_volume_backup_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -11813,7 +12227,7 @@ def test_get_volume_backup_rest_bad_request( transport: str = "rest", request_type=gkebackup.GetVolumeBackupRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11837,7 +12251,7 @@ def test_get_volume_backup_rest_bad_request( def test_get_volume_backup_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11881,7 +12295,7 @@ def test_get_volume_backup_rest_flattened(): def test_get_volume_backup_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11896,7 +12310,7 @@ def test_get_volume_backup_rest_flattened_error(transport: str = "rest"): def test_get_volume_backup_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11909,7 +12323,7 @@ def test_get_volume_backup_rest_error(): ) def test_create_restore_plan_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12094,7 +12508,7 @@ def test_create_restore_plan_rest_required_fields( assert "restorePlanId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_restore_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12106,7 +12520,7 @@ def test_create_restore_plan_rest_required_fields( jsonified_request["restorePlanId"] = "restore_plan_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_restore_plan._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("restore_plan_id",)) @@ -12119,7 +12533,7 @@ def test_create_restore_plan_rest_required_fields( assert jsonified_request["restorePlanId"] == "restore_plan_id_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12165,7 +12579,7 @@ def test_create_restore_plan_rest_required_fields( def test_create_restore_plan_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_restore_plan._get_unset_required_fields({}) @@ -12184,7 +12598,7 @@ def test_create_restore_plan_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_restore_plan_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -12244,7 +12658,7 @@ def test_create_restore_plan_rest_bad_request( transport: str = "rest", request_type=gkebackup.CreateRestorePlanRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12266,7 +12680,7 @@ def test_create_restore_plan_rest_bad_request( def test_create_restore_plan_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12308,7 +12722,7 @@ def test_create_restore_plan_rest_flattened(): def test_create_restore_plan_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12325,7 +12739,7 @@ def test_create_restore_plan_rest_flattened_error(transport: str = "rest"): def test_create_restore_plan_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12338,7 +12752,7 @@ def test_create_restore_plan_rest_error(): ) def test_list_restore_plans_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12391,7 +12805,7 @@ def test_list_restore_plans_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_restore_plans._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12400,7 +12814,7 @@ def test_list_restore_plans_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_restore_plans._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -12418,7 +12832,7 @@ def test_list_restore_plans_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12460,7 +12874,7 @@ def test_list_restore_plans_rest_required_fields( def test_list_restore_plans_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_restore_plans._get_unset_required_fields({}) @@ -12480,7 +12894,7 @@ def test_list_restore_plans_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_restore_plans_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -12538,7 +12952,7 @@ def test_list_restore_plans_rest_bad_request( transport: str = "rest", request_type=gkebackup.ListRestorePlansRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12560,7 +12974,7 @@ def test_list_restore_plans_rest_bad_request( def test_list_restore_plans_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12602,7 +13016,7 @@ def test_list_restore_plans_rest_flattened(): def test_list_restore_plans_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12617,7 +13031,7 @@ def test_list_restore_plans_rest_flattened_error(transport: str = "rest"): def test_list_restore_plans_rest_pager(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12687,7 +13101,7 @@ def test_list_restore_plans_rest_pager(transport: str = "rest"): ) def test_get_restore_plan_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12752,7 +13166,7 @@ def test_get_restore_plan_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_restore_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12761,7 +13175,7 @@ def test_get_restore_plan_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_restore_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -12770,7 +13184,7 @@ def test_get_restore_plan_rest_required_fields( assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -12812,7 +13226,7 @@ def test_get_restore_plan_rest_required_fields( def test_get_restore_plan_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_restore_plan._get_unset_required_fields({}) @@ -12822,7 +13236,7 @@ def test_get_restore_plan_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_restore_plan_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -12880,7 +13294,7 @@ def test_get_restore_plan_rest_bad_request( transport: str = "rest", request_type=gkebackup.GetRestorePlanRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12902,7 +13316,7 @@ def test_get_restore_plan_rest_bad_request( def test_get_restore_plan_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12946,7 +13360,7 @@ def test_get_restore_plan_rest_flattened(): def test_get_restore_plan_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12961,7 +13375,7 @@ def test_get_restore_plan_rest_flattened_error(transport: str = "rest"): def test_get_restore_plan_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -12974,7 +13388,7 @@ def test_get_restore_plan_rest_error(): ) def test_update_restore_plan_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13160,14 +13574,14 @@ def test_update_restore_plan_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_restore_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_restore_plan._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -13176,7 +13590,7 @@ def test_update_restore_plan_rest_required_fields( # verify required fields with non-default values are left alone client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13216,7 +13630,7 @@ def test_update_restore_plan_rest_required_fields( def test_update_restore_plan_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_restore_plan._get_unset_required_fields({}) @@ -13226,7 +13640,7 @@ def test_update_restore_plan_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_restore_plan_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -13286,7 +13700,7 @@ def test_update_restore_plan_rest_bad_request( transport: str = "rest", request_type=gkebackup.UpdateRestorePlanRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13312,7 +13726,7 @@ def test_update_restore_plan_rest_bad_request( def test_update_restore_plan_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13357,7 +13771,7 @@ def test_update_restore_plan_rest_flattened(): def test_update_restore_plan_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13373,7 +13787,7 @@ def test_update_restore_plan_rest_flattened_error(transport: str = "rest"): def test_update_restore_plan_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -13386,7 +13800,7 @@ def test_update_restore_plan_rest_error(): ) def test_delete_restore_plan_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13432,7 +13846,7 @@ def test_delete_restore_plan_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_restore_plan._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13441,7 +13855,7 @@ def test_delete_restore_plan_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_restore_plan._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -13457,7 +13871,7 @@ def test_delete_restore_plan_rest_required_fields( assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13496,7 +13910,7 @@ def test_delete_restore_plan_rest_required_fields( def test_delete_restore_plan_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_restore_plan._get_unset_required_fields({}) @@ -13514,7 +13928,7 @@ def test_delete_restore_plan_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_restore_plan_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -13574,7 +13988,7 @@ def test_delete_restore_plan_rest_bad_request( transport: str = "rest", request_type=gkebackup.DeleteRestorePlanRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13596,7 +14010,7 @@ def test_delete_restore_plan_rest_bad_request( def test_delete_restore_plan_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13638,7 +14052,7 @@ def test_delete_restore_plan_rest_flattened(): def test_delete_restore_plan_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13653,7 +14067,7 @@ def test_delete_restore_plan_rest_flattened_error(transport: str = "rest"): def test_delete_restore_plan_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -13666,7 +14080,7 @@ def test_delete_restore_plan_rest_error(): ) def test_create_restore_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -13856,7 +14270,7 @@ def test_create_restore_rest_required_fields( assert "restoreId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_restore._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -13868,7 +14282,7 @@ def test_create_restore_rest_required_fields( jsonified_request["restoreId"] = "restore_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_restore._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("restore_id",)) @@ -13881,7 +14295,7 @@ def test_create_restore_rest_required_fields( assert jsonified_request["restoreId"] == "restore_id_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -13927,7 +14341,7 @@ def test_create_restore_rest_required_fields( def test_create_restore_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_restore._get_unset_required_fields({}) @@ -13946,7 +14360,7 @@ def test_create_restore_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_restore_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -14004,7 +14418,7 @@ def test_create_restore_rest_bad_request( transport: str = "rest", request_type=gkebackup.CreateRestoreRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14026,7 +14440,7 @@ def test_create_restore_rest_bad_request( def test_create_restore_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14070,7 +14484,7 @@ def test_create_restore_rest_flattened(): def test_create_restore_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14087,7 +14501,7 @@ def test_create_restore_rest_flattened_error(transport: str = "rest"): def test_create_restore_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -14100,7 +14514,7 @@ def test_create_restore_rest_error(): ) def test_list_restores_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14151,7 +14565,7 @@ def test_list_restores_rest_required_fields(request_type=gkebackup.ListRestoresR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_restores._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14160,7 +14574,7 @@ def test_list_restores_rest_required_fields(request_type=gkebackup.ListRestoresR jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_restores._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -14178,7 +14592,7 @@ def test_list_restores_rest_required_fields(request_type=gkebackup.ListRestoresR assert jsonified_request["parent"] == "parent_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14220,7 +14634,7 @@ def test_list_restores_rest_required_fields(request_type=gkebackup.ListRestoresR def test_list_restores_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_restores._get_unset_required_fields({}) @@ -14240,7 +14654,7 @@ def test_list_restores_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_restores_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -14296,7 +14710,7 @@ def test_list_restores_rest_bad_request( transport: str = "rest", request_type=gkebackup.ListRestoresRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14318,7 +14732,7 @@ def test_list_restores_rest_bad_request( def test_list_restores_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14362,7 +14776,7 @@ def test_list_restores_rest_flattened(): def test_list_restores_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14377,7 +14791,7 @@ def test_list_restores_rest_flattened_error(transport: str = "rest"): def test_list_restores_rest_pager(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14447,7 +14861,7 @@ def test_list_restores_rest_pager(transport: str = "rest"): ) def test_get_restore_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14520,7 +14934,7 @@ def test_get_restore_rest_required_fields(request_type=gkebackup.GetRestoreReque # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_restore._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14529,7 +14943,7 @@ def test_get_restore_rest_required_fields(request_type=gkebackup.GetRestoreReque jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_restore._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -14538,7 +14952,7 @@ def test_get_restore_rest_required_fields(request_type=gkebackup.GetRestoreReque assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14580,7 +14994,7 @@ def test_get_restore_rest_required_fields(request_type=gkebackup.GetRestoreReque def test_get_restore_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_restore._get_unset_required_fields({}) @@ -14590,7 +15004,7 @@ def test_get_restore_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_restore_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -14644,7 +15058,7 @@ def test_get_restore_rest_bad_request( transport: str = "rest", request_type=gkebackup.GetRestoreRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14668,7 +15082,7 @@ def test_get_restore_rest_bad_request( def test_get_restore_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14712,7 +15126,7 @@ def test_get_restore_rest_flattened(): def test_get_restore_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -14727,7 +15141,7 @@ def test_get_restore_rest_flattened_error(transport: str = "rest"): def test_get_restore_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -14740,7 +15154,7 @@ def test_get_restore_rest_error(): ) def test_update_restore_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -14931,14 +15345,14 @@ def test_update_restore_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_restore._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_restore._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("update_mask",)) @@ -14947,7 +15361,7 @@ def test_update_restore_rest_required_fields( # verify required fields with non-default values are left alone client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -14987,7 +15401,7 @@ def test_update_restore_rest_required_fields( def test_update_restore_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_restore._get_unset_required_fields({}) @@ -14997,7 +15411,7 @@ def test_update_restore_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_restore_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -15055,7 +15469,7 @@ def test_update_restore_rest_bad_request( transport: str = "rest", request_type=gkebackup.UpdateRestoreRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15081,7 +15495,7 @@ def test_update_restore_rest_bad_request( def test_update_restore_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15126,7 +15540,7 @@ def test_update_restore_rest_flattened(): def test_update_restore_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15142,7 +15556,7 @@ def test_update_restore_rest_flattened_error(transport: str = "rest"): def test_update_restore_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -15155,7 +15569,7 @@ def test_update_restore_rest_error(): ) def test_delete_restore_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15203,7 +15617,7 @@ def test_delete_restore_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_restore._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15212,7 +15626,7 @@ def test_delete_restore_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_restore._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -15228,7 +15642,7 @@ def test_delete_restore_rest_required_fields( assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -15267,7 +15681,7 @@ def test_delete_restore_rest_required_fields( def test_delete_restore_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_restore._get_unset_required_fields({}) @@ -15285,7 +15699,7 @@ def test_delete_restore_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_restore_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -15343,7 +15757,7 @@ def test_delete_restore_rest_bad_request( transport: str = "rest", request_type=gkebackup.DeleteRestoreRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15367,7 +15781,7 @@ def test_delete_restore_rest_bad_request( def test_delete_restore_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15409,7 +15823,7 @@ def test_delete_restore_rest_flattened(): def test_delete_restore_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15424,7 +15838,7 @@ def test_delete_restore_rest_flattened_error(transport: str = "rest"): def test_delete_restore_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -15437,7 +15851,7 @@ def test_delete_restore_rest_error(): ) def test_list_volume_restores_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15490,7 +15904,7 @@ def test_list_volume_restores_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_volume_restores._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15499,7 +15913,7 @@ def test_list_volume_restores_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_volume_restores._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -15517,7 +15931,7 @@ def test_list_volume_restores_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -15559,7 +15973,7 @@ def test_list_volume_restores_rest_required_fields( def test_list_volume_restores_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_volume_restores._get_unset_required_fields({}) @@ -15579,7 +15993,7 @@ def test_list_volume_restores_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_volume_restores_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -15637,7 +16051,7 @@ def test_list_volume_restores_rest_bad_request( transport: str = "rest", request_type=gkebackup.ListVolumeRestoresRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15661,7 +16075,7 @@ def test_list_volume_restores_rest_bad_request( def test_list_volume_restores_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15705,7 +16119,7 @@ def test_list_volume_restores_rest_flattened(): def test_list_volume_restores_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15720,7 +16134,7 @@ def test_list_volume_restores_rest_flattened_error(transport: str = "rest"): def test_list_volume_restores_rest_pager(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -15792,7 +16206,7 @@ def test_list_volume_restores_rest_pager(transport: str = "rest"): ) def test_get_volume_restore_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -15859,7 +16273,7 @@ def test_get_volume_restore_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_volume_restore._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15868,7 +16282,7 @@ def test_get_volume_restore_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_volume_restore._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -15877,7 +16291,7 @@ def test_get_volume_restore_rest_required_fields( assert jsonified_request["name"] == "name_value" client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -15919,7 +16333,7 @@ def test_get_volume_restore_rest_required_fields( def test_get_volume_restore_rest_unset_required_fields(): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_volume_restore._get_unset_required_fields({}) @@ -15929,7 +16343,7 @@ def test_get_volume_restore_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_volume_restore_rest_interceptors(null_interceptor): transport = transports.BackupForGKERestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.BackupForGKERestInterceptor(), @@ -15985,7 +16399,7 @@ def test_get_volume_restore_rest_bad_request( transport: str = "rest", request_type=gkebackup.GetVolumeRestoreRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16009,7 +16423,7 @@ def test_get_volume_restore_rest_bad_request( def test_get_volume_restore_rest_flattened(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -16053,7 +16467,7 @@ def test_get_volume_restore_rest_flattened(): def test_get_volume_restore_rest_flattened_error(transport: str = "rest"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -16068,24 +16482,24 @@ def test_get_volume_restore_rest_flattened_error(transport: str = "rest"): def test_get_volume_restore_rest_error(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.BackupForGKEGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.BackupForGKEGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = BackupForGKEClient( @@ -16095,7 +16509,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.BackupForGKEGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -16106,16 +16520,17 @@ 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 = BackupForGKEClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.BackupForGKEGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = BackupForGKEClient( @@ -16127,7 +16542,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.BackupForGKEGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = BackupForGKEClient(transport=transport) assert client.transport is transport @@ -16136,13 +16551,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.BackupForGKEGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.BackupForGKEGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -16159,7 +16574,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -16173,7 +16588,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = BackupForGKEClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -16181,7 +16596,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -16193,7 +16608,7 @@ def test_backup_for_gke_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.BackupForGKETransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -16205,7 +16620,7 @@ def test_backup_for_gke_base_transport(): ) as Transport: Transport.return_value = None transport = transports.BackupForGKETransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -16274,7 +16689,7 @@ def test_backup_for_gke_base_transport_with_credentials_file(): "google.cloud.gke_backup_v1.services.backup_for_gke.transports.BackupForGKETransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.BackupForGKETransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -16293,7 +16708,7 @@ def test_backup_for_gke_base_transport_with_adc(): "google.cloud.gke_backup_v1.services.backup_for_gke.transports.BackupForGKETransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.BackupForGKETransport() adc.assert_called_once() @@ -16301,7 +16716,7 @@ def test_backup_for_gke_base_transport_with_adc(): def test_backup_for_gke_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) BackupForGKEClient() adc.assert_called_once_with( scopes=None, @@ -16321,7 +16736,7 @@ def test_backup_for_gke_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -16368,7 +16783,7 @@ def test_backup_for_gke_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -16393,7 +16808,7 @@ def test_backup_for_gke_transport_create_channel(transport_class, grpc_helpers): [transports.BackupForGKEGrpcTransport, transports.BackupForGKEGrpcAsyncIOTransport], ) def test_backup_for_gke_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -16431,7 +16846,7 @@ def test_backup_for_gke_grpc_transport_client_cert_source_for_mtls(transport_cla def test_backup_for_gke_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -16443,7 +16858,7 @@ def test_backup_for_gke_http_transport_client_cert_source_for_mtls(): def test_backup_for_gke_rest_lro_client(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -16468,7 +16883,7 @@ def test_backup_for_gke_rest_lro_client(): ) def test_backup_for_gke_host_no_port(transport_name): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkebackup.googleapis.com" ), @@ -16491,7 +16906,7 @@ def test_backup_for_gke_host_no_port(transport_name): ) def test_backup_for_gke_host_with_port(transport_name): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkebackup.googleapis.com:8000" ), @@ -16511,8 +16926,8 @@ def test_backup_for_gke_host_with_port(transport_name): ], ) def test_backup_for_gke_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = BackupForGKEClient( credentials=creds1, transport=transport_name, @@ -16640,7 +17055,7 @@ def test_backup_for_gke_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -16715,7 +17130,7 @@ def test_backup_for_gke_transport_channel_mtls_with_adc(transport_class): def test_backup_for_gke_grpc_lro_client(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -16732,7 +17147,7 @@ def test_backup_for_gke_grpc_lro_client(): def test_backup_for_gke_grpc_lro_async_client(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -17094,7 +17509,7 @@ def test_client_with_default_client_info(): transports.BackupForGKETransport, "_prep_wrapped_messages" ) as prep: client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -17104,7 +17519,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = BackupForGKEClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -17113,7 +17528,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -17128,7 +17543,7 @@ def test_get_location_rest_bad_request( transport: str = "rest", request_type=locations_pb2.GetLocationRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17158,7 +17573,7 @@ def test_get_location_rest_bad_request( ) def test_get_location_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -17186,7 +17601,7 @@ def test_list_locations_rest_bad_request( transport: str = "rest", request_type=locations_pb2.ListLocationsRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17214,7 +17629,7 @@ def test_list_locations_rest_bad_request( ) def test_list_locations_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1"} @@ -17242,7 +17657,7 @@ def test_get_iam_policy_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.GetIamPolicyRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17272,7 +17687,7 @@ def test_get_iam_policy_rest_bad_request( ) def test_get_iam_policy_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -17302,7 +17717,7 @@ def test_set_iam_policy_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.SetIamPolicyRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17332,7 +17747,7 @@ def test_set_iam_policy_rest_bad_request( ) def test_set_iam_policy_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -17362,7 +17777,7 @@ def test_test_iam_permissions_rest_bad_request( transport: str = "rest", request_type=iam_policy_pb2.TestIamPermissionsRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17392,7 +17807,7 @@ def test_test_iam_permissions_rest_bad_request( ) def test_test_iam_permissions_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = { @@ -17422,7 +17837,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17452,7 +17867,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -17480,7 +17895,7 @@ def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17510,7 +17925,7 @@ def test_delete_operation_rest_bad_request( ) def test_delete_operation_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -17538,7 +17953,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17568,7 +17983,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -17596,7 +18011,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17626,7 +18041,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -17652,7 +18067,7 @@ def test_list_operations_rest(request_type): def test_delete_operation(transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17677,7 +18092,7 @@ def test_delete_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_delete_operation_async(transport: str = "grpc_asyncio"): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17701,7 +18116,7 @@ async def test_delete_operation_async(transport: str = "grpc_asyncio"): def test_delete_operation_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -17730,7 +18145,7 @@ def test_delete_operation_field_headers(): @pytest.mark.asyncio async def test_delete_operation_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -17757,7 +18172,7 @@ async def test_delete_operation_field_headers_async(): def test_delete_operation_from_dict(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -17775,7 +18190,7 @@ def test_delete_operation_from_dict(): @pytest.mark.asyncio async def test_delete_operation_from_dict_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -17791,7 +18206,7 @@ async def test_delete_operation_from_dict_async(): def test_cancel_operation(transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17816,7 +18231,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17840,7 +18255,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -17869,7 +18284,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -17896,7 +18311,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -17914,7 +18329,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -17930,7 +18345,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17955,7 +18370,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -17981,7 +18396,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18010,7 +18425,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18039,7 +18454,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -18057,7 +18472,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -18075,7 +18490,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18100,7 +18515,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18126,7 +18541,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18155,7 +18570,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18184,7 +18599,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -18202,7 +18617,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -18220,7 +18635,7 @@ async def test_list_operations_from_dict_async(): def test_list_locations(transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18245,7 +18660,7 @@ def test_list_locations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_locations_async(transport: str = "grpc_asyncio"): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18271,7 +18686,7 @@ async def test_list_locations_async(transport: str = "grpc_asyncio"): def test_list_locations_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18300,7 +18715,7 @@ def test_list_locations_field_headers(): @pytest.mark.asyncio async def test_list_locations_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18329,7 +18744,7 @@ async def test_list_locations_field_headers_async(): def test_list_locations_from_dict(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -18347,7 +18762,7 @@ def test_list_locations_from_dict(): @pytest.mark.asyncio async def test_list_locations_from_dict_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -18365,7 +18780,7 @@ async def test_list_locations_from_dict_async(): def test_get_location(transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18390,7 +18805,7 @@ def test_get_location(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_location_async(transport: str = "grpc_asyncio"): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18415,7 +18830,7 @@ async def test_get_location_async(transport: str = "grpc_asyncio"): def test_get_location_field_headers(): - client = BackupForGKEClient(credentials=ga_credentials.AnonymousCredentials()) + client = BackupForGKEClient(credentials=_AnonymousCredentialsWithUniverseDomain()) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -18442,7 +18857,9 @@ def test_get_location_field_headers(): @pytest.mark.asyncio async def test_get_location_field_headers_async(): - client = BackupForGKEAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + client = BackupForGKEAsyncClient( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. @@ -18470,7 +18887,7 @@ async def test_get_location_field_headers_async(): def test_get_location_from_dict(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -18488,7 +18905,7 @@ def test_get_location_from_dict(): @pytest.mark.asyncio async def test_get_location_from_dict_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_locations), "__call__") as call: @@ -18506,7 +18923,7 @@ async def test_get_location_from_dict_async(): def test_set_iam_policy(transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18539,7 +18956,7 @@ def test_set_iam_policy(transport: str = "grpc"): @pytest.mark.asyncio async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18574,7 +18991,7 @@ async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): def test_set_iam_policy_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18604,7 +19021,7 @@ def test_set_iam_policy_field_headers(): @pytest.mark.asyncio async def test_set_iam_policy_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18633,7 +19050,7 @@ async def test_set_iam_policy_field_headers_async(): def test_set_iam_policy_from_dict(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -18652,7 +19069,7 @@ def test_set_iam_policy_from_dict(): @pytest.mark.asyncio async def test_set_iam_policy_from_dict_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: @@ -18670,7 +19087,7 @@ async def test_set_iam_policy_from_dict_async(): def test_get_iam_policy(transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18705,7 +19122,7 @@ def test_get_iam_policy(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18741,7 +19158,7 @@ async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): def test_get_iam_policy_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18771,7 +19188,7 @@ def test_get_iam_policy_field_headers(): @pytest.mark.asyncio async def test_get_iam_policy_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18800,7 +19217,7 @@ async def test_get_iam_policy_field_headers_async(): def test_get_iam_policy_from_dict(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -18819,7 +19236,7 @@ def test_get_iam_policy_from_dict(): @pytest.mark.asyncio async def test_get_iam_policy_from_dict_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: @@ -18837,7 +19254,7 @@ async def test_get_iam_policy_from_dict_async(): def test_test_iam_permissions(transport: str = "grpc"): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18871,7 +19288,7 @@ def test_test_iam_permissions(transport: str = "grpc"): @pytest.mark.asyncio async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -18906,7 +19323,7 @@ async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): def test_test_iam_permissions_field_headers(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18938,7 +19355,7 @@ def test_test_iam_permissions_field_headers(): @pytest.mark.asyncio async def test_test_iam_permissions_field_headers_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -18971,7 +19388,7 @@ async def test_test_iam_permissions_field_headers_async(): def test_test_iam_permissions_from_dict(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -18992,7 +19409,7 @@ def test_test_iam_permissions_from_dict(): @pytest.mark.asyncio async def test_test_iam_permissions_from_dict_async(): client = BackupForGKEAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -19020,7 +19437,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -19037,7 +19454,7 @@ def test_client_ctx(): ] for transport in transports: client = BackupForGKEClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -19068,7 +19485,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, diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway/gapic_version.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway/gapic_version.py index 928de34fce5d..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway/gapic_version.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.8.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/gapic_version.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/gapic_version.py index 928de34fce5d..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/gapic_version.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.8.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/async_client.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/async_client.py index de45dbc96f35..8c9943e4197f 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/async_client.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/async_client.py @@ -38,9 +38,9 @@ from google.cloud.gkeconnect.gateway_v1beta1 import gapic_version as package_version 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.api import httpbody_pb2 # type: ignore from google.protobuf import any_pb2 # type: ignore @@ -61,8 +61,12 @@ class GatewayServiceAsyncClient: _client: GatewayServiceClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = GatewayServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = GatewayServiceClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = GatewayServiceClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = GatewayServiceClient._DEFAULT_UNIVERSE common_billing_account_path = staticmethod( GatewayServiceClient.common_billing_account_path @@ -167,6 +171,25 @@ def transport(self) -> GatewayServiceTransport: """ 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(GatewayServiceClient).get_transport_class, type(GatewayServiceClient) ) @@ -179,7 +202,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the gateway service client. + """Instantiates the gateway service async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -190,23 +213,38 @@ def __init__( transport (Union[str, ~.GatewayServiceTransport]): 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. @@ -376,6 +414,9 @@ async def sample_get_resource(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -545,6 +586,9 @@ async def sample_post_resource(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -714,6 +758,9 @@ async def sample_delete_resource(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -883,6 +930,9 @@ async def sample_put_resource(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1052,6 +1102,9 @@ async def sample_patch_resource(): client_info=DEFAULT_CLIENT_INFO, ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/client.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/client.py index 308a7f28ded7..903807c2ecc9 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/client.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.gkeconnect.gateway_v1beta1 import gapic_version as package_version 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.api import httpbody_pb2 # type: ignore from google.protobuf import any_pb2 # type: ignore @@ -129,11 +130,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 = "connectgateway.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "connectgateway.{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 @@ -262,7 +267,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 @@ -292,6 +297,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") @@ -325,6 +335,175 @@ 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 + + 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 + + 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 = GatewayServiceClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = GatewayServiceClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = GatewayServiceClient._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 = GatewayServiceClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = GatewayServiceClient._DEFAULT_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 GatewayServiceClient._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, *, @@ -344,22 +523,32 @@ def __init__( transport (Union[str, GatewayServiceTransport]): 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. @@ -370,17 +559,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = GatewayServiceClient._read_environment_variables() + self._client_cert_source = GatewayServiceClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = GatewayServiceClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -389,20 +595,33 @@ 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, GatewayServiceTransport): + transport_provided = isinstance(transport, GatewayServiceTransport) + if transport_provided: # transport is a GatewayServiceTransport 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(GatewayServiceTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or GatewayServiceClient._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( @@ -412,17 +631,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 get_resource( @@ -582,6 +801,9 @@ def sample_get_resource(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_resource] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -750,6 +972,9 @@ def sample_post_resource(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.post_resource] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -918,6 +1143,9 @@ def sample_delete_resource(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.delete_resource] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1086,6 +1314,9 @@ def sample_put_resource(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.put_resource] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1254,6 +1485,9 @@ def sample_patch_resource(): # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.patch_resource] + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/base.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/base.py index 7681045782af..d1e7b8736d86 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/base.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/base.py @@ -56,7 +56,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'connectgateway.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 @@ -119,6 +119,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-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/grpc.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/grpc.py index 451d3c6e138c..8c66cf0030a7 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/grpc.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/grpc.py @@ -67,7 +67,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'connectgateway.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-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/grpc_asyncio.py b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/grpc_asyncio.py index 6f130e159477..3efecfb49436 100644 --- a/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-connect-gateway/google/cloud/gkeconnect/gateway_v1beta1/services/gateway_service/transports/grpc_asyncio.py @@ -112,7 +112,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'connectgateway.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-gke-connect-gateway/noxfile.py b/packages/google-cloud-gke-connect-gateway/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-gke-connect-gateway/noxfile.py +++ b/packages/google-cloud-gke-connect-gateway/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-gke-connect-gateway/samples/generated_samples/snippet_metadata_google.cloud.gkeconnect.gateway.v1beta1.json b/packages/google-cloud-gke-connect-gateway/samples/generated_samples/snippet_metadata_google.cloud.gkeconnect.gateway.v1beta1.json index 08531fce80b8..6586a7512b44 100644 --- a/packages/google-cloud-gke-connect-gateway/samples/generated_samples/snippet_metadata_google.cloud.gkeconnect.gateway.v1beta1.json +++ b/packages/google-cloud-gke-connect-gateway/samples/generated_samples/snippet_metadata_google.cloud.gkeconnect.gateway.v1beta1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-gke-connect-gateway", - "version": "0.8.5" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1beta1/test_gateway_service.py b/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1beta1/test_gateway_service.py index 9aac756a5bb2..79639c047102 100644 --- a/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1beta1/test_gateway_service.py +++ b/packages/google-cloud-gke-connect-gateway/tests/unit/gapic/gateway_v1beta1/test_gateway_service.py @@ -26,7 +26,7 @@ from google.api import httpbody_pb2 # type: ignore from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -61,6 +61,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -90,6 +113,266 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert GatewayServiceClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert GatewayServiceClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert GatewayServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + GatewayServiceClient._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 GatewayServiceClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert GatewayServiceClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert GatewayServiceClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + GatewayServiceClient._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 GatewayServiceClient._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 GatewayServiceClient._get_client_cert_source(None, False) is None + assert ( + GatewayServiceClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + GatewayServiceClient._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 ( + GatewayServiceClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + GatewayServiceClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + GatewayServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GatewayServiceClient), +) +@mock.patch.object( + GatewayServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GatewayServiceAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = GatewayServiceClient._DEFAULT_UNIVERSE + default_endpoint = GatewayServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = GatewayServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + GatewayServiceClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + GatewayServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == GatewayServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + GatewayServiceClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + GatewayServiceClient._get_api_endpoint(None, None, default_universe, "always") + == GatewayServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + GatewayServiceClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == GatewayServiceClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + GatewayServiceClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + GatewayServiceClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + GatewayServiceClient._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 ( + GatewayServiceClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + GatewayServiceClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + GatewayServiceClient._get_universe_domain(None, None) + == GatewayServiceClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + GatewayServiceClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (GatewayServiceClient, transports.GatewayServiceGrpcTransport, "grpc"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -98,7 +381,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_gateway_service_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -144,7 +427,7 @@ def test_gateway_service_client_service_account_always_use_jwt( ], ) def test_gateway_service_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -188,20 +471,22 @@ def test_gateway_service_client_get_transport_class(): ) @mock.patch.object( GatewayServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(GatewayServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GatewayServiceClient), ) @mock.patch.object( GatewayServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(GatewayServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GatewayServiceAsyncClient), ) def test_gateway_service_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(GatewayServiceClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -236,7 +521,9 @@ def test_gateway_service_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, @@ -266,15 +553,23 @@ def test_gateway_service_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") @@ -284,7 +579,9 @@ def test_gateway_service_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", @@ -302,7 +599,9 @@ def test_gateway_service_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, @@ -333,13 +632,13 @@ def test_gateway_service_client_client_options( ) @mock.patch.object( GatewayServiceClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(GatewayServiceClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GatewayServiceClient), ) @mock.patch.object( GatewayServiceAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(GatewayServiceAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GatewayServiceAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_gateway_service_client_mtls_env_auto( @@ -362,7 +661,9 @@ def test_gateway_service_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 @@ -394,7 +695,9 @@ def test_gateway_service_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 @@ -428,7 +731,9 @@ def test_gateway_service_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, @@ -518,6 +823,118 @@ def test_gateway_service_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", [GatewayServiceClient, GatewayServiceAsyncClient] +) +@mock.patch.object( + GatewayServiceClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GatewayServiceClient), +) +@mock.patch.object( + GatewayServiceAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GatewayServiceAsyncClient), +) +def test_gateway_service_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = GatewayServiceClient._DEFAULT_UNIVERSE + default_endpoint = GatewayServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = GatewayServiceClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -543,7 +960,9 @@ def test_gateway_service_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, @@ -582,7 +1001,9 @@ def test_gateway_service_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, @@ -642,7 +1063,9 @@ def test_gateway_service_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, @@ -659,8 +1082,8 @@ def test_gateway_service_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -689,7 +1112,7 @@ def test_gateway_service_client_create_channel_credentials_file( ) def test_get_resource(request_type, transport: str = "grpc"): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -721,7 +1144,7 @@ def test_get_resource_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -738,7 +1161,7 @@ async def test_get_resource_async( transport: str = "grpc_asyncio", request_type=httpbody_pb2.HttpBody ): client = GatewayServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -775,7 +1198,7 @@ async def test_get_resource_async_from_dict(): def test_get_resource_from_dict_foreign(): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_resource), "__call__") as call: @@ -802,7 +1225,7 @@ def test_get_resource_from_dict_foreign(): ) def test_post_resource(request_type, transport: str = "grpc"): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -834,7 +1257,7 @@ def test_post_resource_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -851,7 +1274,7 @@ async def test_post_resource_async( transport: str = "grpc_asyncio", request_type=httpbody_pb2.HttpBody ): client = GatewayServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -888,7 +1311,7 @@ async def test_post_resource_async_from_dict(): def test_post_resource_from_dict_foreign(): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.post_resource), "__call__") as call: @@ -915,7 +1338,7 @@ def test_post_resource_from_dict_foreign(): ) def test_delete_resource(request_type, transport: str = "grpc"): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -947,7 +1370,7 @@ def test_delete_resource_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -964,7 +1387,7 @@ async def test_delete_resource_async( transport: str = "grpc_asyncio", request_type=httpbody_pb2.HttpBody ): client = GatewayServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1001,7 +1424,7 @@ async def test_delete_resource_async_from_dict(): def test_delete_resource_from_dict_foreign(): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_resource), "__call__") as call: @@ -1028,7 +1451,7 @@ def test_delete_resource_from_dict_foreign(): ) def test_put_resource(request_type, transport: str = "grpc"): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1060,7 +1483,7 @@ def test_put_resource_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1077,7 +1500,7 @@ async def test_put_resource_async( transport: str = "grpc_asyncio", request_type=httpbody_pb2.HttpBody ): client = GatewayServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1114,7 +1537,7 @@ async def test_put_resource_async_from_dict(): def test_put_resource_from_dict_foreign(): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.put_resource), "__call__") as call: @@ -1141,7 +1564,7 @@ def test_put_resource_from_dict_foreign(): ) def test_patch_resource(request_type, transport: str = "grpc"): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1173,7 +1596,7 @@ def test_patch_resource_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1190,7 +1613,7 @@ async def test_patch_resource_async( transport: str = "grpc_asyncio", request_type=httpbody_pb2.HttpBody ): client = GatewayServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1227,7 +1650,7 @@ async def test_patch_resource_async_from_dict(): def test_patch_resource_from_dict_foreign(): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.patch_resource), "__call__") as call: @@ -1248,17 +1671,17 @@ def test_patch_resource_from_dict_foreign(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.GatewayServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.GatewayServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = GatewayServiceClient( @@ -1268,7 +1691,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.GatewayServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1279,16 +1702,17 @@ 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 = GatewayServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.GatewayServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = GatewayServiceClient( @@ -1300,7 +1724,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.GatewayServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = GatewayServiceClient(transport=transport) assert client.transport is transport @@ -1309,13 +1733,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.GatewayServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.GatewayServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -1331,7 +1755,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -1344,7 +1768,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = GatewayServiceClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -1352,7 +1776,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -1364,7 +1788,7 @@ def test_gateway_service_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.GatewayServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -1376,7 +1800,7 @@ def test_gateway_service_base_transport(): ) as Transport: Transport.return_value = None transport = transports.GatewayServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -1412,7 +1836,7 @@ def test_gateway_service_base_transport_with_credentials_file(): "google.cloud.gkeconnect.gateway_v1beta1.services.gateway_service.transports.GatewayServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.GatewayServiceTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1431,7 +1855,7 @@ def test_gateway_service_base_transport_with_adc(): "google.cloud.gkeconnect.gateway_v1beta1.services.gateway_service.transports.GatewayServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.GatewayServiceTransport() adc.assert_called_once() @@ -1439,7 +1863,7 @@ def test_gateway_service_base_transport_with_adc(): def test_gateway_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) GatewayServiceClient() adc.assert_called_once_with( scopes=None, @@ -1459,7 +1883,7 @@ def test_gateway_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -1505,7 +1929,7 @@ def test_gateway_service_transport_create_channel(transport_class, grpc_helpers) ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -1533,7 +1957,7 @@ def test_gateway_service_transport_create_channel(transport_class, grpc_helpers) ], ) def test_gateway_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1579,7 +2003,7 @@ def test_gateway_service_grpc_transport_client_cert_source_for_mtls(transport_cl ) def test_gateway_service_host_no_port(transport_name): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="connectgateway.googleapis.com" ), @@ -1597,7 +2021,7 @@ def test_gateway_service_host_no_port(transport_name): ) def test_gateway_service_host_with_port(transport_name): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="connectgateway.googleapis.com:8000" ), @@ -1656,7 +2080,7 @@ def test_gateway_service_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -1842,7 +2266,7 @@ def test_client_with_default_client_info(): transports.GatewayServiceTransport, "_prep_wrapped_messages" ) as prep: client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1852,7 +2276,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = GatewayServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1861,7 +2285,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = GatewayServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -1879,7 +2303,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -1895,7 +2319,7 @@ def test_client_ctx(): ] for transport in transports: client = GatewayServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -1926,7 +2350,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, diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub/gapic_version.py b/packages/google-cloud-gke-hub/google/cloud/gkehub/gapic_version.py index 4316e0e5df1f..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub/gapic_version.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.11.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/configmanagement_v1/gapic_version.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/configmanagement_v1/gapic_version.py index 4316e0e5df1f..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/configmanagement_v1/gapic_version.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/configmanagement_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.11.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/gapic_version.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/gapic_version.py index 4316e0e5df1f..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/gapic_version.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.11.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/multiclusteringress_v1/gapic_version.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/multiclusteringress_v1/gapic_version.py index 4316e0e5df1f..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/multiclusteringress_v1/gapic_version.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/multiclusteringress_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.11.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/async_client.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/async_client.py index f448d2e3de69..ad7474b932a7 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/async_client.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/async_client.py @@ -38,9 +38,9 @@ from google.cloud.gkehub_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -78,8 +78,12 @@ class GkeHubAsyncClient: _client: GkeHubClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = GkeHubClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = GkeHubClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = GkeHubClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = GkeHubClient._DEFAULT_UNIVERSE feature_path = staticmethod(GkeHubClient.feature_path) parse_feature_path = staticmethod(GkeHubClient.parse_feature_path) @@ -178,6 +182,25 @@ def transport(self) -> GkeHubTransport: """ 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(GkeHubClient).get_transport_class, type(GkeHubClient) ) @@ -190,7 +213,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the gke hub client. + """Instantiates the gke hub async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -201,23 +224,38 @@ def __init__( transport (Union[str, ~.GkeHubTransport]): 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. @@ -324,6 +362,9 @@ async def sample_list_memberships(): 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, @@ -437,6 +478,9 @@ async def sample_list_features(): 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, @@ -547,6 +591,9 @@ async def sample_get_membership(): 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, @@ -647,6 +694,9 @@ async def sample_get_feature(): 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, @@ -790,6 +840,9 @@ async def sample_create_membership(): 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, @@ -922,6 +975,9 @@ async def sample_create_feature(): 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, @@ -1050,6 +1106,9 @@ async def sample_delete_membership(): 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, @@ -1172,6 +1231,9 @@ async def sample_delete_feature(): 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, @@ -1313,6 +1375,9 @@ async def sample_update_membership(): 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, @@ -1453,6 +1518,9 @@ async def sample_update_feature(): 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, @@ -1545,6 +1613,9 @@ async def sample_generate_connect_manifest(): 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, diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/client.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/client.py index 02aed5d064f2..a04a7d52d6ba 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/client.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.gkehub_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -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 = "gkehub.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "gkehub.{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 @@ -325,7 +330,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 @@ -355,6 +360,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") @@ -388,6 +398,175 @@ 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 + + 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 + + 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 = GkeHubClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = GkeHubClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = GkeHubClient._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 = GkeHubClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = GkeHubClient._DEFAULT_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 GkeHubClient._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, *, @@ -407,22 +586,32 @@ def __init__( transport (Union[str, GkeHubTransport]): 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. @@ -433,17 +622,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, + ) = GkeHubClient._read_environment_variables() + self._client_cert_source = GkeHubClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = GkeHubClient._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" @@ -452,20 +658,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, GkeHubTransport): + transport_provided = isinstance(transport, GkeHubTransport) + if transport_provided: # transport is a GkeHubTransport 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(GkeHubTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or GkeHubClient._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( @@ -475,17 +691,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_memberships( @@ -583,6 +799,9 @@ def sample_list_memberships(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -696,6 +915,9 @@ def sample_list_features(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -806,6 +1028,9 @@ def sample_get_membership(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -906,6 +1131,9 @@ def sample_get_feature(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1049,6 +1277,9 @@ def sample_create_membership(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1181,6 +1412,9 @@ def sample_create_feature(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1309,6 +1543,9 @@ def sample_delete_membership(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1431,6 +1668,9 @@ def sample_delete_feature(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1572,6 +1812,9 @@ def sample_update_membership(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1712,6 +1955,9 @@ def sample_update_feature(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1807,6 +2053,9 @@ def sample_generate_connect_manifest(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/base.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/base.py index 56ed1e2dc5e6..cb232261cb16 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/base.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/base.py @@ -57,7 +57,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkehub.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 @@ -120,6 +120,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-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc.py index c27aa334e537..f9296e46f078 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc.py @@ -80,7 +80,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkehub.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-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc_asyncio.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc_asyncio.py index ffdfb2562ff4..30ececf13c05 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/grpc_asyncio.py @@ -125,7 +125,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkehub.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-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/rest.py b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/rest.py index bfec8e627b63..db552ad52234 100644 --- a/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/rest.py +++ b/packages/google-cloud-gke-hub/google/cloud/gkehub_v1/services/gke_hub/transports/rest.py @@ -37,9 +37,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -460,7 +460,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkehub.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-gke-hub/noxfile.py b/packages/google-cloud-gke-hub/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-gke-hub/noxfile.py +++ b/packages/google-cloud-gke-hub/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-gke-hub/samples/generated_samples/snippet_metadata_google.cloud.gkehub.v1.json b/packages/google-cloud-gke-hub/samples/generated_samples/snippet_metadata_google.cloud.gkehub.v1.json index 4b944703f4ec..f5d7aaa2ae7a 100644 --- a/packages/google-cloud-gke-hub/samples/generated_samples/snippet_metadata_google.cloud.gkehub.v1.json +++ b/packages/google-cloud-gke-hub/samples/generated_samples/snippet_metadata_google.cloud.gkehub.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-gke-hub", - "version": "1.11.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1/test_gke_hub.py b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1/test_gke_hub.py index 3c65cffa4400..39d2a3bac54f 100644 --- a/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1/test_gke_hub.py +++ b/packages/google-cloud-gke-hub/tests/unit/gapic/gkehub_v1/test_gke_hub.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -79,6 +79,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -102,6 +125,237 @@ def test__get_default_mtls_endpoint(): assert GkeHubClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert GkeHubClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert GkeHubClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert GkeHubClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + GkeHubClient._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 GkeHubClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert GkeHubClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert GkeHubClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + GkeHubClient._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 GkeHubClient._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 GkeHubClient._get_client_cert_source(None, False) is None + assert ( + GkeHubClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + GkeHubClient._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 ( + GkeHubClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + GkeHubClient._get_client_cert_source(mock_provided_cert_source, "true") + is mock_provided_cert_source + ) + + +@mock.patch.object( + GkeHubClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GkeHubClient), +) +@mock.patch.object( + GkeHubAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GkeHubAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = GkeHubClient._DEFAULT_UNIVERSE + default_endpoint = GkeHubClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = GkeHubClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + GkeHubClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + GkeHubClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == GkeHubClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + GkeHubClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + GkeHubClient._get_api_endpoint(None, None, default_universe, "always") + == GkeHubClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + GkeHubClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == GkeHubClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + GkeHubClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + GkeHubClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + GkeHubClient._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 ( + GkeHubClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + GkeHubClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + GkeHubClient._get_universe_domain(None, None) == GkeHubClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + GkeHubClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (GkeHubClient, transports.GkeHubGrpcTransport, "grpc"), + (GkeHubClient, transports.GkeHubRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -111,7 +365,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_gke_hub_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -161,7 +415,7 @@ def test_gke_hub_client_service_account_always_use_jwt(transport_class, transpor ], ) def test_gke_hub_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -206,15 +460,21 @@ def test_gke_hub_client_get_transport_class(): ], ) @mock.patch.object( - GkeHubClient, "DEFAULT_ENDPOINT", modify_default_endpoint(GkeHubClient) + GkeHubClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GkeHubClient), ) @mock.patch.object( - GkeHubAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(GkeHubAsyncClient) + GkeHubAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GkeHubAsyncClient), ) def test_gke_hub_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(GkeHubClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -249,7 +509,9 @@ def test_gke_hub_client_client_options(client_class, transport_class, transport_ 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, @@ -279,15 +541,23 @@ def test_gke_hub_client_client_options(client_class, transport_class, transport_ # 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") @@ -297,7 +567,9 @@ def test_gke_hub_client_client_options(client_class, transport_class, transport_ 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", @@ -315,7 +587,9 @@ def test_gke_hub_client_client_options(client_class, transport_class, transport_ 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, @@ -347,10 +621,14 @@ def test_gke_hub_client_client_options(client_class, transport_class, transport_ ], ) @mock.patch.object( - GkeHubClient, "DEFAULT_ENDPOINT", modify_default_endpoint(GkeHubClient) + GkeHubClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GkeHubClient), ) @mock.patch.object( - GkeHubAsyncClient, "DEFAULT_ENDPOINT", modify_default_endpoint(GkeHubAsyncClient) + GkeHubAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GkeHubAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_gke_hub_client_mtls_env_auto( @@ -373,7 +651,9 @@ def test_gke_hub_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 @@ -405,7 +685,9 @@ def test_gke_hub_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 @@ -439,7 +721,9 @@ def test_gke_hub_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, @@ -523,6 +807,116 @@ def test_gke_hub_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", [GkeHubClient, GkeHubAsyncClient]) +@mock.patch.object( + GkeHubClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GkeHubClient), +) +@mock.patch.object( + GkeHubAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GkeHubAsyncClient), +) +def test_gke_hub_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = GkeHubClient._DEFAULT_UNIVERSE + default_endpoint = GkeHubClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = GkeHubClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -545,7 +939,9 @@ def test_gke_hub_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, @@ -580,7 +976,9 @@ def test_gke_hub_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, @@ -633,7 +1031,9 @@ def test_gke_hub_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, @@ -650,8 +1050,8 @@ def test_gke_hub_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -680,7 +1080,7 @@ def test_gke_hub_client_create_channel_credentials_file( ) def test_list_memberships(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -712,7 +1112,7 @@ def test_list_memberships_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -729,7 +1129,7 @@ async def test_list_memberships_async( transport: str = "grpc_asyncio", request_type=service.ListMembershipsRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -766,7 +1166,7 @@ async def test_list_memberships_async_from_dict(): def test_list_memberships_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -796,7 +1196,7 @@ def test_list_memberships_field_headers(): @pytest.mark.asyncio async def test_list_memberships_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -827,7 +1227,7 @@ async def test_list_memberships_field_headers_async(): def test_list_memberships_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -851,7 +1251,7 @@ def test_list_memberships_flattened(): def test_list_memberships_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -866,7 +1266,7 @@ def test_list_memberships_flattened_error(): @pytest.mark.asyncio async def test_list_memberships_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -895,7 +1295,7 @@ async def test_list_memberships_flattened_async(): @pytest.mark.asyncio async def test_list_memberships_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -909,7 +1309,7 @@ async def test_list_memberships_flattened_error_async(): def test_list_memberships_pager(transport_name: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -959,7 +1359,7 @@ def test_list_memberships_pager(transport_name: str = "grpc"): def test_list_memberships_pages(transport_name: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1001,7 +1401,7 @@ def test_list_memberships_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_memberships_async_pager(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1051,7 +1451,7 @@ async def test_list_memberships_async_pager(): @pytest.mark.asyncio async def test_list_memberships_async_pages(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1106,7 +1506,7 @@ async def test_list_memberships_async_pages(): ) def test_list_features(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1136,7 +1536,7 @@ def test_list_features_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1153,7 +1553,7 @@ async def test_list_features_async( transport: str = "grpc_asyncio", request_type=service.ListFeaturesRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1188,7 +1588,7 @@ async def test_list_features_async_from_dict(): def test_list_features_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1218,7 +1618,7 @@ def test_list_features_field_headers(): @pytest.mark.asyncio async def test_list_features_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1249,7 +1649,7 @@ async def test_list_features_field_headers_async(): def test_list_features_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1273,7 +1673,7 @@ def test_list_features_flattened(): def test_list_features_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1288,7 +1688,7 @@ def test_list_features_flattened_error(): @pytest.mark.asyncio async def test_list_features_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1317,7 +1717,7 @@ async def test_list_features_flattened_async(): @pytest.mark.asyncio async def test_list_features_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1331,7 +1731,7 @@ async def test_list_features_flattened_error_async(): def test_list_features_pager(transport_name: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1381,7 +1781,7 @@ def test_list_features_pager(transport_name: str = "grpc"): def test_list_features_pages(transport_name: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1423,7 +1823,7 @@ def test_list_features_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_features_async_pager(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1473,7 +1873,7 @@ async def test_list_features_async_pager(): @pytest.mark.asyncio async def test_list_features_async_pages(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1528,7 +1928,7 @@ async def test_list_features_async_pages(): ) def test_get_membership(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1564,7 +1964,7 @@ def test_get_membership_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1581,7 +1981,7 @@ async def test_get_membership_async( transport: str = "grpc_asyncio", request_type=service.GetMembershipRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1622,7 +2022,7 @@ async def test_get_membership_async_from_dict(): def test_get_membership_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1652,7 +2052,7 @@ def test_get_membership_field_headers(): @pytest.mark.asyncio async def test_get_membership_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1683,7 +2083,7 @@ async def test_get_membership_field_headers_async(): def test_get_membership_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1707,7 +2107,7 @@ def test_get_membership_flattened(): def test_get_membership_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1722,7 +2122,7 @@ def test_get_membership_flattened_error(): @pytest.mark.asyncio async def test_get_membership_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1751,7 +2151,7 @@ async def test_get_membership_flattened_async(): @pytest.mark.asyncio async def test_get_membership_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1772,7 +2172,7 @@ async def test_get_membership_flattened_error_async(): ) def test_get_feature(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1802,7 +2202,7 @@ def test_get_feature_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1819,7 +2219,7 @@ async def test_get_feature_async( transport: str = "grpc_asyncio", request_type=service.GetFeatureRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1854,7 +2254,7 @@ async def test_get_feature_async_from_dict(): def test_get_feature_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1884,7 +2284,7 @@ def test_get_feature_field_headers(): @pytest.mark.asyncio async def test_get_feature_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1913,7 +2313,7 @@ async def test_get_feature_field_headers_async(): def test_get_feature_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1937,7 +2337,7 @@ def test_get_feature_flattened(): def test_get_feature_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1952,7 +2352,7 @@ def test_get_feature_flattened_error(): @pytest.mark.asyncio async def test_get_feature_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1979,7 +2379,7 @@ async def test_get_feature_flattened_async(): @pytest.mark.asyncio async def test_get_feature_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2000,7 +2400,7 @@ async def test_get_feature_flattened_error_async(): ) def test_create_membership(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2029,7 +2429,7 @@ def test_create_membership_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2048,7 +2448,7 @@ async def test_create_membership_async( transport: str = "grpc_asyncio", request_type=service.CreateMembershipRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2082,7 +2482,7 @@ async def test_create_membership_async_from_dict(): def test_create_membership_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2114,7 +2514,7 @@ def test_create_membership_field_headers(): @pytest.mark.asyncio async def test_create_membership_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2147,7 +2547,7 @@ async def test_create_membership_field_headers_async(): def test_create_membership_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2191,7 +2591,7 @@ def test_create_membership_flattened(): def test_create_membership_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2214,7 +2614,7 @@ def test_create_membership_flattened_error(): @pytest.mark.asyncio async def test_create_membership_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2263,7 +2663,7 @@ async def test_create_membership_flattened_async(): @pytest.mark.asyncio async def test_create_membership_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2292,7 +2692,7 @@ async def test_create_membership_flattened_error_async(): ) def test_create_feature(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2319,7 +2719,7 @@ def test_create_feature_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2336,7 +2736,7 @@ async def test_create_feature_async( transport: str = "grpc_asyncio", request_type=service.CreateFeatureRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2368,7 +2768,7 @@ async def test_create_feature_async_from_dict(): def test_create_feature_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2398,7 +2798,7 @@ def test_create_feature_field_headers(): @pytest.mark.asyncio async def test_create_feature_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2429,7 +2829,7 @@ async def test_create_feature_field_headers_async(): def test_create_feature_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2461,7 +2861,7 @@ def test_create_feature_flattened(): def test_create_feature_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2478,7 +2878,7 @@ def test_create_feature_flattened_error(): @pytest.mark.asyncio async def test_create_feature_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2515,7 +2915,7 @@ async def test_create_feature_flattened_async(): @pytest.mark.asyncio async def test_create_feature_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2538,7 +2938,7 @@ async def test_create_feature_flattened_error_async(): ) def test_delete_membership(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2567,7 +2967,7 @@ def test_delete_membership_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2586,7 +2986,7 @@ async def test_delete_membership_async( transport: str = "grpc_asyncio", request_type=service.DeleteMembershipRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2620,7 +3020,7 @@ async def test_delete_membership_async_from_dict(): def test_delete_membership_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2652,7 +3052,7 @@ def test_delete_membership_field_headers(): @pytest.mark.asyncio async def test_delete_membership_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2685,7 +3085,7 @@ async def test_delete_membership_field_headers_async(): def test_delete_membership_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2711,7 +3111,7 @@ def test_delete_membership_flattened(): def test_delete_membership_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2726,7 +3126,7 @@ def test_delete_membership_flattened_error(): @pytest.mark.asyncio async def test_delete_membership_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2757,7 +3157,7 @@ async def test_delete_membership_flattened_async(): @pytest.mark.asyncio async def test_delete_membership_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2778,7 +3178,7 @@ async def test_delete_membership_flattened_error_async(): ) def test_delete_feature(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2805,7 +3205,7 @@ def test_delete_feature_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2822,7 +3222,7 @@ async def test_delete_feature_async( transport: str = "grpc_asyncio", request_type=service.DeleteFeatureRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2854,7 +3254,7 @@ async def test_delete_feature_async_from_dict(): def test_delete_feature_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2884,7 +3284,7 @@ def test_delete_feature_field_headers(): @pytest.mark.asyncio async def test_delete_feature_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2915,7 +3315,7 @@ async def test_delete_feature_field_headers_async(): def test_delete_feature_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2939,7 +3339,7 @@ def test_delete_feature_flattened(): def test_delete_feature_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2954,7 +3354,7 @@ def test_delete_feature_flattened_error(): @pytest.mark.asyncio async def test_delete_feature_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2983,7 +3383,7 @@ async def test_delete_feature_flattened_async(): @pytest.mark.asyncio async def test_delete_feature_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3004,7 +3404,7 @@ async def test_delete_feature_flattened_error_async(): ) def test_update_membership(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3033,7 +3433,7 @@ def test_update_membership_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3052,7 +3452,7 @@ async def test_update_membership_async( transport: str = "grpc_asyncio", request_type=service.UpdateMembershipRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3086,7 +3486,7 @@ async def test_update_membership_async_from_dict(): def test_update_membership_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3118,7 +3518,7 @@ def test_update_membership_field_headers(): @pytest.mark.asyncio async def test_update_membership_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3151,7 +3551,7 @@ async def test_update_membership_field_headers_async(): def test_update_membership_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3195,7 +3595,7 @@ def test_update_membership_flattened(): def test_update_membership_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3218,7 +3618,7 @@ def test_update_membership_flattened_error(): @pytest.mark.asyncio async def test_update_membership_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3267,7 +3667,7 @@ async def test_update_membership_flattened_async(): @pytest.mark.asyncio async def test_update_membership_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3296,7 +3696,7 @@ async def test_update_membership_flattened_error_async(): ) def test_update_feature(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3323,7 +3723,7 @@ def test_update_feature_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3340,7 +3740,7 @@ async def test_update_feature_async( transport: str = "grpc_asyncio", request_type=service.UpdateFeatureRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3372,7 +3772,7 @@ async def test_update_feature_async_from_dict(): def test_update_feature_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3402,7 +3802,7 @@ def test_update_feature_field_headers(): @pytest.mark.asyncio async def test_update_feature_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3433,7 +3833,7 @@ async def test_update_feature_field_headers_async(): def test_update_feature_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3465,7 +3865,7 @@ def test_update_feature_flattened(): def test_update_feature_flattened_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3482,7 +3882,7 @@ def test_update_feature_flattened_error(): @pytest.mark.asyncio async def test_update_feature_flattened_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3519,7 +3919,7 @@ async def test_update_feature_flattened_async(): @pytest.mark.asyncio async def test_update_feature_flattened_error_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3542,7 +3942,7 @@ async def test_update_feature_flattened_error_async(): ) def test_generate_connect_manifest(request_type, transport: str = "grpc"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3571,7 +3971,7 @@ def test_generate_connect_manifest_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3590,7 +3990,7 @@ async def test_generate_connect_manifest_async( transport: str = "grpc_asyncio", request_type=service.GenerateConnectManifestRequest ): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3624,7 +4024,7 @@ async def test_generate_connect_manifest_async_from_dict(): def test_generate_connect_manifest_field_headers(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3656,7 +4056,7 @@ def test_generate_connect_manifest_field_headers(): @pytest.mark.asyncio async def test_generate_connect_manifest_field_headers_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3696,7 +4096,7 @@ async def test_generate_connect_manifest_field_headers_async(): ) def test_list_memberships_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3749,7 +4149,7 @@ def test_list_memberships_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_memberships._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3758,7 +4158,7 @@ def test_list_memberships_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_memberships._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3776,7 +4176,7 @@ def test_list_memberships_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3818,7 +4218,7 @@ def test_list_memberships_rest_required_fields( def test_list_memberships_rest_unset_required_fields(): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_memberships._get_unset_required_fields({}) @@ -3838,7 +4238,7 @@ def test_list_memberships_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_memberships_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -3892,7 +4292,7 @@ def test_list_memberships_rest_bad_request( transport: str = "rest", request_type=service.ListMembershipsRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3914,7 +4314,7 @@ def test_list_memberships_rest_bad_request( def test_list_memberships_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3956,7 +4356,7 @@ def test_list_memberships_rest_flattened(): def test_list_memberships_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3971,7 +4371,7 @@ def test_list_memberships_rest_flattened_error(transport: str = "rest"): def test_list_memberships_rest_pager(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4039,7 +4439,7 @@ def test_list_memberships_rest_pager(transport: str = "rest"): ) def test_list_features_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4073,7 +4473,7 @@ def test_list_features_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_features_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -4127,7 +4527,7 @@ def test_list_features_rest_bad_request( transport: str = "rest", request_type=service.ListFeaturesRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4149,7 +4549,7 @@ def test_list_features_rest_bad_request( def test_list_features_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4190,7 +4590,7 @@ def test_list_features_rest_flattened(): def test_list_features_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4205,7 +4605,7 @@ def test_list_features_rest_flattened_error(transport: str = "rest"): def test_list_features_rest_pager(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4273,7 +4673,7 @@ def test_list_features_rest_pager(transport: str = "rest"): ) def test_get_membership_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4328,7 +4728,7 @@ def test_get_membership_rest_required_fields(request_type=service.GetMembershipR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_membership._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4337,7 +4737,7 @@ def test_get_membership_rest_required_fields(request_type=service.GetMembershipR jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_membership._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4346,7 +4746,7 @@ def test_get_membership_rest_required_fields(request_type=service.GetMembershipR assert jsonified_request["name"] == "name_value" client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4388,7 +4788,7 @@ def test_get_membership_rest_required_fields(request_type=service.GetMembershipR def test_get_membership_rest_unset_required_fields(): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_membership._get_unset_required_fields({}) @@ -4398,7 +4798,7 @@ def test_get_membership_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_membership_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -4452,7 +4852,7 @@ def test_get_membership_rest_bad_request( transport: str = "rest", request_type=service.GetMembershipRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4474,7 +4874,7 @@ def test_get_membership_rest_bad_request( def test_get_membership_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4518,7 +4918,7 @@ def test_get_membership_rest_flattened(): def test_get_membership_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4533,7 +4933,7 @@ def test_get_membership_rest_flattened_error(transport: str = "rest"): def test_get_membership_rest_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4546,7 +4946,7 @@ def test_get_membership_rest_error(): ) def test_get_feature_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4580,7 +4980,7 @@ def test_get_feature_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_feature_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -4632,7 +5032,7 @@ def test_get_feature_rest_bad_request( transport: str = "rest", request_type=service.GetFeatureRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4654,7 +5054,7 @@ def test_get_feature_rest_bad_request( def test_get_feature_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4695,7 +5095,7 @@ def test_get_feature_rest_flattened(): def test_get_feature_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4710,7 +5110,7 @@ def test_get_feature_rest_flattened_error(transport: str = "rest"): def test_get_feature_rest_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4723,7 +5123,7 @@ def test_get_feature_rest_error(): ) def test_create_membership_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4890,7 +5290,7 @@ def test_create_membership_rest_required_fields( assert "membershipId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_membership._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4902,7 +5302,7 @@ def test_create_membership_rest_required_fields( jsonified_request["membershipId"] = "membership_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_membership._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4920,7 +5320,7 @@ def test_create_membership_rest_required_fields( assert jsonified_request["membershipId"] == "membership_id_value" client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4966,7 +5366,7 @@ def test_create_membership_rest_required_fields( def test_create_membership_rest_unset_required_fields(): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_membership._get_unset_required_fields({}) @@ -4990,7 +5390,7 @@ def test_create_membership_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_membership_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -5048,7 +5448,7 @@ def test_create_membership_rest_bad_request( transport: str = "rest", request_type=service.CreateMembershipRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5070,7 +5470,7 @@ def test_create_membership_rest_bad_request( def test_create_membership_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5118,7 +5518,7 @@ def test_create_membership_rest_flattened(): def test_create_membership_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5141,7 +5541,7 @@ def test_create_membership_rest_flattened_error(transport: str = "rest"): def test_create_membership_rest_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5154,7 +5554,7 @@ def test_create_membership_rest_error(): ) def test_create_feature_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5270,7 +5670,7 @@ def get_message_fields(field): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_feature_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -5326,7 +5726,7 @@ def test_create_feature_rest_bad_request( transport: str = "rest", request_type=service.CreateFeatureRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5348,7 +5748,7 @@ def test_create_feature_rest_bad_request( def test_create_feature_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5389,7 +5789,7 @@ def test_create_feature_rest_flattened(): def test_create_feature_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5406,7 +5806,7 @@ def test_create_feature_rest_flattened_error(transport: str = "rest"): def test_create_feature_rest_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5419,7 +5819,7 @@ def test_create_feature_rest_error(): ) def test_delete_membership_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5465,7 +5865,7 @@ def test_delete_membership_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_membership._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5474,7 +5874,7 @@ def test_delete_membership_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_membership._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5490,7 +5890,7 @@ def test_delete_membership_rest_required_fields( assert jsonified_request["name"] == "name_value" client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5529,7 +5929,7 @@ def test_delete_membership_rest_required_fields( def test_delete_membership_rest_unset_required_fields(): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_membership._get_unset_required_fields({}) @@ -5547,7 +5947,7 @@ def test_delete_membership_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_membership_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -5605,7 +6005,7 @@ def test_delete_membership_rest_bad_request( transport: str = "rest", request_type=service.DeleteMembershipRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5627,7 +6027,7 @@ def test_delete_membership_rest_bad_request( def test_delete_membership_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5669,7 +6069,7 @@ def test_delete_membership_rest_flattened(): def test_delete_membership_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5684,7 +6084,7 @@ def test_delete_membership_rest_flattened_error(transport: str = "rest"): def test_delete_membership_rest_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5697,7 +6097,7 @@ def test_delete_membership_rest_error(): ) def test_delete_feature_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5726,7 +6126,7 @@ def test_delete_feature_rest(request_type): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_feature_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -5782,7 +6182,7 @@ def test_delete_feature_rest_bad_request( transport: str = "rest", request_type=service.DeleteFeatureRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5804,7 +6204,7 @@ def test_delete_feature_rest_bad_request( def test_delete_feature_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5843,7 +6243,7 @@ def test_delete_feature_rest_flattened(): def test_delete_feature_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5858,7 +6258,7 @@ def test_delete_feature_rest_flattened_error(transport: str = "rest"): def test_delete_feature_rest_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5871,7 +6271,7 @@ def test_delete_feature_rest_error(): ) def test_update_membership_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6036,7 +6436,7 @@ def test_update_membership_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_membership._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6045,7 +6445,7 @@ def test_update_membership_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_membership._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6061,7 +6461,7 @@ def test_update_membership_rest_required_fields( assert jsonified_request["name"] == "name_value" client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6101,7 +6501,7 @@ def test_update_membership_rest_required_fields( def test_update_membership_rest_unset_required_fields(): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_membership._get_unset_required_fields({}) @@ -6125,7 +6525,7 @@ def test_update_membership_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_membership_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -6183,7 +6583,7 @@ def test_update_membership_rest_bad_request( transport: str = "rest", request_type=service.UpdateMembershipRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6205,7 +6605,7 @@ def test_update_membership_rest_bad_request( def test_update_membership_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6255,7 +6655,7 @@ def test_update_membership_rest_flattened(): def test_update_membership_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6278,7 +6678,7 @@ def test_update_membership_rest_flattened_error(transport: str = "rest"): def test_update_membership_rest_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6291,7 +6691,7 @@ def test_update_membership_rest_error(): ) def test_update_feature_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6407,7 +6807,7 @@ def get_message_fields(field): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_feature_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -6463,7 +6863,7 @@ def test_update_feature_rest_bad_request( transport: str = "rest", request_type=service.UpdateFeatureRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6485,7 +6885,7 @@ def test_update_feature_rest_bad_request( def test_update_feature_rest_flattened(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6526,7 +6926,7 @@ def test_update_feature_rest_flattened(): def test_update_feature_rest_flattened_error(transport: str = "rest"): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6543,7 +6943,7 @@ def test_update_feature_rest_flattened_error(transport: str = "rest"): def test_update_feature_rest_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6556,7 +6956,7 @@ def test_update_feature_rest_error(): ) def test_generate_connect_manifest_rest(request_type): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6604,7 +7004,7 @@ def test_generate_connect_manifest_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_connect_manifest._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6613,7 +7013,7 @@ def test_generate_connect_manifest_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_connect_manifest._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6633,7 +7033,7 @@ def test_generate_connect_manifest_rest_required_fields( assert jsonified_request["name"] == "name_value" client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6675,7 +7075,7 @@ def test_generate_connect_manifest_rest_required_fields( def test_generate_connect_manifest_rest_unset_required_fields(): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_connect_manifest._get_unset_required_fields({}) @@ -6697,7 +7097,7 @@ def test_generate_connect_manifest_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_connect_manifest_rest_interceptors(null_interceptor): transport = transports.GkeHubRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GkeHubRestInterceptor(), ) client = GkeHubClient(transport=transport) @@ -6753,7 +7153,7 @@ def test_generate_connect_manifest_rest_bad_request( transport: str = "rest", request_type=service.GenerateConnectManifestRequest ): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6775,24 +7175,24 @@ def test_generate_connect_manifest_rest_bad_request( def test_generate_connect_manifest_rest_error(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.GkeHubGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.GkeHubGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = GkeHubClient( @@ -6802,7 +7202,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.GkeHubGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -6813,16 +7213,17 @@ 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 = GkeHubClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.GkeHubGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = GkeHubClient( @@ -6834,7 +7235,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.GkeHubGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = GkeHubClient(transport=transport) assert client.transport is transport @@ -6843,13 +7244,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.GkeHubGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.GkeHubGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -6866,7 +7267,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -6880,7 +7281,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = GkeHubClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -6888,7 +7289,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -6900,7 +7301,7 @@ def test_gke_hub_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.GkeHubTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -6912,7 +7313,7 @@ def test_gke_hub_base_transport(): ) as Transport: Transport.return_value = None transport = transports.GkeHubTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6959,7 +7360,7 @@ def test_gke_hub_base_transport_with_credentials_file(): "google.cloud.gkehub_v1.services.gke_hub.transports.GkeHubTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.GkeHubTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6978,7 +7379,7 @@ def test_gke_hub_base_transport_with_adc(): "google.cloud.gkehub_v1.services.gke_hub.transports.GkeHubTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.GkeHubTransport() adc.assert_called_once() @@ -6986,7 +7387,7 @@ def test_gke_hub_base_transport_with_adc(): def test_gke_hub_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) GkeHubClient() adc.assert_called_once_with( scopes=None, @@ -7006,7 +7407,7 @@ def test_gke_hub_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -7053,7 +7454,7 @@ def test_gke_hub_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -7078,7 +7479,7 @@ def test_gke_hub_transport_create_channel(transport_class, grpc_helpers): [transports.GkeHubGrpcTransport, transports.GkeHubGrpcAsyncIOTransport], ) def test_gke_hub_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -7116,7 +7517,7 @@ def test_gke_hub_grpc_transport_client_cert_source_for_mtls(transport_class): def test_gke_hub_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -7128,7 +7529,7 @@ def test_gke_hub_http_transport_client_cert_source_for_mtls(): def test_gke_hub_rest_lro_client(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -7153,7 +7554,7 @@ def test_gke_hub_rest_lro_client(): ) def test_gke_hub_host_no_port(transport_name): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkehub.googleapis.com" ), @@ -7176,7 +7577,7 @@ def test_gke_hub_host_no_port(transport_name): ) def test_gke_hub_host_with_port(transport_name): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkehub.googleapis.com:8000" ), @@ -7196,8 +7597,8 @@ def test_gke_hub_host_with_port(transport_name): ], ) def test_gke_hub_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = GkeHubClient( credentials=creds1, transport=transport_name, @@ -7286,7 +7687,7 @@ def test_gke_hub_transport_channel_mtls_with_client_cert_source(transport_class) mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -7361,7 +7762,7 @@ def test_gke_hub_transport_channel_mtls_with_adc(transport_class): def test_gke_hub_grpc_lro_client(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -7378,7 +7779,7 @@ def test_gke_hub_grpc_lro_client(): def test_gke_hub_grpc_lro_async_client(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -7557,7 +7958,7 @@ def test_client_with_default_client_info(): transports.GkeHubTransport, "_prep_wrapped_messages" ) as prep: client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7567,7 +7968,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = GkeHubClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -7576,7 +7977,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = GkeHubAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -7595,7 +7996,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7612,7 +8013,7 @@ def test_client_ctx(): ] for transport in transports: client = GkeHubClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7643,7 +8044,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, diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud/gapic_version.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud/gapic_version.py index 7257802240c5..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud/gapic_version.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.6.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/gapic_version.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/gapic_version.py index 7257802240c5..360a0d13ebdd 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/gapic_version.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.6.5" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py index b9e6f4935e84..655d3e3eafea 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/async_client.py @@ -38,9 +38,9 @@ from google.cloud.gke_multicloud_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -69,8 +69,12 @@ class AttachedClustersAsyncClient: _client: AttachedClustersClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = AttachedClustersClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AttachedClustersClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = AttachedClustersClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = AttachedClustersClient._DEFAULT_UNIVERSE attached_cluster_path = staticmethod(AttachedClustersClient.attached_cluster_path) parse_attached_cluster_path = staticmethod( @@ -185,6 +189,25 @@ def transport(self) -> AttachedClustersTransport: """ 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(AttachedClustersClient).get_transport_class, type(AttachedClustersClient) ) @@ -197,7 +220,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the attached clusters client. + """Instantiates the attached clusters async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -208,23 +231,41 @@ def __init__( transport (Union[str, ~.AttachedClustersTransport]): 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: + NOTE: "rest" transport functionality is currently in a + beta state (preview). We welcome your feedback via an + issue in this library's source repository. + 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. @@ -387,6 +428,9 @@ async def sample_create_attached_cluster(): 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, @@ -539,6 +583,9 @@ async def sample_update_attached_cluster(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -689,6 +736,9 @@ async def sample_import_attached_cluster(): 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, @@ -821,6 +871,9 @@ async def sample_get_attached_cluster(): 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, @@ -950,6 +1003,9 @@ async def sample_list_attached_clusters(): 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, @@ -1092,6 +1148,9 @@ async def sample_delete_attached_cluster(): 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, @@ -1223,6 +1282,9 @@ async def sample_get_attached_server_config(): 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, @@ -1376,6 +1438,9 @@ async def sample_generate_attached_cluster_install_manifest(): 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, @@ -1469,6 +1534,9 @@ async def sample_generate_attached_cluster_agent_token(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1523,6 +1591,9 @@ async def list_operations( 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, @@ -1577,6 +1648,9 @@ async def get_operation( 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, @@ -1635,6 +1709,9 @@ async def delete_operation( 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, @@ -1689,6 +1766,9 @@ async def cancel_operation( 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-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py index 196e89f0fb1a..f17e96b95f78 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.gke_multicloud_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -139,11 +140,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 = "gkemulticloud.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "gkemulticloud.{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 @@ -314,7 +319,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 @@ -344,6 +349,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") @@ -377,6 +387,175 @@ 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 + + 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 + + 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 = AttachedClustersClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = AttachedClustersClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = AttachedClustersClient._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 = AttachedClustersClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = AttachedClustersClient._DEFAULT_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 AttachedClustersClient._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, *, @@ -399,22 +578,32 @@ def __init__( NOTE: "rest" transport functionality is currently in a beta state (preview). We welcome your feedback via an issue in this library's source repository. - 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. @@ -425,17 +614,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, + ) = AttachedClustersClient._read_environment_variables() + self._client_cert_source = AttachedClustersClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = AttachedClustersClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -444,20 +650,33 @@ 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, AttachedClustersTransport): + transport_provided = isinstance(transport, AttachedClustersTransport) + if transport_provided: # transport is a AttachedClustersTransport 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(AttachedClustersTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or AttachedClustersClient._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( @@ -467,17 +686,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 create_attached_cluster( @@ -631,6 +850,9 @@ def sample_create_attached_cluster(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -783,6 +1005,9 @@ def sample_update_attached_cluster(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -933,6 +1158,9 @@ def sample_import_attached_cluster(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1056,6 +1284,9 @@ def sample_get_attached_cluster(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1176,6 +1407,9 @@ def sample_list_attached_clusters(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1318,6 +1552,9 @@ def sample_delete_attached_cluster(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1442,6 +1679,9 @@ def sample_get_attached_server_config(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1590,6 +1830,9 @@ def sample_generate_attached_cluster_install_manifest(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1679,6 +1922,9 @@ def sample_generate_attached_cluster_agent_token(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1746,6 +1992,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1800,6 +2049,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1858,6 +2110,9 @@ def delete_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1912,6 +2167,9 @@ def cancel_operation( 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-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/base.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/base.py index 45569b4e371e..df3b15f3b7d8 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/base.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/base.py @@ -57,7 +57,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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 @@ -120,6 +120,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-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py index 3b902a0db0fd..01911854d79b 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py index c161cd10419e..b5e743249305 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/rest.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/rest.py index 1a217e507553..6c1988f8480c 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/rest.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/attached_clusters/transports/rest.py @@ -37,9 +37,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -509,7 +509,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py index e55017fed19a..35fcea6c151a 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/async_client.py @@ -38,9 +38,9 @@ from google.cloud.gke_multicloud_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -69,8 +69,12 @@ class AwsClustersAsyncClient: _client: AwsClustersClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = AwsClustersClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AwsClustersClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = AwsClustersClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = AwsClustersClient._DEFAULT_UNIVERSE aws_cluster_path = staticmethod(AwsClustersClient.aws_cluster_path) parse_aws_cluster_path = staticmethod(AwsClustersClient.parse_aws_cluster_path) @@ -179,6 +183,25 @@ def transport(self) -> AwsClustersTransport: """ 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(AwsClustersClient).get_transport_class, type(AwsClustersClient) ) @@ -191,7 +214,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the aws clusters client. + """Instantiates the aws clusters async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -202,23 +225,41 @@ def __init__( transport (Union[str, ~.AwsClustersTransport]): 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: + NOTE: "rest" transport functionality is currently in a + beta state (preview). We welcome your feedback via an + issue in this library's source repository. + 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. @@ -386,6 +427,9 @@ async def sample_create_aws_cluster(): 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, @@ -560,6 +604,9 @@ async def sample_update_aws_cluster(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -687,6 +734,9 @@ async def sample_get_aws_cluster(): 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, @@ -812,6 +862,9 @@ async def sample_list_aws_clusters(): 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, @@ -955,6 +1008,9 @@ async def sample_delete_aws_cluster(): 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, @@ -1056,6 +1112,9 @@ async def sample_generate_aws_cluster_agent_token(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1150,6 +1209,9 @@ async def sample_generate_aws_access_token(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1314,6 +1376,9 @@ async def sample_create_aws_node_pool(): 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, @@ -1487,6 +1552,9 @@ async def sample_update_aws_node_pool(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1619,6 +1687,9 @@ async def sample_rollback_aws_node_pool_update(): 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, @@ -1746,6 +1817,9 @@ async def sample_get_aws_node_pool(): 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, @@ -1873,6 +1947,9 @@ async def sample_list_aws_node_pools(): 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, @@ -2012,6 +2089,9 @@ async def sample_delete_aws_node_pool(): 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, @@ -2118,6 +2198,9 @@ async def sample_get_aws_open_id_config(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2213,6 +2296,9 @@ async def sample_get_aws_json_web_keys(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2334,6 +2420,9 @@ async def sample_get_aws_server_config(): 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, @@ -2388,6 +2477,9 @@ async def list_operations( 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, @@ -2442,6 +2534,9 @@ async def get_operation( 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, @@ -2500,6 +2595,9 @@ async def delete_operation( 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, @@ -2554,6 +2652,9 @@ async def cancel_operation( 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-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py index cd295e6a5940..28b7d0cb5b78 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.gke_multicloud_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -137,11 +138,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 = "gkemulticloud.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "gkemulticloud.{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 @@ -338,7 +343,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 @@ -368,6 +373,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") @@ -401,6 +411,175 @@ 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 + + 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 + + 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 = AwsClustersClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = AwsClustersClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = AwsClustersClient._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 = AwsClustersClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = AwsClustersClient._DEFAULT_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 AwsClustersClient._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, *, @@ -423,22 +602,32 @@ def __init__( NOTE: "rest" transport functionality is currently in a beta state (preview). We welcome your feedback via an issue in this library's source repository. - 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. @@ -449,17 +638,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, + ) = AwsClustersClient._read_environment_variables() + self._client_cert_source = AwsClustersClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert ) + self._universe_domain = AwsClustersClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env + ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -468,20 +674,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, AwsClustersTransport): + transport_provided = isinstance(transport, AwsClustersTransport) + if transport_provided: # transport is a AwsClustersTransport 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(AwsClustersTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or AwsClustersClient._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( @@ -491,17 +707,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 create_aws_cluster( @@ -660,6 +876,9 @@ def sample_create_aws_cluster(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -834,6 +1053,9 @@ def sample_update_aws_cluster(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -952,6 +1174,9 @@ def sample_get_aws_cluster(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1068,6 +1293,9 @@ def sample_list_aws_clusters(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1211,6 +1439,9 @@ def sample_delete_aws_cluster(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1306,6 +1537,9 @@ def sample_generate_aws_cluster_agent_token(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1394,6 +1628,9 @@ def sample_generate_aws_access_token(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1558,6 +1795,9 @@ def sample_create_aws_node_pool(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1731,6 +1971,9 @@ def sample_update_aws_node_pool(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1865,6 +2108,9 @@ def sample_rollback_aws_node_pool_update(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1983,6 +2229,9 @@ def sample_get_aws_node_pool(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2101,6 +2350,9 @@ def sample_list_aws_node_pools(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2240,6 +2492,9 @@ def sample_delete_aws_node_pool(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2338,6 +2593,9 @@ def sample_get_aws_open_id_config(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2425,6 +2683,9 @@ def sample_get_aws_json_web_keys(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2537,6 +2798,9 @@ def sample_get_aws_server_config(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2604,6 +2868,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2658,6 +2925,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2716,6 +2986,9 @@ def delete_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -2770,6 +3043,9 @@ def cancel_operation( 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-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/base.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/base.py index a33e5ac619d1..424a49c7bffe 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/base.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/base.py @@ -57,7 +57,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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 @@ -120,6 +120,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-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py index e4d03771edd3..ed24432edb84 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py index ec7aaece46f2..2de6e7018a31 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/rest.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/rest.py index ca74a01967d7..97eafca5e4e0 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/rest.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/aws_clusters/transports/rest.py @@ -37,9 +37,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -712,7 +712,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py index 8aadab8e1197..61abf5b8095b 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/async_client.py @@ -38,9 +38,9 @@ from google.cloud.gke_multicloud_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -69,8 +69,12 @@ class AzureClustersAsyncClient: _client: AzureClustersClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = AzureClustersClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = AzureClustersClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = AzureClustersClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = AzureClustersClient._DEFAULT_UNIVERSE azure_client_path = staticmethod(AzureClustersClient.azure_client_path) parse_azure_client_path = staticmethod(AzureClustersClient.parse_azure_client_path) @@ -191,6 +195,25 @@ def transport(self) -> AzureClustersTransport: """ 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(AzureClustersClient).get_transport_class, type(AzureClustersClient) ) @@ -203,7 +226,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the azure clusters client. + """Instantiates the azure clusters async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -214,23 +237,41 @@ def __init__( transport (Union[str, ~.AzureClustersTransport]): 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: + NOTE: "rest" transport functionality is currently in a + beta state (preview). We welcome your feedback via an + issue in this library's source repository. + 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. @@ -406,6 +447,9 @@ async def sample_create_azure_client(): 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, @@ -550,6 +594,9 @@ async def sample_get_azure_client(): 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, @@ -677,6 +724,9 @@ async def sample_list_azure_clients(): 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, @@ -820,6 +870,9 @@ async def sample_delete_azure_client(): 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, @@ -992,6 +1045,9 @@ async def sample_create_azure_cluster(): 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, @@ -1153,6 +1209,9 @@ async def sample_update_azure_cluster(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1281,6 +1340,9 @@ async def sample_get_azure_cluster(): 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, @@ -1408,6 +1470,9 @@ async def sample_list_azure_clusters(): 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, @@ -1552,6 +1617,9 @@ async def sample_delete_azure_cluster(): 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, @@ -1653,6 +1721,9 @@ async def sample_generate_azure_cluster_agent_token(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1748,6 +1819,9 @@ async def sample_generate_azure_access_token(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -1911,6 +1985,9 @@ async def sample_create_azure_node_pool(): 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, @@ -2061,6 +2138,9 @@ async def sample_update_azure_node_pool(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2188,6 +2268,9 @@ async def sample_get_azure_node_pool(): 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, @@ -2315,6 +2398,9 @@ async def sample_list_azure_node_pools(): 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, @@ -2454,6 +2540,9 @@ async def sample_delete_azure_node_pool(): 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, @@ -2587,6 +2676,9 @@ async def sample_get_azure_open_id_config(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2706,6 +2798,9 @@ async def sample_get_azure_json_web_keys(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -2831,6 +2926,9 @@ async def sample_get_azure_server_config(): 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, @@ -2885,6 +2983,9 @@ async def list_operations( 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, @@ -2939,6 +3040,9 @@ async def get_operation( 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, @@ -2997,6 +3101,9 @@ async def delete_operation( 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, @@ -3051,6 +3158,9 @@ async def cancel_operation( 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-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py index 7f9906884da8..d669ae3c749a 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.gke_multicloud_v1 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -137,11 +138,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 = "gkemulticloud.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "gkemulticloud.{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 @@ -358,7 +363,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 @@ -388,6 +393,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") @@ -421,6 +431,175 @@ 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 + + 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 + + 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 = AzureClustersClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = AzureClustersClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = AzureClustersClient._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 = AzureClustersClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = AzureClustersClient._DEFAULT_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 AzureClustersClient._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, *, @@ -443,22 +622,32 @@ def __init__( NOTE: "rest" transport functionality is currently in a beta state (preview). We welcome your feedback via an issue in this library's source repository. - 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. @@ -469,17 +658,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, + ) = AzureClustersClient._read_environment_variables() + self._client_cert_source = AzureClustersClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = AzureClustersClient._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" @@ -488,20 +694,33 @@ 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, AzureClustersTransport): + transport_provided = isinstance(transport, AzureClustersTransport) + if transport_provided: # transport is a AzureClustersTransport 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(AzureClustersTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or AzureClustersClient._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( @@ -511,17 +730,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 create_azure_client( @@ -688,6 +907,9 @@ def sample_create_azure_client(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -823,6 +1045,9 @@ def sample_get_azure_client(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -941,6 +1166,9 @@ def sample_list_azure_clients(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1084,6 +1312,9 @@ def sample_delete_azure_client(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1256,6 +1487,9 @@ def sample_create_azure_cluster(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1417,6 +1651,9 @@ def sample_update_azure_cluster(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1536,6 +1773,9 @@ def sample_get_azure_cluster(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1654,6 +1894,9 @@ def sample_list_azure_clusters(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1798,6 +2041,9 @@ def sample_delete_azure_cluster(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1893,6 +2139,9 @@ def sample_generate_azure_cluster_agent_token(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1982,6 +2231,9 @@ def sample_generate_azure_access_token(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2145,6 +2397,9 @@ def sample_create_azure_node_pool(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2295,6 +2550,9 @@ def sample_update_azure_node_pool(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2413,6 +2671,9 @@ def sample_get_azure_node_pool(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2531,6 +2792,9 @@ def sample_list_azure_node_pools(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2670,6 +2934,9 @@ def sample_delete_azure_node_pool(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2794,6 +3061,9 @@ def sample_get_azure_open_id_config(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -2904,6 +3174,9 @@ def sample_get_azure_json_web_keys(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3020,6 +3293,9 @@ def sample_get_azure_server_config(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3087,6 +3363,9 @@ def list_operations( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3141,6 +3420,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -3199,6 +3481,9 @@ def delete_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -3253,6 +3538,9 @@ def cancel_operation( 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-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/base.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/base.py index 2910949a8f63..61f961c581c3 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/base.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/base.py @@ -57,7 +57,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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 @@ -120,6 +120,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-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py index 8f1751f9192b..dbbac00ffae3 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py index 05c98366a86b..49d9b564cb7c 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/rest.py b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/rest.py index eb263eb1d97e..1d746738c6cf 100644 --- a/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/rest.py +++ b/packages/google-cloud-gke-multicloud/google/cloud/gke_multicloud_v1/services/azure_clusters/transports/rest.py @@ -37,9 +37,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -807,7 +807,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gkemulticloud.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-gke-multicloud/noxfile.py b/packages/google-cloud-gke-multicloud/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-gke-multicloud/noxfile.py +++ b/packages/google-cloud-gke-multicloud/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-gke-multicloud/samples/generated_samples/snippet_metadata_google.cloud.gkemulticloud.v1.json b/packages/google-cloud-gke-multicloud/samples/generated_samples/snippet_metadata_google.cloud.gkemulticloud.v1.json index baaa77b57773..08dd05577dce 100644 --- a/packages/google-cloud-gke-multicloud/samples/generated_samples/snippet_metadata_google.cloud.gkemulticloud.v1.json +++ b/packages/google-cloud-gke-multicloud/samples/generated_samples/snippet_metadata_google.cloud.gkemulticloud.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-gke-multicloud", - "version": "0.6.5" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py index 674488dc1f8c..aa398d1ed8be 100644 --- a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py +++ b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_attached_clusters.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -83,6 +83,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -113,6 +136,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert AttachedClustersClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert AttachedClustersClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert AttachedClustersClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + AttachedClustersClient._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 AttachedClustersClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert AttachedClustersClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert AttachedClustersClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + AttachedClustersClient._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 AttachedClustersClient._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 AttachedClustersClient._get_client_cert_source(None, False) is None + assert ( + AttachedClustersClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + AttachedClustersClient._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 ( + AttachedClustersClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + AttachedClustersClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + AttachedClustersClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AttachedClustersClient), +) +@mock.patch.object( + AttachedClustersAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AttachedClustersAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = AttachedClustersClient._DEFAULT_UNIVERSE + default_endpoint = AttachedClustersClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AttachedClustersClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + AttachedClustersClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + AttachedClustersClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == AttachedClustersClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AttachedClustersClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + AttachedClustersClient._get_api_endpoint(None, None, default_universe, "always") + == AttachedClustersClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AttachedClustersClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == AttachedClustersClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AttachedClustersClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + AttachedClustersClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + AttachedClustersClient._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 ( + AttachedClustersClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + AttachedClustersClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + AttachedClustersClient._get_universe_domain(None, None) + == AttachedClustersClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + AttachedClustersClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (AttachedClustersClient, transports.AttachedClustersGrpcTransport, "grpc"), + (AttachedClustersClient, transports.AttachedClustersRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -124,7 +408,7 @@ def test__get_default_mtls_endpoint(): def test_attached_clusters_client_from_service_account_info( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -178,7 +462,7 @@ def test_attached_clusters_client_service_account_always_use_jwt( def test_attached_clusters_client_from_service_account_file( client_class, transport_name ): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -228,20 +512,22 @@ def test_attached_clusters_client_get_transport_class(): ) @mock.patch.object( AttachedClustersClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AttachedClustersClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AttachedClustersClient), ) @mock.patch.object( AttachedClustersAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AttachedClustersAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AttachedClustersAsyncClient), ) def test_attached_clusters_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(AttachedClustersClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -276,7 +562,9 @@ def test_attached_clusters_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, @@ -306,15 +594,23 @@ def test_attached_clusters_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") @@ -324,7 +620,9 @@ def test_attached_clusters_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", @@ -342,7 +640,9 @@ def test_attached_clusters_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, @@ -395,13 +695,13 @@ def test_attached_clusters_client_client_options( ) @mock.patch.object( AttachedClustersClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AttachedClustersClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AttachedClustersClient), ) @mock.patch.object( AttachedClustersAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AttachedClustersAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AttachedClustersAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_attached_clusters_client_mtls_env_auto( @@ -424,7 +724,9 @@ def test_attached_clusters_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 @@ -456,7 +758,9 @@ def test_attached_clusters_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 @@ -490,7 +794,9 @@ def test_attached_clusters_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, @@ -580,6 +886,118 @@ def test_attached_clusters_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", [AttachedClustersClient, AttachedClustersAsyncClient] +) +@mock.patch.object( + AttachedClustersClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AttachedClustersClient), +) +@mock.patch.object( + AttachedClustersAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AttachedClustersAsyncClient), +) +def test_attached_clusters_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = AttachedClustersClient._DEFAULT_UNIVERSE + default_endpoint = AttachedClustersClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AttachedClustersClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -606,7 +1024,9 @@ def test_attached_clusters_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, @@ -651,7 +1071,9 @@ def test_attached_clusters_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, @@ -711,7 +1133,9 @@ def test_attached_clusters_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, @@ -728,8 +1152,8 @@ def test_attached_clusters_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -758,7 +1182,7 @@ def test_attached_clusters_client_create_channel_credentials_file( ) def test_create_attached_cluster(request_type, transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -787,7 +1211,7 @@ def test_create_attached_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -807,7 +1231,7 @@ async def test_create_attached_cluster_async( request_type=attached_service.CreateAttachedClusterRequest, ): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -841,7 +1265,7 @@ async def test_create_attached_cluster_async_from_dict(): def test_create_attached_cluster_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -873,7 +1297,7 @@ def test_create_attached_cluster_field_headers(): @pytest.mark.asyncio async def test_create_attached_cluster_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -906,7 +1330,7 @@ async def test_create_attached_cluster_field_headers_async(): def test_create_attached_cluster_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -940,7 +1364,7 @@ def test_create_attached_cluster_flattened(): def test_create_attached_cluster_flattened_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -957,7 +1381,7 @@ def test_create_attached_cluster_flattened_error(): @pytest.mark.asyncio async def test_create_attached_cluster_flattened_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -996,7 +1420,7 @@ async def test_create_attached_cluster_flattened_async(): @pytest.mark.asyncio async def test_create_attached_cluster_flattened_error_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1019,7 +1443,7 @@ async def test_create_attached_cluster_flattened_error_async(): ) def test_update_attached_cluster(request_type, transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1048,7 +1472,7 @@ def test_update_attached_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1068,7 +1492,7 @@ async def test_update_attached_cluster_async( request_type=attached_service.UpdateAttachedClusterRequest, ): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1102,7 +1526,7 @@ async def test_update_attached_cluster_async_from_dict(): def test_update_attached_cluster_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1134,7 +1558,7 @@ def test_update_attached_cluster_field_headers(): @pytest.mark.asyncio async def test_update_attached_cluster_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1167,7 +1591,7 @@ async def test_update_attached_cluster_field_headers_async(): def test_update_attached_cluster_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1197,7 +1621,7 @@ def test_update_attached_cluster_flattened(): def test_update_attached_cluster_flattened_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1213,7 +1637,7 @@ def test_update_attached_cluster_flattened_error(): @pytest.mark.asyncio async def test_update_attached_cluster_flattened_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1248,7 +1672,7 @@ async def test_update_attached_cluster_flattened_async(): @pytest.mark.asyncio async def test_update_attached_cluster_flattened_error_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1270,7 +1694,7 @@ async def test_update_attached_cluster_flattened_error_async(): ) def test_import_attached_cluster(request_type, transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1299,7 +1723,7 @@ def test_import_attached_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1319,7 +1743,7 @@ async def test_import_attached_cluster_async( request_type=attached_service.ImportAttachedClusterRequest, ): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1353,7 +1777,7 @@ async def test_import_attached_cluster_async_from_dict(): def test_import_attached_cluster_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1385,7 +1809,7 @@ def test_import_attached_cluster_field_headers(): @pytest.mark.asyncio async def test_import_attached_cluster_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1418,7 +1842,7 @@ async def test_import_attached_cluster_field_headers_async(): def test_import_attached_cluster_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1448,7 +1872,7 @@ def test_import_attached_cluster_flattened(): def test_import_attached_cluster_flattened_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1464,7 +1888,7 @@ def test_import_attached_cluster_flattened_error(): @pytest.mark.asyncio async def test_import_attached_cluster_flattened_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1499,7 +1923,7 @@ async def test_import_attached_cluster_flattened_async(): @pytest.mark.asyncio async def test_import_attached_cluster_flattened_error_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1521,7 +1945,7 @@ async def test_import_attached_cluster_flattened_error_async(): ) def test_get_attached_cluster(request_type, transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1571,7 +1995,7 @@ def test_get_attached_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1591,7 +2015,7 @@ async def test_get_attached_cluster_async( request_type=attached_service.GetAttachedClusterRequest, ): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1646,7 +2070,7 @@ async def test_get_attached_cluster_async_from_dict(): def test_get_attached_cluster_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1678,7 +2102,7 @@ def test_get_attached_cluster_field_headers(): @pytest.mark.asyncio async def test_get_attached_cluster_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1711,7 +2135,7 @@ async def test_get_attached_cluster_field_headers_async(): def test_get_attached_cluster_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1737,7 +2161,7 @@ def test_get_attached_cluster_flattened(): def test_get_attached_cluster_flattened_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1752,7 +2176,7 @@ def test_get_attached_cluster_flattened_error(): @pytest.mark.asyncio async def test_get_attached_cluster_flattened_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1783,7 +2207,7 @@ async def test_get_attached_cluster_flattened_async(): @pytest.mark.asyncio async def test_get_attached_cluster_flattened_error_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1804,7 +2228,7 @@ async def test_get_attached_cluster_flattened_error_async(): ) def test_list_attached_clusters(request_type, transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1836,7 +2260,7 @@ def test_list_attached_clusters_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1856,7 +2280,7 @@ async def test_list_attached_clusters_async( request_type=attached_service.ListAttachedClustersRequest, ): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1893,7 +2317,7 @@ async def test_list_attached_clusters_async_from_dict(): def test_list_attached_clusters_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1925,7 +2349,7 @@ def test_list_attached_clusters_field_headers(): @pytest.mark.asyncio async def test_list_attached_clusters_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1958,7 +2382,7 @@ async def test_list_attached_clusters_field_headers_async(): def test_list_attached_clusters_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1984,7 +2408,7 @@ def test_list_attached_clusters_flattened(): def test_list_attached_clusters_flattened_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1999,7 +2423,7 @@ def test_list_attached_clusters_flattened_error(): @pytest.mark.asyncio async def test_list_attached_clusters_flattened_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2030,7 +2454,7 @@ async def test_list_attached_clusters_flattened_async(): @pytest.mark.asyncio async def test_list_attached_clusters_flattened_error_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2044,7 +2468,7 @@ async def test_list_attached_clusters_flattened_error_async(): def test_list_attached_clusters_pager(transport_name: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2096,7 +2520,7 @@ def test_list_attached_clusters_pager(transport_name: str = "grpc"): def test_list_attached_clusters_pages(transport_name: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2140,7 +2564,7 @@ def test_list_attached_clusters_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_attached_clusters_async_pager(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2192,7 +2616,7 @@ async def test_list_attached_clusters_async_pager(): @pytest.mark.asyncio async def test_list_attached_clusters_async_pages(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2249,7 +2673,7 @@ async def test_list_attached_clusters_async_pages(): ) def test_delete_attached_cluster(request_type, transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2278,7 +2702,7 @@ def test_delete_attached_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2298,7 +2722,7 @@ async def test_delete_attached_cluster_async( request_type=attached_service.DeleteAttachedClusterRequest, ): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2332,7 +2756,7 @@ async def test_delete_attached_cluster_async_from_dict(): def test_delete_attached_cluster_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2364,7 +2788,7 @@ def test_delete_attached_cluster_field_headers(): @pytest.mark.asyncio async def test_delete_attached_cluster_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2397,7 +2821,7 @@ async def test_delete_attached_cluster_field_headers_async(): def test_delete_attached_cluster_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2423,7 +2847,7 @@ def test_delete_attached_cluster_flattened(): def test_delete_attached_cluster_flattened_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2438,7 +2862,7 @@ def test_delete_attached_cluster_flattened_error(): @pytest.mark.asyncio async def test_delete_attached_cluster_flattened_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2469,7 +2893,7 @@ async def test_delete_attached_cluster_flattened_async(): @pytest.mark.asyncio async def test_delete_attached_cluster_flattened_error_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2490,7 +2914,7 @@ async def test_delete_attached_cluster_flattened_error_async(): ) def test_get_attached_server_config(request_type, transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2522,7 +2946,7 @@ def test_get_attached_server_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2542,7 +2966,7 @@ async def test_get_attached_server_config_async( request_type=attached_service.GetAttachedServerConfigRequest, ): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2579,7 +3003,7 @@ async def test_get_attached_server_config_async_from_dict(): def test_get_attached_server_config_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2611,7 +3035,7 @@ def test_get_attached_server_config_field_headers(): @pytest.mark.asyncio async def test_get_attached_server_config_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2644,7 +3068,7 @@ async def test_get_attached_server_config_field_headers_async(): def test_get_attached_server_config_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2670,7 +3094,7 @@ def test_get_attached_server_config_flattened(): def test_get_attached_server_config_flattened_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2685,7 +3109,7 @@ def test_get_attached_server_config_flattened_error(): @pytest.mark.asyncio async def test_get_attached_server_config_flattened_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2716,7 +3140,7 @@ async def test_get_attached_server_config_flattened_async(): @pytest.mark.asyncio async def test_get_attached_server_config_flattened_error_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2739,7 +3163,7 @@ def test_generate_attached_cluster_install_manifest( request_type, transport: str = "grpc" ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2777,7 +3201,7 @@ def test_generate_attached_cluster_install_manifest_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2799,7 +3223,7 @@ async def test_generate_attached_cluster_install_manifest_async( request_type=attached_service.GenerateAttachedClusterInstallManifestRequest, ): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2840,7 +3264,7 @@ async def test_generate_attached_cluster_install_manifest_async_from_dict(): def test_generate_attached_cluster_install_manifest_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2874,7 +3298,7 @@ def test_generate_attached_cluster_install_manifest_field_headers(): @pytest.mark.asyncio async def test_generate_attached_cluster_install_manifest_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2907,7 +3331,7 @@ async def test_generate_attached_cluster_install_manifest_field_headers_async(): def test_generate_attached_cluster_install_manifest_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2939,7 +3363,7 @@ def test_generate_attached_cluster_install_manifest_flattened(): def test_generate_attached_cluster_install_manifest_flattened_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2955,7 +3379,7 @@ def test_generate_attached_cluster_install_manifest_flattened_error(): @pytest.mark.asyncio async def test_generate_attached_cluster_install_manifest_flattened_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2992,7 +3416,7 @@ async def test_generate_attached_cluster_install_manifest_flattened_async(): @pytest.mark.asyncio async def test_generate_attached_cluster_install_manifest_flattened_error_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3014,7 +3438,7 @@ async def test_generate_attached_cluster_install_manifest_flattened_error_async( ) def test_generate_attached_cluster_agent_token(request_type, transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3052,7 +3476,7 @@ def test_generate_attached_cluster_agent_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3072,7 +3496,7 @@ async def test_generate_attached_cluster_agent_token_async( request_type=attached_service.GenerateAttachedClusterAgentTokenRequest, ): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3115,7 +3539,7 @@ async def test_generate_attached_cluster_agent_token_async_from_dict(): def test_generate_attached_cluster_agent_token_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3147,7 +3571,7 @@ def test_generate_attached_cluster_agent_token_field_headers(): @pytest.mark.asyncio async def test_generate_attached_cluster_agent_token_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3187,7 +3611,7 @@ async def test_generate_attached_cluster_agent_token_field_headers_async(): ) def test_create_attached_cluster_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3337,7 +3761,7 @@ def test_create_attached_cluster_rest_required_fields( assert "attachedClusterId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_attached_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3349,7 +3773,7 @@ def test_create_attached_cluster_rest_required_fields( jsonified_request["attachedClusterId"] = "attached_cluster_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_attached_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3367,7 +3791,7 @@ def test_create_attached_cluster_rest_required_fields( assert jsonified_request["attachedClusterId"] == "attached_cluster_id_value" client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3412,7 +3836,7 @@ def test_create_attached_cluster_rest_required_fields( def test_create_attached_cluster_rest_unset_required_fields(): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_attached_cluster._get_unset_required_fields({}) @@ -3436,7 +3860,7 @@ def test_create_attached_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_attached_cluster_rest_interceptors(null_interceptor): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AttachedClustersRestInterceptor(), @@ -3496,7 +3920,7 @@ def test_create_attached_cluster_rest_bad_request( transport: str = "rest", request_type=attached_service.CreateAttachedClusterRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3518,7 +3942,7 @@ def test_create_attached_cluster_rest_bad_request( def test_create_attached_cluster_rest_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3560,7 +3984,7 @@ def test_create_attached_cluster_rest_flattened(): def test_create_attached_cluster_rest_flattened_error(transport: str = "rest"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3577,7 +4001,7 @@ def test_create_attached_cluster_rest_flattened_error(transport: str = "rest"): def test_create_attached_cluster_rest_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3590,7 +4014,7 @@ def test_create_attached_cluster_rest_error(): ) def test_update_attached_cluster_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3741,14 +4165,14 @@ def test_update_attached_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_attached_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_attached_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -3762,7 +4186,7 @@ def test_update_attached_cluster_rest_required_fields( # verify required fields with non-default values are left alone client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3802,7 +4226,7 @@ def test_update_attached_cluster_rest_required_fields( def test_update_attached_cluster_rest_unset_required_fields(): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_attached_cluster._get_unset_required_fields({}) @@ -3825,7 +4249,7 @@ def test_update_attached_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_attached_cluster_rest_interceptors(null_interceptor): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AttachedClustersRestInterceptor(), @@ -3885,7 +4309,7 @@ def test_update_attached_cluster_rest_bad_request( transport: str = "rest", request_type=attached_service.UpdateAttachedClusterRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3911,7 +4335,7 @@ def test_update_attached_cluster_rest_bad_request( def test_update_attached_cluster_rest_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3956,7 +4380,7 @@ def test_update_attached_cluster_rest_flattened(): def test_update_attached_cluster_rest_flattened_error(transport: str = "rest"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3972,7 +4396,7 @@ def test_update_attached_cluster_rest_flattened_error(transport: str = "rest"): def test_update_attached_cluster_rest_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3985,7 +4409,7 @@ def test_update_attached_cluster_rest_error(): ) def test_import_attached_cluster_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4034,7 +4458,7 @@ def test_import_attached_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_attached_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4046,7 +4470,7 @@ def test_import_attached_cluster_rest_required_fields( jsonified_request["distribution"] = "distribution_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).import_attached_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4061,7 +4485,7 @@ def test_import_attached_cluster_rest_required_fields( assert jsonified_request["distribution"] == "distribution_value" client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4101,7 +4525,7 @@ def test_import_attached_cluster_rest_required_fields( def test_import_attached_cluster_rest_unset_required_fields(): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.import_attached_cluster._get_unset_required_fields({}) @@ -4121,7 +4545,7 @@ def test_import_attached_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_import_attached_cluster_rest_interceptors(null_interceptor): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AttachedClustersRestInterceptor(), @@ -4181,7 +4605,7 @@ def test_import_attached_cluster_rest_bad_request( transport: str = "rest", request_type=attached_service.ImportAttachedClusterRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4203,7 +4627,7 @@ def test_import_attached_cluster_rest_bad_request( def test_import_attached_cluster_rest_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4244,7 +4668,7 @@ def test_import_attached_cluster_rest_flattened(): def test_import_attached_cluster_rest_flattened_error(transport: str = "rest"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4260,7 +4684,7 @@ def test_import_attached_cluster_rest_flattened_error(transport: str = "rest"): def test_import_attached_cluster_rest_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4273,7 +4697,7 @@ def test_import_attached_cluster_rest_error(): ) def test_get_attached_cluster_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4344,7 +4768,7 @@ def test_get_attached_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_attached_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4353,7 +4777,7 @@ def test_get_attached_cluster_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_attached_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4362,7 +4786,7 @@ def test_get_attached_cluster_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4404,7 +4828,7 @@ def test_get_attached_cluster_rest_required_fields( def test_get_attached_cluster_rest_unset_required_fields(): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_attached_cluster._get_unset_required_fields({}) @@ -4414,7 +4838,7 @@ def test_get_attached_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_attached_cluster_rest_interceptors(null_interceptor): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AttachedClustersRestInterceptor(), @@ -4472,7 +4896,7 @@ def test_get_attached_cluster_rest_bad_request( transport: str = "rest", request_type=attached_service.GetAttachedClusterRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4496,7 +4920,7 @@ def test_get_attached_cluster_rest_bad_request( def test_get_attached_cluster_rest_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4540,7 +4964,7 @@ def test_get_attached_cluster_rest_flattened(): def test_get_attached_cluster_rest_flattened_error(transport: str = "rest"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4555,7 +4979,7 @@ def test_get_attached_cluster_rest_flattened_error(transport: str = "rest"): def test_get_attached_cluster_rest_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4568,7 +4992,7 @@ def test_get_attached_cluster_rest_error(): ) def test_list_attached_clusters_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4619,7 +5043,7 @@ def test_list_attached_clusters_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_attached_clusters._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4628,7 +5052,7 @@ def test_list_attached_clusters_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_attached_clusters._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4644,7 +5068,7 @@ def test_list_attached_clusters_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4688,7 +5112,7 @@ def test_list_attached_clusters_rest_required_fields( def test_list_attached_clusters_rest_unset_required_fields(): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_attached_clusters._get_unset_required_fields({}) @@ -4706,7 +5130,7 @@ def test_list_attached_clusters_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_attached_clusters_rest_interceptors(null_interceptor): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AttachedClustersRestInterceptor(), @@ -4766,7 +5190,7 @@ def test_list_attached_clusters_rest_bad_request( transport: str = "rest", request_type=attached_service.ListAttachedClustersRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4788,7 +5212,7 @@ def test_list_attached_clusters_rest_bad_request( def test_list_attached_clusters_rest_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4830,7 +5254,7 @@ def test_list_attached_clusters_rest_flattened(): def test_list_attached_clusters_rest_flattened_error(transport: str = "rest"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4845,7 +5269,7 @@ def test_list_attached_clusters_rest_flattened_error(transport: str = "rest"): def test_list_attached_clusters_rest_pager(transport: str = "rest"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4915,7 +5339,7 @@ def test_list_attached_clusters_rest_pager(transport: str = "rest"): ) def test_delete_attached_cluster_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4963,7 +5387,7 @@ def test_delete_attached_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_attached_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4972,7 +5396,7 @@ def test_delete_attached_cluster_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_attached_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4990,7 +5414,7 @@ def test_delete_attached_cluster_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5029,7 +5453,7 @@ def test_delete_attached_cluster_rest_required_fields( def test_delete_attached_cluster_rest_unset_required_fields(): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_attached_cluster._get_unset_required_fields({}) @@ -5049,7 +5473,7 @@ def test_delete_attached_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_attached_cluster_rest_interceptors(null_interceptor): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AttachedClustersRestInterceptor(), @@ -5109,7 +5533,7 @@ def test_delete_attached_cluster_rest_bad_request( transport: str = "rest", request_type=attached_service.DeleteAttachedClusterRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5133,7 +5557,7 @@ def test_delete_attached_cluster_rest_bad_request( def test_delete_attached_cluster_rest_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5175,7 +5599,7 @@ def test_delete_attached_cluster_rest_flattened(): def test_delete_attached_cluster_rest_flattened_error(transport: str = "rest"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5190,7 +5614,7 @@ def test_delete_attached_cluster_rest_flattened_error(transport: str = "rest"): def test_delete_attached_cluster_rest_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5203,7 +5627,7 @@ def test_delete_attached_cluster_rest_error(): ) def test_get_attached_server_config_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5254,7 +5678,7 @@ def test_get_attached_server_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_attached_server_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5263,7 +5687,7 @@ def test_get_attached_server_config_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_attached_server_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5272,7 +5696,7 @@ def test_get_attached_server_config_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5314,7 +5738,7 @@ def test_get_attached_server_config_rest_required_fields( def test_get_attached_server_config_rest_unset_required_fields(): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_attached_server_config._get_unset_required_fields({}) @@ -5324,7 +5748,7 @@ def test_get_attached_server_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_attached_server_config_rest_interceptors(null_interceptor): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AttachedClustersRestInterceptor(), @@ -5383,7 +5807,7 @@ def test_get_attached_server_config_rest_bad_request( request_type=attached_service.GetAttachedServerConfigRequest, ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5405,7 +5829,7 @@ def test_get_attached_server_config_rest_bad_request( def test_get_attached_server_config_rest_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5449,7 +5873,7 @@ def test_get_attached_server_config_rest_flattened(): def test_get_attached_server_config_rest_flattened_error(transport: str = "rest"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5464,7 +5888,7 @@ def test_get_attached_server_config_rest_flattened_error(transport: str = "rest" def test_get_attached_server_config_rest_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5477,7 +5901,7 @@ def test_get_attached_server_config_rest_error(): ) def test_generate_attached_cluster_install_manifest_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5538,7 +5962,7 @@ def test_generate_attached_cluster_install_manifest_rest_required_fields( assert "platformVersion" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_attached_cluster_install_manifest._get_unset_required_fields( jsonified_request ) @@ -5555,7 +5979,7 @@ def test_generate_attached_cluster_install_manifest_rest_required_fields( jsonified_request["platformVersion"] = "platform_version_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_attached_cluster_install_manifest._get_unset_required_fields( jsonified_request ) @@ -5578,7 +6002,7 @@ def test_generate_attached_cluster_install_manifest_rest_required_fields( assert jsonified_request["platformVersion"] == "platform_version_value" client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5633,7 +6057,7 @@ def test_generate_attached_cluster_install_manifest_rest_required_fields( def test_generate_attached_cluster_install_manifest_rest_unset_required_fields(): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -5662,7 +6086,7 @@ def test_generate_attached_cluster_install_manifest_rest_unset_required_fields() @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_attached_cluster_install_manifest_rest_interceptors(null_interceptor): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AttachedClustersRestInterceptor(), @@ -5727,7 +6151,7 @@ def test_generate_attached_cluster_install_manifest_rest_bad_request( request_type=attached_service.GenerateAttachedClusterInstallManifestRequest, ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5749,7 +6173,7 @@ def test_generate_attached_cluster_install_manifest_rest_bad_request( def test_generate_attached_cluster_install_manifest_rest_flattened(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5798,7 +6222,7 @@ def test_generate_attached_cluster_install_manifest_rest_flattened_error( transport: str = "rest", ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5814,7 +6238,7 @@ def test_generate_attached_cluster_install_manifest_rest_flattened_error( def test_generate_attached_cluster_install_manifest_rest_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5827,7 +6251,7 @@ def test_generate_attached_cluster_install_manifest_rest_error(): ) def test_generate_attached_cluster_agent_token_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5891,7 +6315,7 @@ def test_generate_attached_cluster_agent_token_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_attached_cluster_agent_token._get_unset_required_fields( jsonified_request ) @@ -5905,7 +6329,7 @@ def test_generate_attached_cluster_agent_token_rest_required_fields( jsonified_request["version"] = "version_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_attached_cluster_agent_token._get_unset_required_fields( jsonified_request ) @@ -5922,7 +6346,7 @@ def test_generate_attached_cluster_agent_token_rest_required_fields( assert jsonified_request["version"] == "version_value" client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5969,7 +6393,7 @@ def test_generate_attached_cluster_agent_token_rest_required_fields( def test_generate_attached_cluster_agent_token_rest_unset_required_fields(): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -5991,7 +6415,7 @@ def test_generate_attached_cluster_agent_token_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_attached_cluster_agent_token_rest_interceptors(null_interceptor): transport = transports.AttachedClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AttachedClustersRestInterceptor(), @@ -6054,7 +6478,7 @@ def test_generate_attached_cluster_agent_token_rest_bad_request( request_type=attached_service.GenerateAttachedClusterAgentTokenRequest, ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6078,24 +6502,24 @@ def test_generate_attached_cluster_agent_token_rest_bad_request( def test_generate_attached_cluster_agent_token_rest_error(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AttachedClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.AttachedClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AttachedClustersClient( @@ -6105,7 +6529,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.AttachedClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -6116,16 +6540,17 @@ 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 = AttachedClustersClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.AttachedClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AttachedClustersClient( @@ -6137,7 +6562,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AttachedClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = AttachedClustersClient(transport=transport) assert client.transport is transport @@ -6146,13 +6571,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AttachedClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.AttachedClustersGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -6169,7 +6594,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -6183,7 +6608,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = AttachedClustersClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -6191,7 +6616,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -6203,7 +6628,7 @@ def test_attached_clusters_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.AttachedClustersTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -6215,7 +6640,7 @@ def test_attached_clusters_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AttachedClustersTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6264,7 +6689,7 @@ def test_attached_clusters_base_transport_with_credentials_file(): "google.cloud.gke_multicloud_v1.services.attached_clusters.transports.AttachedClustersTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AttachedClustersTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6283,7 +6708,7 @@ def test_attached_clusters_base_transport_with_adc(): "google.cloud.gke_multicloud_v1.services.attached_clusters.transports.AttachedClustersTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AttachedClustersTransport() adc.assert_called_once() @@ -6291,7 +6716,7 @@ def test_attached_clusters_base_transport_with_adc(): def test_attached_clusters_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) AttachedClustersClient() adc.assert_called_once_with( scopes=None, @@ -6311,7 +6736,7 @@ def test_attached_clusters_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -6358,7 +6783,7 @@ def test_attached_clusters_transport_create_channel(transport_class, grpc_helper ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6386,7 +6811,7 @@ def test_attached_clusters_transport_create_channel(transport_class, grpc_helper ], ) def test_attached_clusters_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6424,7 +6849,7 @@ def test_attached_clusters_grpc_transport_client_cert_source_for_mtls(transport_ def test_attached_clusters_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -6436,7 +6861,7 @@ def test_attached_clusters_http_transport_client_cert_source_for_mtls(): def test_attached_clusters_rest_lro_client(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -6461,7 +6886,7 @@ def test_attached_clusters_rest_lro_client(): ) def test_attached_clusters_host_no_port(transport_name): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkemulticloud.googleapis.com" ), @@ -6484,7 +6909,7 @@ def test_attached_clusters_host_no_port(transport_name): ) def test_attached_clusters_host_with_port(transport_name): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkemulticloud.googleapis.com:8000" ), @@ -6504,8 +6929,8 @@ def test_attached_clusters_host_with_port(transport_name): ], ) def test_attached_clusters_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = AttachedClustersClient( credentials=creds1, transport=transport_name, @@ -6593,7 +7018,7 @@ def test_attached_clusters_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6671,7 +7096,7 @@ def test_attached_clusters_transport_channel_mtls_with_adc(transport_class): def test_attached_clusters_grpc_lro_client(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -6688,7 +7113,7 @@ def test_attached_clusters_grpc_lro_client(): def test_attached_clusters_grpc_lro_async_client(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -6864,7 +7289,7 @@ def test_client_with_default_client_info(): transports.AttachedClustersTransport, "_prep_wrapped_messages" ) as prep: client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6874,7 +7299,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = AttachedClustersClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6883,7 +7308,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6898,7 +7323,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6928,7 +7353,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -6956,7 +7381,7 @@ def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6986,7 +7411,7 @@ def test_delete_operation_rest_bad_request( ) def test_delete_operation_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -7014,7 +7439,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7044,7 +7469,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -7072,7 +7497,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7102,7 +7527,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -7128,7 +7553,7 @@ def test_list_operations_rest(request_type): def test_delete_operation(transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7153,7 +7578,7 @@ def test_delete_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_delete_operation_async(transport: str = "grpc_asyncio"): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7177,7 +7602,7 @@ async def test_delete_operation_async(transport: str = "grpc_asyncio"): def test_delete_operation_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7206,7 +7631,7 @@ def test_delete_operation_field_headers(): @pytest.mark.asyncio async def test_delete_operation_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7233,7 +7658,7 @@ async def test_delete_operation_field_headers_async(): def test_delete_operation_from_dict(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -7251,7 +7676,7 @@ def test_delete_operation_from_dict(): @pytest.mark.asyncio async def test_delete_operation_from_dict_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -7267,7 +7692,7 @@ async def test_delete_operation_from_dict_async(): def test_cancel_operation(transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7292,7 +7717,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7316,7 +7741,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7345,7 +7770,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7372,7 +7797,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7390,7 +7815,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -7406,7 +7831,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7431,7 +7856,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7457,7 +7882,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7486,7 +7911,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7515,7 +7940,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7533,7 +7958,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -7551,7 +7976,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7576,7 +8001,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7602,7 +8027,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7631,7 +8056,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -7660,7 +8085,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7678,7 +8103,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = AttachedClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -7702,7 +8127,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -7719,7 +8144,7 @@ def test_client_ctx(): ] for transport in transports: client = AttachedClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -7750,7 +8175,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, diff --git a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py index 5f03f5b0e2dc..bf28d680ffb2 100644 --- a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py +++ b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_aws_clusters.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -83,6 +83,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -109,6 +132,251 @@ def test__get_default_mtls_endpoint(): assert AwsClustersClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert AwsClustersClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert AwsClustersClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert AwsClustersClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + AwsClustersClient._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 AwsClustersClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert AwsClustersClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert AwsClustersClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + AwsClustersClient._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 AwsClustersClient._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 AwsClustersClient._get_client_cert_source(None, False) is None + assert ( + AwsClustersClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + AwsClustersClient._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 ( + AwsClustersClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + AwsClustersClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + AwsClustersClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AwsClustersClient), +) +@mock.patch.object( + AwsClustersAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AwsClustersAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = AwsClustersClient._DEFAULT_UNIVERSE + default_endpoint = AwsClustersClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AwsClustersClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + AwsClustersClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + AwsClustersClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == AwsClustersClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AwsClustersClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + AwsClustersClient._get_api_endpoint(None, None, default_universe, "always") + == AwsClustersClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AwsClustersClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == AwsClustersClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AwsClustersClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + AwsClustersClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + AwsClustersClient._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 ( + AwsClustersClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + AwsClustersClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + AwsClustersClient._get_universe_domain(None, None) + == AwsClustersClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + AwsClustersClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (AwsClustersClient, transports.AwsClustersGrpcTransport, "grpc"), + (AwsClustersClient, transports.AwsClustersRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -118,7 +386,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_aws_clusters_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -170,7 +438,7 @@ def test_aws_clusters_client_service_account_always_use_jwt( ], ) def test_aws_clusters_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -219,19 +487,23 @@ def test_aws_clusters_client_get_transport_class(): ], ) @mock.patch.object( - AwsClustersClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AwsClustersClient) + AwsClustersClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AwsClustersClient), ) @mock.patch.object( AwsClustersAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AwsClustersAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AwsClustersAsyncClient), ) def test_aws_clusters_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(AwsClustersClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -266,7 +538,9 @@ def test_aws_clusters_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, @@ -296,15 +570,23 @@ def test_aws_clusters_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") @@ -314,7 +596,9 @@ def test_aws_clusters_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", @@ -332,7 +616,9 @@ def test_aws_clusters_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, @@ -364,12 +650,14 @@ def test_aws_clusters_client_client_options( ], ) @mock.patch.object( - AwsClustersClient, "DEFAULT_ENDPOINT", modify_default_endpoint(AwsClustersClient) + AwsClustersClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AwsClustersClient), ) @mock.patch.object( AwsClustersAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AwsClustersAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AwsClustersAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_aws_clusters_client_mtls_env_auto( @@ -392,7 +680,9 @@ def test_aws_clusters_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 @@ -424,7 +714,9 @@ def test_aws_clusters_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 @@ -458,7 +750,9 @@ def test_aws_clusters_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, @@ -544,6 +838,116 @@ def test_aws_clusters_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", [AwsClustersClient, AwsClustersAsyncClient]) +@mock.patch.object( + AwsClustersClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AwsClustersClient), +) +@mock.patch.object( + AwsClustersAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AwsClustersAsyncClient), +) +def test_aws_clusters_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = AwsClustersClient._DEFAULT_UNIVERSE + default_endpoint = AwsClustersClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AwsClustersClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -570,7 +974,9 @@ def test_aws_clusters_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, @@ -605,7 +1011,9 @@ def test_aws_clusters_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, @@ -658,7 +1066,9 @@ def test_aws_clusters_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, @@ -675,8 +1085,8 @@ def test_aws_clusters_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -705,7 +1115,7 @@ def test_aws_clusters_client_create_channel_credentials_file( ) def test_create_aws_cluster(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -734,7 +1144,7 @@ def test_create_aws_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -753,7 +1163,7 @@ async def test_create_aws_cluster_async( transport: str = "grpc_asyncio", request_type=aws_service.CreateAwsClusterRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -787,7 +1197,7 @@ async def test_create_aws_cluster_async_from_dict(): def test_create_aws_cluster_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -819,7 +1229,7 @@ def test_create_aws_cluster_field_headers(): @pytest.mark.asyncio async def test_create_aws_cluster_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -852,7 +1262,7 @@ async def test_create_aws_cluster_field_headers_async(): def test_create_aws_cluster_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -886,7 +1296,7 @@ def test_create_aws_cluster_flattened(): def test_create_aws_cluster_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -903,7 +1313,7 @@ def test_create_aws_cluster_flattened_error(): @pytest.mark.asyncio async def test_create_aws_cluster_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -942,7 +1352,7 @@ async def test_create_aws_cluster_flattened_async(): @pytest.mark.asyncio async def test_create_aws_cluster_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -965,7 +1375,7 @@ async def test_create_aws_cluster_flattened_error_async(): ) def test_update_aws_cluster(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -994,7 +1404,7 @@ def test_update_aws_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1013,7 +1423,7 @@ async def test_update_aws_cluster_async( transport: str = "grpc_asyncio", request_type=aws_service.UpdateAwsClusterRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1047,7 +1457,7 @@ async def test_update_aws_cluster_async_from_dict(): def test_update_aws_cluster_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1079,7 +1489,7 @@ def test_update_aws_cluster_field_headers(): @pytest.mark.asyncio async def test_update_aws_cluster_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1112,7 +1522,7 @@ async def test_update_aws_cluster_field_headers_async(): def test_update_aws_cluster_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1142,7 +1552,7 @@ def test_update_aws_cluster_flattened(): def test_update_aws_cluster_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1158,7 +1568,7 @@ def test_update_aws_cluster_flattened_error(): @pytest.mark.asyncio async def test_update_aws_cluster_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1193,7 +1603,7 @@ async def test_update_aws_cluster_flattened_async(): @pytest.mark.asyncio async def test_update_aws_cluster_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1215,7 +1625,7 @@ async def test_update_aws_cluster_flattened_error_async(): ) def test_get_aws_cluster(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1261,7 +1671,7 @@ def test_get_aws_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1278,7 +1688,7 @@ async def test_get_aws_cluster_async( transport: str = "grpc_asyncio", request_type=aws_service.GetAwsClusterRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1329,7 +1739,7 @@ async def test_get_aws_cluster_async_from_dict(): def test_get_aws_cluster_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1359,7 +1769,7 @@ def test_get_aws_cluster_field_headers(): @pytest.mark.asyncio async def test_get_aws_cluster_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1390,7 +1800,7 @@ async def test_get_aws_cluster_field_headers_async(): def test_get_aws_cluster_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1414,7 +1824,7 @@ def test_get_aws_cluster_flattened(): def test_get_aws_cluster_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1429,7 +1839,7 @@ def test_get_aws_cluster_flattened_error(): @pytest.mark.asyncio async def test_get_aws_cluster_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1458,7 +1868,7 @@ async def test_get_aws_cluster_flattened_async(): @pytest.mark.asyncio async def test_get_aws_cluster_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1479,7 +1889,7 @@ async def test_get_aws_cluster_flattened_error_async(): ) def test_list_aws_clusters(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1511,7 +1921,7 @@ def test_list_aws_clusters_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1530,7 +1940,7 @@ async def test_list_aws_clusters_async( transport: str = "grpc_asyncio", request_type=aws_service.ListAwsClustersRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1567,7 +1977,7 @@ async def test_list_aws_clusters_async_from_dict(): def test_list_aws_clusters_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1599,7 +2009,7 @@ def test_list_aws_clusters_field_headers(): @pytest.mark.asyncio async def test_list_aws_clusters_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1632,7 +2042,7 @@ async def test_list_aws_clusters_field_headers_async(): def test_list_aws_clusters_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1658,7 +2068,7 @@ def test_list_aws_clusters_flattened(): def test_list_aws_clusters_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1673,7 +2083,7 @@ def test_list_aws_clusters_flattened_error(): @pytest.mark.asyncio async def test_list_aws_clusters_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1704,7 +2114,7 @@ async def test_list_aws_clusters_flattened_async(): @pytest.mark.asyncio async def test_list_aws_clusters_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1718,7 +2128,7 @@ async def test_list_aws_clusters_flattened_error_async(): def test_list_aws_clusters_pager(transport_name: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1770,7 +2180,7 @@ def test_list_aws_clusters_pager(transport_name: str = "grpc"): def test_list_aws_clusters_pages(transport_name: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1814,7 +2224,7 @@ def test_list_aws_clusters_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_aws_clusters_async_pager(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1866,7 +2276,7 @@ async def test_list_aws_clusters_async_pager(): @pytest.mark.asyncio async def test_list_aws_clusters_async_pages(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1923,7 +2333,7 @@ async def test_list_aws_clusters_async_pages(): ) def test_delete_aws_cluster(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1952,7 +2362,7 @@ def test_delete_aws_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1971,7 +2381,7 @@ async def test_delete_aws_cluster_async( transport: str = "grpc_asyncio", request_type=aws_service.DeleteAwsClusterRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2005,7 +2415,7 @@ async def test_delete_aws_cluster_async_from_dict(): def test_delete_aws_cluster_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2037,7 +2447,7 @@ def test_delete_aws_cluster_field_headers(): @pytest.mark.asyncio async def test_delete_aws_cluster_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2070,7 +2480,7 @@ async def test_delete_aws_cluster_field_headers_async(): def test_delete_aws_cluster_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2096,7 +2506,7 @@ def test_delete_aws_cluster_flattened(): def test_delete_aws_cluster_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2111,7 +2521,7 @@ def test_delete_aws_cluster_flattened_error(): @pytest.mark.asyncio async def test_delete_aws_cluster_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2142,7 +2552,7 @@ async def test_delete_aws_cluster_flattened_async(): @pytest.mark.asyncio async def test_delete_aws_cluster_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2163,7 +2573,7 @@ async def test_delete_aws_cluster_flattened_error_async(): ) def test_generate_aws_cluster_agent_token(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2199,7 +2609,7 @@ def test_generate_aws_cluster_agent_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2219,7 +2629,7 @@ async def test_generate_aws_cluster_agent_token_async( request_type=aws_service.GenerateAwsClusterAgentTokenRequest, ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2260,7 +2670,7 @@ async def test_generate_aws_cluster_agent_token_async_from_dict(): def test_generate_aws_cluster_agent_token_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2292,7 +2702,7 @@ def test_generate_aws_cluster_agent_token_field_headers(): @pytest.mark.asyncio async def test_generate_aws_cluster_agent_token_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2332,7 +2742,7 @@ async def test_generate_aws_cluster_agent_token_field_headers_async(): ) def test_generate_aws_access_token(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2364,7 +2774,7 @@ def test_generate_aws_access_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2384,7 +2794,7 @@ async def test_generate_aws_access_token_async( request_type=aws_service.GenerateAwsAccessTokenRequest, ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2421,7 +2831,7 @@ async def test_generate_aws_access_token_async_from_dict(): def test_generate_aws_access_token_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2453,7 +2863,7 @@ def test_generate_aws_access_token_field_headers(): @pytest.mark.asyncio async def test_generate_aws_access_token_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2493,7 +2903,7 @@ async def test_generate_aws_access_token_field_headers_async(): ) def test_create_aws_node_pool(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2522,7 +2932,7 @@ def test_create_aws_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2541,7 +2951,7 @@ async def test_create_aws_node_pool_async( transport: str = "grpc_asyncio", request_type=aws_service.CreateAwsNodePoolRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2575,7 +2985,7 @@ async def test_create_aws_node_pool_async_from_dict(): def test_create_aws_node_pool_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2607,7 +3017,7 @@ def test_create_aws_node_pool_field_headers(): @pytest.mark.asyncio async def test_create_aws_node_pool_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2640,7 +3050,7 @@ async def test_create_aws_node_pool_field_headers_async(): def test_create_aws_node_pool_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2674,7 +3084,7 @@ def test_create_aws_node_pool_flattened(): def test_create_aws_node_pool_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2691,7 +3101,7 @@ def test_create_aws_node_pool_flattened_error(): @pytest.mark.asyncio async def test_create_aws_node_pool_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2730,7 +3140,7 @@ async def test_create_aws_node_pool_flattened_async(): @pytest.mark.asyncio async def test_create_aws_node_pool_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2753,7 +3163,7 @@ async def test_create_aws_node_pool_flattened_error_async(): ) def test_update_aws_node_pool(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2782,7 +3192,7 @@ def test_update_aws_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2801,7 +3211,7 @@ async def test_update_aws_node_pool_async( transport: str = "grpc_asyncio", request_type=aws_service.UpdateAwsNodePoolRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2835,7 +3245,7 @@ async def test_update_aws_node_pool_async_from_dict(): def test_update_aws_node_pool_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2867,7 +3277,7 @@ def test_update_aws_node_pool_field_headers(): @pytest.mark.asyncio async def test_update_aws_node_pool_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2900,7 +3310,7 @@ async def test_update_aws_node_pool_field_headers_async(): def test_update_aws_node_pool_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2930,7 +3340,7 @@ def test_update_aws_node_pool_flattened(): def test_update_aws_node_pool_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2946,7 +3356,7 @@ def test_update_aws_node_pool_flattened_error(): @pytest.mark.asyncio async def test_update_aws_node_pool_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2981,7 +3391,7 @@ async def test_update_aws_node_pool_flattened_async(): @pytest.mark.asyncio async def test_update_aws_node_pool_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3003,7 +3413,7 @@ async def test_update_aws_node_pool_flattened_error_async(): ) def test_rollback_aws_node_pool_update(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3032,7 +3442,7 @@ def test_rollback_aws_node_pool_update_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3052,7 +3462,7 @@ async def test_rollback_aws_node_pool_update_async( request_type=aws_service.RollbackAwsNodePoolUpdateRequest, ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3086,7 +3496,7 @@ async def test_rollback_aws_node_pool_update_async_from_dict(): def test_rollback_aws_node_pool_update_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3118,7 +3528,7 @@ def test_rollback_aws_node_pool_update_field_headers(): @pytest.mark.asyncio async def test_rollback_aws_node_pool_update_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3151,7 +3561,7 @@ async def test_rollback_aws_node_pool_update_field_headers_async(): def test_rollback_aws_node_pool_update_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3177,7 +3587,7 @@ def test_rollback_aws_node_pool_update_flattened(): def test_rollback_aws_node_pool_update_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3192,7 +3602,7 @@ def test_rollback_aws_node_pool_update_flattened_error(): @pytest.mark.asyncio async def test_rollback_aws_node_pool_update_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3223,7 +3633,7 @@ async def test_rollback_aws_node_pool_update_flattened_async(): @pytest.mark.asyncio async def test_rollback_aws_node_pool_update_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3244,7 +3654,7 @@ async def test_rollback_aws_node_pool_update_flattened_error_async(): ) def test_get_aws_node_pool(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3288,7 +3698,7 @@ def test_get_aws_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3307,7 +3717,7 @@ async def test_get_aws_node_pool_async( transport: str = "grpc_asyncio", request_type=aws_service.GetAwsNodePoolRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3356,7 +3766,7 @@ async def test_get_aws_node_pool_async_from_dict(): def test_get_aws_node_pool_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3388,7 +3798,7 @@ def test_get_aws_node_pool_field_headers(): @pytest.mark.asyncio async def test_get_aws_node_pool_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3421,7 +3831,7 @@ async def test_get_aws_node_pool_field_headers_async(): def test_get_aws_node_pool_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3447,7 +3857,7 @@ def test_get_aws_node_pool_flattened(): def test_get_aws_node_pool_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3462,7 +3872,7 @@ def test_get_aws_node_pool_flattened_error(): @pytest.mark.asyncio async def test_get_aws_node_pool_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3493,7 +3903,7 @@ async def test_get_aws_node_pool_flattened_async(): @pytest.mark.asyncio async def test_get_aws_node_pool_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3514,7 +3924,7 @@ async def test_get_aws_node_pool_flattened_error_async(): ) def test_list_aws_node_pools(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3546,7 +3956,7 @@ def test_list_aws_node_pools_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3565,7 +3975,7 @@ async def test_list_aws_node_pools_async( transport: str = "grpc_asyncio", request_type=aws_service.ListAwsNodePoolsRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3602,7 +4012,7 @@ async def test_list_aws_node_pools_async_from_dict(): def test_list_aws_node_pools_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3634,7 +4044,7 @@ def test_list_aws_node_pools_field_headers(): @pytest.mark.asyncio async def test_list_aws_node_pools_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3667,7 +4077,7 @@ async def test_list_aws_node_pools_field_headers_async(): def test_list_aws_node_pools_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3693,7 +4103,7 @@ def test_list_aws_node_pools_flattened(): def test_list_aws_node_pools_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3708,7 +4118,7 @@ def test_list_aws_node_pools_flattened_error(): @pytest.mark.asyncio async def test_list_aws_node_pools_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3739,7 +4149,7 @@ async def test_list_aws_node_pools_flattened_async(): @pytest.mark.asyncio async def test_list_aws_node_pools_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3753,7 +4163,7 @@ async def test_list_aws_node_pools_flattened_error_async(): def test_list_aws_node_pools_pager(transport_name: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3805,7 +4215,7 @@ def test_list_aws_node_pools_pager(transport_name: str = "grpc"): def test_list_aws_node_pools_pages(transport_name: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3849,7 +4259,7 @@ def test_list_aws_node_pools_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_aws_node_pools_async_pager(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3901,7 +4311,7 @@ async def test_list_aws_node_pools_async_pager(): @pytest.mark.asyncio async def test_list_aws_node_pools_async_pages(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3958,7 +4368,7 @@ async def test_list_aws_node_pools_async_pages(): ) def test_delete_aws_node_pool(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3987,7 +4397,7 @@ def test_delete_aws_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4006,7 +4416,7 @@ async def test_delete_aws_node_pool_async( transport: str = "grpc_asyncio", request_type=aws_service.DeleteAwsNodePoolRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4040,7 +4450,7 @@ async def test_delete_aws_node_pool_async_from_dict(): def test_delete_aws_node_pool_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4072,7 +4482,7 @@ def test_delete_aws_node_pool_field_headers(): @pytest.mark.asyncio async def test_delete_aws_node_pool_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4105,7 +4515,7 @@ async def test_delete_aws_node_pool_field_headers_async(): def test_delete_aws_node_pool_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4131,7 +4541,7 @@ def test_delete_aws_node_pool_flattened(): def test_delete_aws_node_pool_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4146,7 +4556,7 @@ def test_delete_aws_node_pool_flattened_error(): @pytest.mark.asyncio async def test_delete_aws_node_pool_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4177,7 +4587,7 @@ async def test_delete_aws_node_pool_flattened_async(): @pytest.mark.asyncio async def test_delete_aws_node_pool_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4198,7 +4608,7 @@ async def test_delete_aws_node_pool_flattened_error_async(): ) def test_get_aws_open_id_config(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4246,7 +4656,7 @@ def test_get_aws_open_id_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4265,7 +4675,7 @@ async def test_get_aws_open_id_config_async( transport: str = "grpc_asyncio", request_type=aws_service.GetAwsOpenIdConfigRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4318,7 +4728,7 @@ async def test_get_aws_open_id_config_async_from_dict(): def test_get_aws_open_id_config_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4350,7 +4760,7 @@ def test_get_aws_open_id_config_field_headers(): @pytest.mark.asyncio async def test_get_aws_open_id_config_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4390,7 +4800,7 @@ async def test_get_aws_open_id_config_field_headers_async(): ) def test_get_aws_json_web_keys(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4419,7 +4829,7 @@ def test_get_aws_json_web_keys_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4438,7 +4848,7 @@ async def test_get_aws_json_web_keys_async( transport: str = "grpc_asyncio", request_type=aws_service.GetAwsJsonWebKeysRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4472,7 +4882,7 @@ async def test_get_aws_json_web_keys_async_from_dict(): def test_get_aws_json_web_keys_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4504,7 +4914,7 @@ def test_get_aws_json_web_keys_field_headers(): @pytest.mark.asyncio async def test_get_aws_json_web_keys_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4544,7 +4954,7 @@ async def test_get_aws_json_web_keys_field_headers_async(): ) def test_get_aws_server_config(request_type, transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4578,7 +4988,7 @@ def test_get_aws_server_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4597,7 +5007,7 @@ async def test_get_aws_server_config_async( transport: str = "grpc_asyncio", request_type=aws_service.GetAwsServerConfigRequest ): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4636,7 +5046,7 @@ async def test_get_aws_server_config_async_from_dict(): def test_get_aws_server_config_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4668,7 +5078,7 @@ def test_get_aws_server_config_field_headers(): @pytest.mark.asyncio async def test_get_aws_server_config_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4701,7 +5111,7 @@ async def test_get_aws_server_config_field_headers_async(): def test_get_aws_server_config_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4727,7 +5137,7 @@ def test_get_aws_server_config_flattened(): def test_get_aws_server_config_flattened_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4742,7 +5152,7 @@ def test_get_aws_server_config_flattened_error(): @pytest.mark.asyncio async def test_get_aws_server_config_flattened_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4773,7 +5183,7 @@ async def test_get_aws_server_config_flattened_async(): @pytest.mark.asyncio async def test_get_aws_server_config_flattened_error_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4794,7 +5204,7 @@ async def test_get_aws_server_config_flattened_error_async(): ) def test_create_aws_cluster_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4980,7 +5390,7 @@ def test_create_aws_cluster_rest_required_fields( assert "awsClusterId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_aws_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4992,7 +5402,7 @@ def test_create_aws_cluster_rest_required_fields( jsonified_request["awsClusterId"] = "aws_cluster_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_aws_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5010,7 +5420,7 @@ def test_create_aws_cluster_rest_required_fields( assert jsonified_request["awsClusterId"] == "aws_cluster_id_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5055,7 +5465,7 @@ def test_create_aws_cluster_rest_required_fields( def test_create_aws_cluster_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_aws_cluster._get_unset_required_fields({}) @@ -5079,7 +5489,7 @@ def test_create_aws_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_aws_cluster_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -5139,7 +5549,7 @@ def test_create_aws_cluster_rest_bad_request( transport: str = "rest", request_type=aws_service.CreateAwsClusterRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5161,7 +5571,7 @@ def test_create_aws_cluster_rest_bad_request( def test_create_aws_cluster_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5203,7 +5613,7 @@ def test_create_aws_cluster_rest_flattened(): def test_create_aws_cluster_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5220,7 +5630,7 @@ def test_create_aws_cluster_rest_flattened_error(transport: str = "rest"): def test_create_aws_cluster_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5233,7 +5643,7 @@ def test_create_aws_cluster_rest_error(): ) def test_update_aws_cluster_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5420,14 +5830,14 @@ def test_update_aws_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_aws_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_aws_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -5441,7 +5851,7 @@ def test_update_aws_cluster_rest_required_fields( # verify required fields with non-default values are left alone client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5481,7 +5891,7 @@ def test_update_aws_cluster_rest_required_fields( def test_update_aws_cluster_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_aws_cluster._get_unset_required_fields({}) @@ -5504,7 +5914,7 @@ def test_update_aws_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_aws_cluster_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -5564,7 +5974,7 @@ def test_update_aws_cluster_rest_bad_request( transport: str = "rest", request_type=aws_service.UpdateAwsClusterRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5590,7 +6000,7 @@ def test_update_aws_cluster_rest_bad_request( def test_update_aws_cluster_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5635,7 +6045,7 @@ def test_update_aws_cluster_rest_flattened(): def test_update_aws_cluster_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5651,7 +6061,7 @@ def test_update_aws_cluster_rest_flattened_error(transport: str = "rest"): def test_update_aws_cluster_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5664,7 +6074,7 @@ def test_update_aws_cluster_rest_error(): ) def test_get_aws_cluster_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5731,7 +6141,7 @@ def test_get_aws_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5740,7 +6150,7 @@ def test_get_aws_cluster_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5749,7 +6159,7 @@ def test_get_aws_cluster_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5791,7 +6201,7 @@ def test_get_aws_cluster_rest_required_fields( def test_get_aws_cluster_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_aws_cluster._get_unset_required_fields({}) @@ -5801,7 +6211,7 @@ def test_get_aws_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_aws_cluster_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -5859,7 +6269,7 @@ def test_get_aws_cluster_rest_bad_request( transport: str = "rest", request_type=aws_service.GetAwsClusterRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5881,7 +6291,7 @@ def test_get_aws_cluster_rest_bad_request( def test_get_aws_cluster_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5925,7 +6335,7 @@ def test_get_aws_cluster_rest_flattened(): def test_get_aws_cluster_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5940,7 +6350,7 @@ def test_get_aws_cluster_rest_flattened_error(transport: str = "rest"): def test_get_aws_cluster_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5953,7 +6363,7 @@ def test_get_aws_cluster_rest_error(): ) def test_list_aws_clusters_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6004,7 +6414,7 @@ def test_list_aws_clusters_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_aws_clusters._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6013,7 +6423,7 @@ def test_list_aws_clusters_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_aws_clusters._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6029,7 +6439,7 @@ def test_list_aws_clusters_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6071,7 +6481,7 @@ def test_list_aws_clusters_rest_required_fields( def test_list_aws_clusters_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_aws_clusters._get_unset_required_fields({}) @@ -6089,7 +6499,7 @@ def test_list_aws_clusters_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_aws_clusters_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -6147,7 +6557,7 @@ def test_list_aws_clusters_rest_bad_request( transport: str = "rest", request_type=aws_service.ListAwsClustersRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6169,7 +6579,7 @@ def test_list_aws_clusters_rest_bad_request( def test_list_aws_clusters_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6211,7 +6621,7 @@ def test_list_aws_clusters_rest_flattened(): def test_list_aws_clusters_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6226,7 +6636,7 @@ def test_list_aws_clusters_rest_flattened_error(transport: str = "rest"): def test_list_aws_clusters_rest_pager(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6296,7 +6706,7 @@ def test_list_aws_clusters_rest_pager(transport: str = "rest"): ) def test_delete_aws_cluster_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6342,7 +6752,7 @@ def test_delete_aws_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_aws_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6351,7 +6761,7 @@ def test_delete_aws_cluster_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_aws_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6369,7 +6779,7 @@ def test_delete_aws_cluster_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6408,7 +6818,7 @@ def test_delete_aws_cluster_rest_required_fields( def test_delete_aws_cluster_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_aws_cluster._get_unset_required_fields({}) @@ -6428,7 +6838,7 @@ def test_delete_aws_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_aws_cluster_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -6488,7 +6898,7 @@ def test_delete_aws_cluster_rest_bad_request( transport: str = "rest", request_type=aws_service.DeleteAwsClusterRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6510,7 +6920,7 @@ def test_delete_aws_cluster_rest_bad_request( def test_delete_aws_cluster_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6552,7 +6962,7 @@ def test_delete_aws_cluster_rest_flattened(): def test_delete_aws_cluster_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6567,7 +6977,7 @@ def test_delete_aws_cluster_rest_flattened_error(transport: str = "rest"): def test_delete_aws_cluster_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6580,7 +6990,7 @@ def test_delete_aws_cluster_rest_error(): ) def test_generate_aws_cluster_agent_token_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6640,7 +7050,7 @@ def test_generate_aws_cluster_agent_token_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_aws_cluster_agent_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6652,7 +7062,7 @@ def test_generate_aws_cluster_agent_token_rest_required_fields( jsonified_request["version"] = "version_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_aws_cluster_agent_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6667,7 +7077,7 @@ def test_generate_aws_cluster_agent_token_rest_required_fields( assert jsonified_request["version"] == "version_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6712,7 +7122,7 @@ def test_generate_aws_cluster_agent_token_rest_required_fields( def test_generate_aws_cluster_agent_token_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -6734,7 +7144,7 @@ def test_generate_aws_cluster_agent_token_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_aws_cluster_agent_token_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -6795,7 +7205,7 @@ def test_generate_aws_cluster_agent_token_rest_bad_request( request_type=aws_service.GenerateAwsClusterAgentTokenRequest, ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6819,7 +7229,7 @@ def test_generate_aws_cluster_agent_token_rest_bad_request( def test_generate_aws_cluster_agent_token_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6832,7 +7242,7 @@ def test_generate_aws_cluster_agent_token_rest_error(): ) def test_generate_aws_access_token_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6885,7 +7295,7 @@ def test_generate_aws_access_token_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_aws_access_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6894,7 +7304,7 @@ def test_generate_aws_access_token_rest_required_fields( jsonified_request["awsCluster"] = "aws_cluster_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_aws_access_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6903,7 +7313,7 @@ def test_generate_aws_access_token_rest_required_fields( assert jsonified_request["awsCluster"] == "aws_cluster_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6945,7 +7355,7 @@ def test_generate_aws_access_token_rest_required_fields( def test_generate_aws_access_token_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_aws_access_token._get_unset_required_fields({}) @@ -6955,7 +7365,7 @@ def test_generate_aws_access_token_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_aws_access_token_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -7013,7 +7423,7 @@ def test_generate_aws_access_token_rest_bad_request( transport: str = "rest", request_type=aws_service.GenerateAwsAccessTokenRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7037,7 +7447,7 @@ def test_generate_aws_access_token_rest_bad_request( def test_generate_aws_access_token_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7050,7 +7460,7 @@ def test_generate_aws_access_token_rest_error(): ) def test_create_aws_node_pool_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7217,7 +7627,7 @@ def test_create_aws_node_pool_rest_required_fields( assert "awsNodePoolId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_aws_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7229,7 +7639,7 @@ def test_create_aws_node_pool_rest_required_fields( jsonified_request["awsNodePoolId"] = "aws_node_pool_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_aws_node_pool._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7247,7 +7657,7 @@ def test_create_aws_node_pool_rest_required_fields( assert jsonified_request["awsNodePoolId"] == "aws_node_pool_id_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7292,7 +7702,7 @@ def test_create_aws_node_pool_rest_required_fields( def test_create_aws_node_pool_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_aws_node_pool._get_unset_required_fields({}) @@ -7316,7 +7726,7 @@ def test_create_aws_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_aws_node_pool_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -7376,7 +7786,7 @@ def test_create_aws_node_pool_rest_bad_request( transport: str = "rest", request_type=aws_service.CreateAwsNodePoolRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7398,7 +7808,7 @@ def test_create_aws_node_pool_rest_bad_request( def test_create_aws_node_pool_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7442,7 +7852,7 @@ def test_create_aws_node_pool_rest_flattened(): def test_create_aws_node_pool_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7459,7 +7869,7 @@ def test_create_aws_node_pool_rest_flattened_error(transport: str = "rest"): def test_create_aws_node_pool_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7472,7 +7882,7 @@ def test_create_aws_node_pool_rest_error(): ) def test_update_aws_node_pool_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7640,14 +8050,14 @@ def test_update_aws_node_pool_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_aws_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_aws_node_pool._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7661,7 +8071,7 @@ def test_update_aws_node_pool_rest_required_fields( # verify required fields with non-default values are left alone client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7701,7 +8111,7 @@ def test_update_aws_node_pool_rest_required_fields( def test_update_aws_node_pool_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_aws_node_pool._get_unset_required_fields({}) @@ -7724,7 +8134,7 @@ def test_update_aws_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_aws_node_pool_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -7784,7 +8194,7 @@ def test_update_aws_node_pool_rest_bad_request( transport: str = "rest", request_type=aws_service.UpdateAwsNodePoolRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7810,7 +8220,7 @@ def test_update_aws_node_pool_rest_bad_request( def test_update_aws_node_pool_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7855,7 +8265,7 @@ def test_update_aws_node_pool_rest_flattened(): def test_update_aws_node_pool_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7871,7 +8281,7 @@ def test_update_aws_node_pool_rest_flattened_error(transport: str = "rest"): def test_update_aws_node_pool_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7884,7 +8294,7 @@ def test_update_aws_node_pool_rest_error(): ) def test_rollback_aws_node_pool_update_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7932,7 +8342,7 @@ def test_rollback_aws_node_pool_update_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).rollback_aws_node_pool_update._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7941,7 +8351,7 @@ def test_rollback_aws_node_pool_update_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).rollback_aws_node_pool_update._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7950,7 +8360,7 @@ def test_rollback_aws_node_pool_update_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7990,7 +8400,7 @@ def test_rollback_aws_node_pool_update_rest_required_fields( def test_rollback_aws_node_pool_update_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.rollback_aws_node_pool_update._get_unset_required_fields( @@ -8002,7 +8412,7 @@ def test_rollback_aws_node_pool_update_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_rollback_aws_node_pool_update_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -8062,7 +8472,7 @@ def test_rollback_aws_node_pool_update_rest_bad_request( transport: str = "rest", request_type=aws_service.RollbackAwsNodePoolUpdateRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8086,7 +8496,7 @@ def test_rollback_aws_node_pool_update_rest_bad_request( def test_rollback_aws_node_pool_update_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8128,7 +8538,7 @@ def test_rollback_aws_node_pool_update_rest_flattened(): def test_rollback_aws_node_pool_update_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8143,7 +8553,7 @@ def test_rollback_aws_node_pool_update_rest_flattened_error(transport: str = "re def test_rollback_aws_node_pool_update_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8156,7 +8566,7 @@ def test_rollback_aws_node_pool_update_rest_error(): ) def test_get_aws_node_pool_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8221,7 +8631,7 @@ def test_get_aws_node_pool_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8230,7 +8640,7 @@ def test_get_aws_node_pool_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8239,7 +8649,7 @@ def test_get_aws_node_pool_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8281,7 +8691,7 @@ def test_get_aws_node_pool_rest_required_fields( def test_get_aws_node_pool_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_aws_node_pool._get_unset_required_fields({}) @@ -8291,7 +8701,7 @@ def test_get_aws_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_aws_node_pool_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -8349,7 +8759,7 @@ def test_get_aws_node_pool_rest_bad_request( transport: str = "rest", request_type=aws_service.GetAwsNodePoolRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8373,7 +8783,7 @@ def test_get_aws_node_pool_rest_bad_request( def test_get_aws_node_pool_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8417,7 +8827,7 @@ def test_get_aws_node_pool_rest_flattened(): def test_get_aws_node_pool_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8432,7 +8842,7 @@ def test_get_aws_node_pool_rest_flattened_error(transport: str = "rest"): def test_get_aws_node_pool_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8445,7 +8855,7 @@ def test_get_aws_node_pool_rest_error(): ) def test_list_aws_node_pools_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8496,7 +8906,7 @@ def test_list_aws_node_pools_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_aws_node_pools._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8505,7 +8915,7 @@ def test_list_aws_node_pools_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_aws_node_pools._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8521,7 +8931,7 @@ def test_list_aws_node_pools_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8563,7 +8973,7 @@ def test_list_aws_node_pools_rest_required_fields( def test_list_aws_node_pools_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_aws_node_pools._get_unset_required_fields({}) @@ -8581,7 +8991,7 @@ def test_list_aws_node_pools_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_aws_node_pools_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -8639,7 +9049,7 @@ def test_list_aws_node_pools_rest_bad_request( transport: str = "rest", request_type=aws_service.ListAwsNodePoolsRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8661,7 +9071,7 @@ def test_list_aws_node_pools_rest_bad_request( def test_list_aws_node_pools_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8705,7 +9115,7 @@ def test_list_aws_node_pools_rest_flattened(): def test_list_aws_node_pools_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8720,7 +9130,7 @@ def test_list_aws_node_pools_rest_flattened_error(transport: str = "rest"): def test_list_aws_node_pools_rest_pager(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8792,7 +9202,7 @@ def test_list_aws_node_pools_rest_pager(transport: str = "rest"): ) def test_delete_aws_node_pool_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8840,7 +9250,7 @@ def test_delete_aws_node_pool_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_aws_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8849,7 +9259,7 @@ def test_delete_aws_node_pool_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_aws_node_pool._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8867,7 +9277,7 @@ def test_delete_aws_node_pool_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8906,7 +9316,7 @@ def test_delete_aws_node_pool_rest_required_fields( def test_delete_aws_node_pool_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_aws_node_pool._get_unset_required_fields({}) @@ -8926,7 +9336,7 @@ def test_delete_aws_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_aws_node_pool_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -8986,7 +9396,7 @@ def test_delete_aws_node_pool_rest_bad_request( transport: str = "rest", request_type=aws_service.DeleteAwsNodePoolRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9010,7 +9420,7 @@ def test_delete_aws_node_pool_rest_bad_request( def test_delete_aws_node_pool_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9052,7 +9462,7 @@ def test_delete_aws_node_pool_rest_flattened(): def test_delete_aws_node_pool_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9067,7 +9477,7 @@ def test_delete_aws_node_pool_rest_flattened_error(transport: str = "rest"): def test_delete_aws_node_pool_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9080,7 +9490,7 @@ def test_delete_aws_node_pool_rest_error(): ) def test_get_aws_open_id_config_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9149,7 +9559,7 @@ def test_get_aws_open_id_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_open_id_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9158,7 +9568,7 @@ def test_get_aws_open_id_config_rest_required_fields( jsonified_request["awsCluster"] = "aws_cluster_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_open_id_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9167,7 +9577,7 @@ def test_get_aws_open_id_config_rest_required_fields( assert jsonified_request["awsCluster"] == "aws_cluster_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9209,7 +9619,7 @@ def test_get_aws_open_id_config_rest_required_fields( def test_get_aws_open_id_config_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_aws_open_id_config._get_unset_required_fields({}) @@ -9219,7 +9629,7 @@ def test_get_aws_open_id_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_aws_open_id_config_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -9277,7 +9687,7 @@ def test_get_aws_open_id_config_rest_bad_request( transport: str = "rest", request_type=aws_service.GetAwsOpenIdConfigRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9301,7 +9711,7 @@ def test_get_aws_open_id_config_rest_bad_request( def test_get_aws_open_id_config_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9314,7 +9724,7 @@ def test_get_aws_open_id_config_rest_error(): ) def test_get_aws_json_web_keys_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9364,7 +9774,7 @@ def test_get_aws_json_web_keys_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_json_web_keys._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9373,7 +9783,7 @@ def test_get_aws_json_web_keys_rest_required_fields( jsonified_request["awsCluster"] = "aws_cluster_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_json_web_keys._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9382,7 +9792,7 @@ def test_get_aws_json_web_keys_rest_required_fields( assert jsonified_request["awsCluster"] == "aws_cluster_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9424,7 +9834,7 @@ def test_get_aws_json_web_keys_rest_required_fields( def test_get_aws_json_web_keys_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_aws_json_web_keys._get_unset_required_fields({}) @@ -9434,7 +9844,7 @@ def test_get_aws_json_web_keys_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_aws_json_web_keys_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -9492,7 +9902,7 @@ def test_get_aws_json_web_keys_rest_bad_request( transport: str = "rest", request_type=aws_service.GetAwsJsonWebKeysRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9516,7 +9926,7 @@ def test_get_aws_json_web_keys_rest_bad_request( def test_get_aws_json_web_keys_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9529,7 +9939,7 @@ def test_get_aws_json_web_keys_rest_error(): ) def test_get_aws_server_config_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9582,7 +9992,7 @@ def test_get_aws_server_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_server_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9591,7 +10001,7 @@ def test_get_aws_server_config_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_aws_server_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9600,7 +10010,7 @@ def test_get_aws_server_config_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9642,7 +10052,7 @@ def test_get_aws_server_config_rest_required_fields( def test_get_aws_server_config_rest_unset_required_fields(): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_aws_server_config._get_unset_required_fields({}) @@ -9652,7 +10062,7 @@ def test_get_aws_server_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_aws_server_config_rest_interceptors(null_interceptor): transport = transports.AwsClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AwsClustersRestInterceptor(), @@ -9710,7 +10120,7 @@ def test_get_aws_server_config_rest_bad_request( transport: str = "rest", request_type=aws_service.GetAwsServerConfigRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9732,7 +10142,7 @@ def test_get_aws_server_config_rest_bad_request( def test_get_aws_server_config_rest_flattened(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9774,7 +10184,7 @@ def test_get_aws_server_config_rest_flattened(): def test_get_aws_server_config_rest_flattened_error(transport: str = "rest"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9789,24 +10199,24 @@ def test_get_aws_server_config_rest_flattened_error(transport: str = "rest"): def test_get_aws_server_config_rest_error(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AwsClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.AwsClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AwsClustersClient( @@ -9816,7 +10226,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.AwsClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -9827,16 +10237,17 @@ 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 = AwsClustersClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.AwsClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AwsClustersClient( @@ -9848,7 +10259,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AwsClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = AwsClustersClient(transport=transport) assert client.transport is transport @@ -9857,13 +10268,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AwsClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.AwsClustersGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -9880,7 +10291,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -9894,7 +10305,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = AwsClustersClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -9902,7 +10313,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -9914,7 +10325,7 @@ def test_aws_clusters_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.AwsClustersTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -9926,7 +10337,7 @@ def test_aws_clusters_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AwsClustersTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -9982,7 +10393,7 @@ def test_aws_clusters_base_transport_with_credentials_file(): "google.cloud.gke_multicloud_v1.services.aws_clusters.transports.AwsClustersTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AwsClustersTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -10001,7 +10412,7 @@ def test_aws_clusters_base_transport_with_adc(): "google.cloud.gke_multicloud_v1.services.aws_clusters.transports.AwsClustersTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AwsClustersTransport() adc.assert_called_once() @@ -10009,7 +10420,7 @@ def test_aws_clusters_base_transport_with_adc(): def test_aws_clusters_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) AwsClustersClient() adc.assert_called_once_with( scopes=None, @@ -10029,7 +10440,7 @@ def test_aws_clusters_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -10076,7 +10487,7 @@ def test_aws_clusters_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -10101,7 +10512,7 @@ def test_aws_clusters_transport_create_channel(transport_class, grpc_helpers): [transports.AwsClustersGrpcTransport, transports.AwsClustersGrpcAsyncIOTransport], ) def test_aws_clusters_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -10139,7 +10550,7 @@ def test_aws_clusters_grpc_transport_client_cert_source_for_mtls(transport_class def test_aws_clusters_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -10151,7 +10562,7 @@ def test_aws_clusters_http_transport_client_cert_source_for_mtls(): def test_aws_clusters_rest_lro_client(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -10176,7 +10587,7 @@ def test_aws_clusters_rest_lro_client(): ) def test_aws_clusters_host_no_port(transport_name): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkemulticloud.googleapis.com" ), @@ -10199,7 +10610,7 @@ def test_aws_clusters_host_no_port(transport_name): ) def test_aws_clusters_host_with_port(transport_name): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkemulticloud.googleapis.com:8000" ), @@ -10219,8 +10630,8 @@ def test_aws_clusters_host_with_port(transport_name): ], ) def test_aws_clusters_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = AwsClustersClient( credentials=creds1, transport=transport_name, @@ -10324,7 +10735,7 @@ def test_aws_clusters_transport_channel_mtls_with_client_cert_source(transport_c mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -10399,7 +10810,7 @@ def test_aws_clusters_transport_channel_mtls_with_adc(transport_class): def test_aws_clusters_grpc_lro_client(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -10416,7 +10827,7 @@ def test_aws_clusters_grpc_lro_client(): def test_aws_clusters_grpc_lro_async_client(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -10623,7 +11034,7 @@ def test_client_with_default_client_info(): transports.AwsClustersTransport, "_prep_wrapped_messages" ) as prep: client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -10633,7 +11044,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = AwsClustersClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -10642,7 +11053,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -10657,7 +11068,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10687,7 +11098,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -10715,7 +11126,7 @@ def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10745,7 +11156,7 @@ def test_delete_operation_rest_bad_request( ) def test_delete_operation_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -10773,7 +11184,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10803,7 +11214,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -10831,7 +11242,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10861,7 +11272,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -10887,7 +11298,7 @@ def test_list_operations_rest(request_type): def test_delete_operation(transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10912,7 +11323,7 @@ def test_delete_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_delete_operation_async(transport: str = "grpc_asyncio"): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10936,7 +11347,7 @@ async def test_delete_operation_async(transport: str = "grpc_asyncio"): def test_delete_operation_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10965,7 +11376,7 @@ def test_delete_operation_field_headers(): @pytest.mark.asyncio async def test_delete_operation_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -10992,7 +11403,7 @@ async def test_delete_operation_field_headers_async(): def test_delete_operation_from_dict(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -11010,7 +11421,7 @@ def test_delete_operation_from_dict(): @pytest.mark.asyncio async def test_delete_operation_from_dict_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -11026,7 +11437,7 @@ async def test_delete_operation_from_dict_async(): def test_cancel_operation(transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11051,7 +11462,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11075,7 +11486,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11104,7 +11515,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11131,7 +11542,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -11149,7 +11560,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -11165,7 +11576,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11190,7 +11601,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11216,7 +11627,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11245,7 +11656,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11274,7 +11685,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -11292,7 +11703,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -11310,7 +11721,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11335,7 +11746,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11361,7 +11772,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11390,7 +11801,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -11419,7 +11830,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -11437,7 +11848,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = AwsClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -11461,7 +11872,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -11478,7 +11889,7 @@ def test_client_ctx(): ] for transport in transports: client = AwsClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -11509,7 +11920,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, diff --git a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py index 40b161bad45f..f356b4c56585 100644 --- a/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py +++ b/packages/google-cloud-gke-multicloud/tests/unit/gapic/gke_multicloud_v1/test_azure_clusters.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -83,6 +83,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -112,6 +135,263 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert AzureClustersClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert AzureClustersClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert AzureClustersClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + AzureClustersClient._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 AzureClustersClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert AzureClustersClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert AzureClustersClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + AzureClustersClient._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 AzureClustersClient._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 AzureClustersClient._get_client_cert_source(None, False) is None + assert ( + AzureClustersClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + AzureClustersClient._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 ( + AzureClustersClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + AzureClustersClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + AzureClustersClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AzureClustersClient), +) +@mock.patch.object( + AzureClustersAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AzureClustersAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = AzureClustersClient._DEFAULT_UNIVERSE + default_endpoint = AzureClustersClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AzureClustersClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + AzureClustersClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + AzureClustersClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == AzureClustersClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AzureClustersClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + AzureClustersClient._get_api_endpoint(None, None, default_universe, "always") + == AzureClustersClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AzureClustersClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == AzureClustersClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + AzureClustersClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + AzureClustersClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + AzureClustersClient._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 ( + AzureClustersClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + AzureClustersClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + AzureClustersClient._get_universe_domain(None, None) + == AzureClustersClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + AzureClustersClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (AzureClustersClient, transports.AzureClustersGrpcTransport, "grpc"), + (AzureClustersClient, transports.AzureClustersRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -121,7 +401,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_azure_clusters_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -173,7 +453,7 @@ def test_azure_clusters_client_service_account_always_use_jwt( ], ) def test_azure_clusters_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -223,20 +503,22 @@ def test_azure_clusters_client_get_transport_class(): ) @mock.patch.object( AzureClustersClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AzureClustersClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AzureClustersClient), ) @mock.patch.object( AzureClustersAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AzureClustersAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AzureClustersAsyncClient), ) def test_azure_clusters_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(AzureClustersClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -271,7 +553,9 @@ def test_azure_clusters_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, @@ -301,15 +585,23 @@ def test_azure_clusters_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") @@ -319,7 +611,9 @@ def test_azure_clusters_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", @@ -337,7 +631,9 @@ def test_azure_clusters_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, @@ -370,13 +666,13 @@ def test_azure_clusters_client_client_options( ) @mock.patch.object( AzureClustersClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AzureClustersClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AzureClustersClient), ) @mock.patch.object( AzureClustersAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(AzureClustersAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AzureClustersAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_azure_clusters_client_mtls_env_auto( @@ -399,7 +695,9 @@ def test_azure_clusters_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 @@ -431,7 +729,9 @@ def test_azure_clusters_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 @@ -465,7 +765,9 @@ def test_azure_clusters_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, @@ -555,6 +857,118 @@ def test_azure_clusters_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", [AzureClustersClient, AzureClustersAsyncClient] +) +@mock.patch.object( + AzureClustersClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AzureClustersClient), +) +@mock.patch.object( + AzureClustersAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(AzureClustersAsyncClient), +) +def test_azure_clusters_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = AzureClustersClient._DEFAULT_UNIVERSE + default_endpoint = AzureClustersClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = AzureClustersClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -581,7 +995,9 @@ def test_azure_clusters_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, @@ -621,7 +1037,9 @@ def test_azure_clusters_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, @@ -681,7 +1099,9 @@ def test_azure_clusters_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, @@ -698,8 +1118,8 @@ def test_azure_clusters_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -728,7 +1148,7 @@ def test_azure_clusters_client_create_channel_credentials_file( ) def test_create_azure_client(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -757,7 +1177,7 @@ def test_create_azure_client_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -776,7 +1196,7 @@ async def test_create_azure_client_async( transport: str = "grpc_asyncio", request_type=azure_service.CreateAzureClientRequest ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -810,7 +1230,7 @@ async def test_create_azure_client_async_from_dict(): def test_create_azure_client_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -842,7 +1262,7 @@ def test_create_azure_client_field_headers(): @pytest.mark.asyncio async def test_create_azure_client_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -875,7 +1295,7 @@ async def test_create_azure_client_field_headers_async(): def test_create_azure_client_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -909,7 +1329,7 @@ def test_create_azure_client_flattened(): def test_create_azure_client_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -926,7 +1346,7 @@ def test_create_azure_client_flattened_error(): @pytest.mark.asyncio async def test_create_azure_client_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -965,7 +1385,7 @@ async def test_create_azure_client_flattened_async(): @pytest.mark.asyncio async def test_create_azure_client_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -988,7 +1408,7 @@ async def test_create_azure_client_flattened_error_async(): ) def test_get_azure_client(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1028,7 +1448,7 @@ def test_get_azure_client_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1045,7 +1465,7 @@ async def test_get_azure_client_async( transport: str = "grpc_asyncio", request_type=azure_service.GetAzureClientRequest ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1090,7 +1510,7 @@ async def test_get_azure_client_async_from_dict(): def test_get_azure_client_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1120,7 +1540,7 @@ def test_get_azure_client_field_headers(): @pytest.mark.asyncio async def test_get_azure_client_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1151,7 +1571,7 @@ async def test_get_azure_client_field_headers_async(): def test_get_azure_client_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1175,7 +1595,7 @@ def test_get_azure_client_flattened(): def test_get_azure_client_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1190,7 +1610,7 @@ def test_get_azure_client_flattened_error(): @pytest.mark.asyncio async def test_get_azure_client_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1219,7 +1639,7 @@ async def test_get_azure_client_flattened_async(): @pytest.mark.asyncio async def test_get_azure_client_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1240,7 +1660,7 @@ async def test_get_azure_client_flattened_error_async(): ) def test_list_azure_clients(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1272,7 +1692,7 @@ def test_list_azure_clients_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1291,7 +1711,7 @@ async def test_list_azure_clients_async( transport: str = "grpc_asyncio", request_type=azure_service.ListAzureClientsRequest ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1328,7 +1748,7 @@ async def test_list_azure_clients_async_from_dict(): def test_list_azure_clients_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1360,7 +1780,7 @@ def test_list_azure_clients_field_headers(): @pytest.mark.asyncio async def test_list_azure_clients_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1393,7 +1813,7 @@ async def test_list_azure_clients_field_headers_async(): def test_list_azure_clients_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1419,7 +1839,7 @@ def test_list_azure_clients_flattened(): def test_list_azure_clients_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1434,7 +1854,7 @@ def test_list_azure_clients_flattened_error(): @pytest.mark.asyncio async def test_list_azure_clients_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1465,7 +1885,7 @@ async def test_list_azure_clients_flattened_async(): @pytest.mark.asyncio async def test_list_azure_clients_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1479,7 +1899,7 @@ async def test_list_azure_clients_flattened_error_async(): def test_list_azure_clients_pager(transport_name: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1531,7 +1951,7 @@ def test_list_azure_clients_pager(transport_name: str = "grpc"): def test_list_azure_clients_pages(transport_name: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1575,7 +1995,7 @@ def test_list_azure_clients_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_azure_clients_async_pager(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1627,7 +2047,7 @@ async def test_list_azure_clients_async_pager(): @pytest.mark.asyncio async def test_list_azure_clients_async_pages(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1684,7 +2104,7 @@ async def test_list_azure_clients_async_pages(): ) def test_delete_azure_client(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1713,7 +2133,7 @@ def test_delete_azure_client_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1732,7 +2152,7 @@ async def test_delete_azure_client_async( transport: str = "grpc_asyncio", request_type=azure_service.DeleteAzureClientRequest ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1766,7 +2186,7 @@ async def test_delete_azure_client_async_from_dict(): def test_delete_azure_client_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1798,7 +2218,7 @@ def test_delete_azure_client_field_headers(): @pytest.mark.asyncio async def test_delete_azure_client_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1831,7 +2251,7 @@ async def test_delete_azure_client_field_headers_async(): def test_delete_azure_client_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1857,7 +2277,7 @@ def test_delete_azure_client_flattened(): def test_delete_azure_client_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1872,7 +2292,7 @@ def test_delete_azure_client_flattened_error(): @pytest.mark.asyncio async def test_delete_azure_client_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1903,7 +2323,7 @@ async def test_delete_azure_client_flattened_async(): @pytest.mark.asyncio async def test_delete_azure_client_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1924,7 +2344,7 @@ async def test_delete_azure_client_flattened_error_async(): ) def test_create_azure_cluster(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1953,7 +2373,7 @@ def test_create_azure_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1973,7 +2393,7 @@ async def test_create_azure_cluster_async( request_type=azure_service.CreateAzureClusterRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2007,7 +2427,7 @@ async def test_create_azure_cluster_async_from_dict(): def test_create_azure_cluster_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2039,7 +2459,7 @@ def test_create_azure_cluster_field_headers(): @pytest.mark.asyncio async def test_create_azure_cluster_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2072,7 +2492,7 @@ async def test_create_azure_cluster_field_headers_async(): def test_create_azure_cluster_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2106,7 +2526,7 @@ def test_create_azure_cluster_flattened(): def test_create_azure_cluster_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2123,7 +2543,7 @@ def test_create_azure_cluster_flattened_error(): @pytest.mark.asyncio async def test_create_azure_cluster_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2162,7 +2582,7 @@ async def test_create_azure_cluster_flattened_async(): @pytest.mark.asyncio async def test_create_azure_cluster_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2185,7 +2605,7 @@ async def test_create_azure_cluster_flattened_error_async(): ) def test_update_azure_cluster(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2214,7 +2634,7 @@ def test_update_azure_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2234,7 +2654,7 @@ async def test_update_azure_cluster_async( request_type=azure_service.UpdateAzureClusterRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2268,7 +2688,7 @@ async def test_update_azure_cluster_async_from_dict(): def test_update_azure_cluster_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2300,7 +2720,7 @@ def test_update_azure_cluster_field_headers(): @pytest.mark.asyncio async def test_update_azure_cluster_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2333,7 +2753,7 @@ async def test_update_azure_cluster_field_headers_async(): def test_update_azure_cluster_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2363,7 +2783,7 @@ def test_update_azure_cluster_flattened(): def test_update_azure_cluster_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2379,7 +2799,7 @@ def test_update_azure_cluster_flattened_error(): @pytest.mark.asyncio async def test_update_azure_cluster_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2414,7 +2834,7 @@ async def test_update_azure_cluster_flattened_async(): @pytest.mark.asyncio async def test_update_azure_cluster_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2436,7 +2856,7 @@ async def test_update_azure_cluster_flattened_error_async(): ) def test_get_azure_cluster(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2488,7 +2908,7 @@ def test_get_azure_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2507,7 +2927,7 @@ async def test_get_azure_cluster_async( transport: str = "grpc_asyncio", request_type=azure_service.GetAzureClusterRequest ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2564,7 +2984,7 @@ async def test_get_azure_cluster_async_from_dict(): def test_get_azure_cluster_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2596,7 +3016,7 @@ def test_get_azure_cluster_field_headers(): @pytest.mark.asyncio async def test_get_azure_cluster_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2629,7 +3049,7 @@ async def test_get_azure_cluster_field_headers_async(): def test_get_azure_cluster_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2655,7 +3075,7 @@ def test_get_azure_cluster_flattened(): def test_get_azure_cluster_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2670,7 +3090,7 @@ def test_get_azure_cluster_flattened_error(): @pytest.mark.asyncio async def test_get_azure_cluster_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2701,7 +3121,7 @@ async def test_get_azure_cluster_flattened_async(): @pytest.mark.asyncio async def test_get_azure_cluster_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2722,7 +3142,7 @@ async def test_get_azure_cluster_flattened_error_async(): ) def test_list_azure_clusters(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2754,7 +3174,7 @@ def test_list_azure_clusters_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2773,7 +3193,7 @@ async def test_list_azure_clusters_async( transport: str = "grpc_asyncio", request_type=azure_service.ListAzureClustersRequest ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2810,7 +3230,7 @@ async def test_list_azure_clusters_async_from_dict(): def test_list_azure_clusters_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2842,7 +3262,7 @@ def test_list_azure_clusters_field_headers(): @pytest.mark.asyncio async def test_list_azure_clusters_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2875,7 +3295,7 @@ async def test_list_azure_clusters_field_headers_async(): def test_list_azure_clusters_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2901,7 +3321,7 @@ def test_list_azure_clusters_flattened(): def test_list_azure_clusters_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2916,7 +3336,7 @@ def test_list_azure_clusters_flattened_error(): @pytest.mark.asyncio async def test_list_azure_clusters_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2947,7 +3367,7 @@ async def test_list_azure_clusters_flattened_async(): @pytest.mark.asyncio async def test_list_azure_clusters_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2961,7 +3381,7 @@ async def test_list_azure_clusters_flattened_error_async(): def test_list_azure_clusters_pager(transport_name: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3013,7 +3433,7 @@ def test_list_azure_clusters_pager(transport_name: str = "grpc"): def test_list_azure_clusters_pages(transport_name: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -3057,7 +3477,7 @@ def test_list_azure_clusters_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_azure_clusters_async_pager(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3109,7 +3529,7 @@ async def test_list_azure_clusters_async_pager(): @pytest.mark.asyncio async def test_list_azure_clusters_async_pages(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3166,7 +3586,7 @@ async def test_list_azure_clusters_async_pages(): ) def test_delete_azure_cluster(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3195,7 +3615,7 @@ def test_delete_azure_cluster_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3215,7 +3635,7 @@ async def test_delete_azure_cluster_async( request_type=azure_service.DeleteAzureClusterRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3249,7 +3669,7 @@ async def test_delete_azure_cluster_async_from_dict(): def test_delete_azure_cluster_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3281,7 +3701,7 @@ def test_delete_azure_cluster_field_headers(): @pytest.mark.asyncio async def test_delete_azure_cluster_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3314,7 +3734,7 @@ async def test_delete_azure_cluster_field_headers_async(): def test_delete_azure_cluster_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3340,7 +3760,7 @@ def test_delete_azure_cluster_flattened(): def test_delete_azure_cluster_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3355,7 +3775,7 @@ def test_delete_azure_cluster_flattened_error(): @pytest.mark.asyncio async def test_delete_azure_cluster_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3386,7 +3806,7 @@ async def test_delete_azure_cluster_flattened_async(): @pytest.mark.asyncio async def test_delete_azure_cluster_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3407,7 +3827,7 @@ async def test_delete_azure_cluster_flattened_error_async(): ) def test_generate_azure_cluster_agent_token(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3443,7 +3863,7 @@ def test_generate_azure_cluster_agent_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3463,7 +3883,7 @@ async def test_generate_azure_cluster_agent_token_async( request_type=azure_service.GenerateAzureClusterAgentTokenRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3504,7 +3924,7 @@ async def test_generate_azure_cluster_agent_token_async_from_dict(): def test_generate_azure_cluster_agent_token_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3536,7 +3956,7 @@ def test_generate_azure_cluster_agent_token_field_headers(): @pytest.mark.asyncio async def test_generate_azure_cluster_agent_token_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3576,7 +3996,7 @@ async def test_generate_azure_cluster_agent_token_field_headers_async(): ) def test_generate_azure_access_token(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3608,7 +4028,7 @@ def test_generate_azure_access_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3628,7 +4048,7 @@ async def test_generate_azure_access_token_async( request_type=azure_service.GenerateAzureAccessTokenRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3665,7 +4085,7 @@ async def test_generate_azure_access_token_async_from_dict(): def test_generate_azure_access_token_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3697,7 +4117,7 @@ def test_generate_azure_access_token_field_headers(): @pytest.mark.asyncio async def test_generate_azure_access_token_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3737,7 +4157,7 @@ async def test_generate_azure_access_token_field_headers_async(): ) def test_create_azure_node_pool(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3766,7 +4186,7 @@ def test_create_azure_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -3786,7 +4206,7 @@ async def test_create_azure_node_pool_async( request_type=azure_service.CreateAzureNodePoolRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3820,7 +4240,7 @@ async def test_create_azure_node_pool_async_from_dict(): def test_create_azure_node_pool_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3852,7 +4272,7 @@ def test_create_azure_node_pool_field_headers(): @pytest.mark.asyncio async def test_create_azure_node_pool_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3885,7 +4305,7 @@ async def test_create_azure_node_pool_field_headers_async(): def test_create_azure_node_pool_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3919,7 +4339,7 @@ def test_create_azure_node_pool_flattened(): def test_create_azure_node_pool_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3936,7 +4356,7 @@ def test_create_azure_node_pool_flattened_error(): @pytest.mark.asyncio async def test_create_azure_node_pool_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3975,7 +4395,7 @@ async def test_create_azure_node_pool_flattened_async(): @pytest.mark.asyncio async def test_create_azure_node_pool_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3998,7 +4418,7 @@ async def test_create_azure_node_pool_flattened_error_async(): ) def test_update_azure_node_pool(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4027,7 +4447,7 @@ def test_update_azure_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4047,7 +4467,7 @@ async def test_update_azure_node_pool_async( request_type=azure_service.UpdateAzureNodePoolRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4081,7 +4501,7 @@ async def test_update_azure_node_pool_async_from_dict(): def test_update_azure_node_pool_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4113,7 +4533,7 @@ def test_update_azure_node_pool_field_headers(): @pytest.mark.asyncio async def test_update_azure_node_pool_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4146,7 +4566,7 @@ async def test_update_azure_node_pool_field_headers_async(): def test_update_azure_node_pool_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4176,7 +4596,7 @@ def test_update_azure_node_pool_flattened(): def test_update_azure_node_pool_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4192,7 +4612,7 @@ def test_update_azure_node_pool_flattened_error(): @pytest.mark.asyncio async def test_update_azure_node_pool_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4227,7 +4647,7 @@ async def test_update_azure_node_pool_flattened_async(): @pytest.mark.asyncio async def test_update_azure_node_pool_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4249,7 +4669,7 @@ async def test_update_azure_node_pool_flattened_error_async(): ) def test_get_azure_node_pool(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4295,7 +4715,7 @@ def test_get_azure_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4314,7 +4734,7 @@ async def test_get_azure_node_pool_async( transport: str = "grpc_asyncio", request_type=azure_service.GetAzureNodePoolRequest ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4365,7 +4785,7 @@ async def test_get_azure_node_pool_async_from_dict(): def test_get_azure_node_pool_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4397,7 +4817,7 @@ def test_get_azure_node_pool_field_headers(): @pytest.mark.asyncio async def test_get_azure_node_pool_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4430,7 +4850,7 @@ async def test_get_azure_node_pool_field_headers_async(): def test_get_azure_node_pool_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4456,7 +4876,7 @@ def test_get_azure_node_pool_flattened(): def test_get_azure_node_pool_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4471,7 +4891,7 @@ def test_get_azure_node_pool_flattened_error(): @pytest.mark.asyncio async def test_get_azure_node_pool_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4502,7 +4922,7 @@ async def test_get_azure_node_pool_flattened_async(): @pytest.mark.asyncio async def test_get_azure_node_pool_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4523,7 +4943,7 @@ async def test_get_azure_node_pool_flattened_error_async(): ) def test_list_azure_node_pools(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4555,7 +4975,7 @@ def test_list_azure_node_pools_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -4575,7 +4995,7 @@ async def test_list_azure_node_pools_async( request_type=azure_service.ListAzureNodePoolsRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4612,7 +5032,7 @@ async def test_list_azure_node_pools_async_from_dict(): def test_list_azure_node_pools_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4644,7 +5064,7 @@ def test_list_azure_node_pools_field_headers(): @pytest.mark.asyncio async def test_list_azure_node_pools_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4677,7 +5097,7 @@ async def test_list_azure_node_pools_field_headers_async(): def test_list_azure_node_pools_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4703,7 +5123,7 @@ def test_list_azure_node_pools_flattened(): def test_list_azure_node_pools_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4718,7 +5138,7 @@ def test_list_azure_node_pools_flattened_error(): @pytest.mark.asyncio async def test_list_azure_node_pools_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4749,7 +5169,7 @@ async def test_list_azure_node_pools_flattened_async(): @pytest.mark.asyncio async def test_list_azure_node_pools_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -4763,7 +5183,7 @@ async def test_list_azure_node_pools_flattened_error_async(): def test_list_azure_node_pools_pager(transport_name: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4815,7 +5235,7 @@ def test_list_azure_node_pools_pager(transport_name: str = "grpc"): def test_list_azure_node_pools_pages(transport_name: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -4859,7 +5279,7 @@ def test_list_azure_node_pools_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_azure_node_pools_async_pager(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4911,7 +5331,7 @@ async def test_list_azure_node_pools_async_pager(): @pytest.mark.asyncio async def test_list_azure_node_pools_async_pages(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4968,7 +5388,7 @@ async def test_list_azure_node_pools_async_pages(): ) def test_delete_azure_node_pool(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4997,7 +5417,7 @@ def test_delete_azure_node_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5017,7 +5437,7 @@ async def test_delete_azure_node_pool_async( request_type=azure_service.DeleteAzureNodePoolRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5051,7 +5471,7 @@ async def test_delete_azure_node_pool_async_from_dict(): def test_delete_azure_node_pool_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5083,7 +5503,7 @@ def test_delete_azure_node_pool_field_headers(): @pytest.mark.asyncio async def test_delete_azure_node_pool_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5116,7 +5536,7 @@ async def test_delete_azure_node_pool_field_headers_async(): def test_delete_azure_node_pool_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5142,7 +5562,7 @@ def test_delete_azure_node_pool_flattened(): def test_delete_azure_node_pool_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5157,7 +5577,7 @@ def test_delete_azure_node_pool_flattened_error(): @pytest.mark.asyncio async def test_delete_azure_node_pool_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5188,7 +5608,7 @@ async def test_delete_azure_node_pool_flattened_async(): @pytest.mark.asyncio async def test_delete_azure_node_pool_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5209,7 +5629,7 @@ async def test_delete_azure_node_pool_flattened_error_async(): ) def test_get_azure_open_id_config(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5257,7 +5677,7 @@ def test_get_azure_open_id_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5277,7 +5697,7 @@ async def test_get_azure_open_id_config_async( request_type=azure_service.GetAzureOpenIdConfigRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5330,7 +5750,7 @@ async def test_get_azure_open_id_config_async_from_dict(): def test_get_azure_open_id_config_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5362,7 +5782,7 @@ def test_get_azure_open_id_config_field_headers(): @pytest.mark.asyncio async def test_get_azure_open_id_config_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5395,7 +5815,7 @@ async def test_get_azure_open_id_config_field_headers_async(): def test_get_azure_open_id_config_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5421,7 +5841,7 @@ def test_get_azure_open_id_config_flattened(): def test_get_azure_open_id_config_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5436,7 +5856,7 @@ def test_get_azure_open_id_config_flattened_error(): @pytest.mark.asyncio async def test_get_azure_open_id_config_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5467,7 +5887,7 @@ async def test_get_azure_open_id_config_flattened_async(): @pytest.mark.asyncio async def test_get_azure_open_id_config_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5488,7 +5908,7 @@ async def test_get_azure_open_id_config_flattened_error_async(): ) def test_get_azure_json_web_keys(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5517,7 +5937,7 @@ def test_get_azure_json_web_keys_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5537,7 +5957,7 @@ async def test_get_azure_json_web_keys_async( request_type=azure_service.GetAzureJsonWebKeysRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5571,7 +5991,7 @@ async def test_get_azure_json_web_keys_async_from_dict(): def test_get_azure_json_web_keys_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5603,7 +6023,7 @@ def test_get_azure_json_web_keys_field_headers(): @pytest.mark.asyncio async def test_get_azure_json_web_keys_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5636,7 +6056,7 @@ async def test_get_azure_json_web_keys_field_headers_async(): def test_get_azure_json_web_keys_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5662,7 +6082,7 @@ def test_get_azure_json_web_keys_flattened(): def test_get_azure_json_web_keys_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5677,7 +6097,7 @@ def test_get_azure_json_web_keys_flattened_error(): @pytest.mark.asyncio async def test_get_azure_json_web_keys_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5708,7 +6128,7 @@ async def test_get_azure_json_web_keys_flattened_async(): @pytest.mark.asyncio async def test_get_azure_json_web_keys_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5729,7 +6149,7 @@ async def test_get_azure_json_web_keys_flattened_error_async(): ) def test_get_azure_server_config(request_type, transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5763,7 +6183,7 @@ def test_get_azure_server_config_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -5783,7 +6203,7 @@ async def test_get_azure_server_config_async( request_type=azure_service.GetAzureServerConfigRequest, ): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5822,7 +6242,7 @@ async def test_get_azure_server_config_async_from_dict(): def test_get_azure_server_config_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5854,7 +6274,7 @@ def test_get_azure_server_config_field_headers(): @pytest.mark.asyncio async def test_get_azure_server_config_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -5887,7 +6307,7 @@ async def test_get_azure_server_config_field_headers_async(): def test_get_azure_server_config_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5913,7 +6333,7 @@ def test_get_azure_server_config_flattened(): def test_get_azure_server_config_flattened_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5928,7 +6348,7 @@ def test_get_azure_server_config_flattened_error(): @pytest.mark.asyncio async def test_get_azure_server_config_flattened_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5959,7 +6379,7 @@ async def test_get_azure_server_config_flattened_async(): @pytest.mark.asyncio async def test_get_azure_server_config_flattened_error_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -5980,7 +6400,7 @@ async def test_get_azure_server_config_flattened_error_async(): ) def test_create_azure_client_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6106,7 +6526,7 @@ def test_create_azure_client_rest_required_fields( assert "azureClientId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_azure_client._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6118,7 +6538,7 @@ def test_create_azure_client_rest_required_fields( jsonified_request["azureClientId"] = "azure_client_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_azure_client._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6136,7 +6556,7 @@ def test_create_azure_client_rest_required_fields( assert jsonified_request["azureClientId"] == "azure_client_id_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6181,7 +6601,7 @@ def test_create_azure_client_rest_required_fields( def test_create_azure_client_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_azure_client._get_unset_required_fields({}) @@ -6205,7 +6625,7 @@ def test_create_azure_client_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_azure_client_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -6265,7 +6685,7 @@ def test_create_azure_client_rest_bad_request( transport: str = "rest", request_type=azure_service.CreateAzureClientRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6287,7 +6707,7 @@ def test_create_azure_client_rest_bad_request( def test_create_azure_client_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6329,7 +6749,7 @@ def test_create_azure_client_rest_flattened(): def test_create_azure_client_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6346,7 +6766,7 @@ def test_create_azure_client_rest_flattened_error(transport: str = "rest"): def test_create_azure_client_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6359,7 +6779,7 @@ def test_create_azure_client_rest_error(): ) def test_get_azure_client_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6420,7 +6840,7 @@ def test_get_azure_client_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_client._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6429,7 +6849,7 @@ def test_get_azure_client_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_client._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6438,7 +6858,7 @@ def test_get_azure_client_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6480,7 +6900,7 @@ def test_get_azure_client_rest_required_fields( def test_get_azure_client_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_azure_client._get_unset_required_fields({}) @@ -6490,7 +6910,7 @@ def test_get_azure_client_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_azure_client_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -6548,7 +6968,7 @@ def test_get_azure_client_rest_bad_request( transport: str = "rest", request_type=azure_service.GetAzureClientRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6570,7 +6990,7 @@ def test_get_azure_client_rest_bad_request( def test_get_azure_client_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6614,7 +7034,7 @@ def test_get_azure_client_rest_flattened(): def test_get_azure_client_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6629,7 +7049,7 @@ def test_get_azure_client_rest_flattened_error(transport: str = "rest"): def test_get_azure_client_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -6642,7 +7062,7 @@ def test_get_azure_client_rest_error(): ) def test_list_azure_clients_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6693,7 +7113,7 @@ def test_list_azure_clients_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_azure_clients._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -6702,7 +7122,7 @@ def test_list_azure_clients_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_azure_clients._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -6718,7 +7138,7 @@ def test_list_azure_clients_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -6760,7 +7180,7 @@ def test_list_azure_clients_rest_required_fields( def test_list_azure_clients_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_azure_clients._get_unset_required_fields({}) @@ -6778,7 +7198,7 @@ def test_list_azure_clients_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_azure_clients_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -6836,7 +7256,7 @@ def test_list_azure_clients_rest_bad_request( transport: str = "rest", request_type=azure_service.ListAzureClientsRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6858,7 +7278,7 @@ def test_list_azure_clients_rest_bad_request( def test_list_azure_clients_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -6900,7 +7320,7 @@ def test_list_azure_clients_rest_flattened(): def test_list_azure_clients_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6915,7 +7335,7 @@ def test_list_azure_clients_rest_flattened_error(transport: str = "rest"): def test_list_azure_clients_rest_pager(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -6985,7 +7405,7 @@ def test_list_azure_clients_rest_pager(transport: str = "rest"): ) def test_delete_azure_client_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7031,7 +7451,7 @@ def test_delete_azure_client_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_azure_client._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7040,7 +7460,7 @@ def test_delete_azure_client_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_azure_client._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7056,7 +7476,7 @@ def test_delete_azure_client_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7095,7 +7515,7 @@ def test_delete_azure_client_rest_required_fields( def test_delete_azure_client_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_azure_client._get_unset_required_fields({}) @@ -7113,7 +7533,7 @@ def test_delete_azure_client_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_azure_client_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -7173,7 +7593,7 @@ def test_delete_azure_client_rest_bad_request( transport: str = "rest", request_type=azure_service.DeleteAzureClientRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7195,7 +7615,7 @@ def test_delete_azure_client_rest_bad_request( def test_delete_azure_client_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7237,7 +7657,7 @@ def test_delete_azure_client_rest_flattened(): def test_delete_azure_client_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7252,7 +7672,7 @@ def test_delete_azure_client_rest_flattened_error(transport: str = "rest"): def test_delete_azure_client_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7265,7 +7685,7 @@ def test_delete_azure_client_rest_error(): ) def test_create_azure_cluster_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7454,7 +7874,7 @@ def test_create_azure_cluster_rest_required_fields( assert "azureClusterId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_azure_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -7466,7 +7886,7 @@ def test_create_azure_cluster_rest_required_fields( jsonified_request["azureClusterId"] = "azure_cluster_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_azure_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7484,7 +7904,7 @@ def test_create_azure_cluster_rest_required_fields( assert jsonified_request["azureClusterId"] == "azure_cluster_id_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7529,7 +7949,7 @@ def test_create_azure_cluster_rest_required_fields( def test_create_azure_cluster_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_azure_cluster._get_unset_required_fields({}) @@ -7553,7 +7973,7 @@ def test_create_azure_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_azure_cluster_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -7613,7 +8033,7 @@ def test_create_azure_cluster_rest_bad_request( transport: str = "rest", request_type=azure_service.CreateAzureClusterRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7635,7 +8055,7 @@ def test_create_azure_cluster_rest_bad_request( def test_create_azure_cluster_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7677,7 +8097,7 @@ def test_create_azure_cluster_rest_flattened(): def test_create_azure_cluster_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -7694,7 +8114,7 @@ def test_create_azure_cluster_rest_flattened_error(transport: str = "rest"): def test_create_azure_cluster_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -7707,7 +8127,7 @@ def test_create_azure_cluster_rest_error(): ) def test_update_azure_cluster_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -7897,14 +8317,14 @@ def test_update_azure_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_azure_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_azure_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -7918,7 +8338,7 @@ def test_update_azure_cluster_rest_required_fields( # verify required fields with non-default values are left alone client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -7958,7 +8378,7 @@ def test_update_azure_cluster_rest_required_fields( def test_update_azure_cluster_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_azure_cluster._get_unset_required_fields({}) @@ -7981,7 +8401,7 @@ def test_update_azure_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_azure_cluster_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -8041,7 +8461,7 @@ def test_update_azure_cluster_rest_bad_request( transport: str = "rest", request_type=azure_service.UpdateAzureClusterRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8067,7 +8487,7 @@ def test_update_azure_cluster_rest_bad_request( def test_update_azure_cluster_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8112,7 +8532,7 @@ def test_update_azure_cluster_rest_flattened(): def test_update_azure_cluster_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8128,7 +8548,7 @@ def test_update_azure_cluster_rest_flattened_error(transport: str = "rest"): def test_update_azure_cluster_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8141,7 +8561,7 @@ def test_update_azure_cluster_rest_error(): ) def test_get_azure_cluster_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8212,7 +8632,7 @@ def test_get_azure_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8221,7 +8641,7 @@ def test_get_azure_cluster_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8230,7 +8650,7 @@ def test_get_azure_cluster_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8272,7 +8692,7 @@ def test_get_azure_cluster_rest_required_fields( def test_get_azure_cluster_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_azure_cluster._get_unset_required_fields({}) @@ -8282,7 +8702,7 @@ def test_get_azure_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_azure_cluster_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -8340,7 +8760,7 @@ def test_get_azure_cluster_rest_bad_request( transport: str = "rest", request_type=azure_service.GetAzureClusterRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8362,7 +8782,7 @@ def test_get_azure_cluster_rest_bad_request( def test_get_azure_cluster_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8406,7 +8826,7 @@ def test_get_azure_cluster_rest_flattened(): def test_get_azure_cluster_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8421,7 +8841,7 @@ def test_get_azure_cluster_rest_flattened_error(transport: str = "rest"): def test_get_azure_cluster_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -8434,7 +8854,7 @@ def test_get_azure_cluster_rest_error(): ) def test_list_azure_clusters_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8485,7 +8905,7 @@ def test_list_azure_clusters_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_azure_clusters._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8494,7 +8914,7 @@ def test_list_azure_clusters_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_azure_clusters._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8510,7 +8930,7 @@ def test_list_azure_clusters_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8552,7 +8972,7 @@ def test_list_azure_clusters_rest_required_fields( def test_list_azure_clusters_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_azure_clusters._get_unset_required_fields({}) @@ -8570,7 +8990,7 @@ def test_list_azure_clusters_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_azure_clusters_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -8628,7 +9048,7 @@ def test_list_azure_clusters_rest_bad_request( transport: str = "rest", request_type=azure_service.ListAzureClustersRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8650,7 +9070,7 @@ def test_list_azure_clusters_rest_bad_request( def test_list_azure_clusters_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8692,7 +9112,7 @@ def test_list_azure_clusters_rest_flattened(): def test_list_azure_clusters_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8707,7 +9127,7 @@ def test_list_azure_clusters_rest_flattened_error(transport: str = "rest"): def test_list_azure_clusters_rest_pager(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8777,7 +9197,7 @@ def test_list_azure_clusters_rest_pager(transport: str = "rest"): ) def test_delete_azure_cluster_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -8823,7 +9243,7 @@ def test_delete_azure_cluster_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_azure_cluster._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -8832,7 +9252,7 @@ def test_delete_azure_cluster_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_azure_cluster._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -8849,7 +9269,7 @@ def test_delete_azure_cluster_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -8888,7 +9308,7 @@ def test_delete_azure_cluster_rest_required_fields( def test_delete_azure_cluster_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_azure_cluster._get_unset_required_fields({}) @@ -8907,7 +9327,7 @@ def test_delete_azure_cluster_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_azure_cluster_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -8967,7 +9387,7 @@ def test_delete_azure_cluster_rest_bad_request( transport: str = "rest", request_type=azure_service.DeleteAzureClusterRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -8989,7 +9409,7 @@ def test_delete_azure_cluster_rest_bad_request( def test_delete_azure_cluster_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9031,7 +9451,7 @@ def test_delete_azure_cluster_rest_flattened(): def test_delete_azure_cluster_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9046,7 +9466,7 @@ def test_delete_azure_cluster_rest_flattened_error(transport: str = "rest"): def test_delete_azure_cluster_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9059,7 +9479,7 @@ def test_delete_azure_cluster_rest_error(): ) def test_generate_azure_cluster_agent_token_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9121,7 +9541,7 @@ def test_generate_azure_cluster_agent_token_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_azure_cluster_agent_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9133,7 +9553,7 @@ def test_generate_azure_cluster_agent_token_rest_required_fields( jsonified_request["version"] = "version_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_azure_cluster_agent_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9148,7 +9568,7 @@ def test_generate_azure_cluster_agent_token_rest_required_fields( assert jsonified_request["version"] == "version_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9193,7 +9613,7 @@ def test_generate_azure_cluster_agent_token_rest_required_fields( def test_generate_azure_cluster_agent_token_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = ( @@ -9215,7 +9635,7 @@ def test_generate_azure_cluster_agent_token_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_azure_cluster_agent_token_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -9278,7 +9698,7 @@ def test_generate_azure_cluster_agent_token_rest_bad_request( request_type=azure_service.GenerateAzureClusterAgentTokenRequest, ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9302,7 +9722,7 @@ def test_generate_azure_cluster_agent_token_rest_bad_request( def test_generate_azure_cluster_agent_token_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9315,7 +9735,7 @@ def test_generate_azure_cluster_agent_token_rest_error(): ) def test_generate_azure_access_token_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9368,7 +9788,7 @@ def test_generate_azure_access_token_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_azure_access_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9377,7 +9797,7 @@ def test_generate_azure_access_token_rest_required_fields( jsonified_request["azureCluster"] = "azure_cluster_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_azure_access_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9386,7 +9806,7 @@ def test_generate_azure_access_token_rest_required_fields( assert jsonified_request["azureCluster"] == "azure_cluster_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9430,7 +9850,7 @@ def test_generate_azure_access_token_rest_required_fields( def test_generate_azure_access_token_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_azure_access_token._get_unset_required_fields({}) @@ -9440,7 +9860,7 @@ def test_generate_azure_access_token_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_azure_access_token_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -9500,7 +9920,7 @@ def test_generate_azure_access_token_rest_bad_request( transport: str = "rest", request_type=azure_service.GenerateAzureAccessTokenRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9524,7 +9944,7 @@ def test_generate_azure_access_token_rest_bad_request( def test_generate_azure_access_token_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9537,7 +9957,7 @@ def test_generate_azure_access_token_rest_error(): ) def test_create_azure_node_pool_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9688,7 +10108,7 @@ def test_create_azure_node_pool_rest_required_fields( assert "azureNodePoolId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_azure_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -9700,7 +10120,7 @@ def test_create_azure_node_pool_rest_required_fields( jsonified_request["azureNodePoolId"] = "azure_node_pool_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_azure_node_pool._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -9718,7 +10138,7 @@ def test_create_azure_node_pool_rest_required_fields( assert jsonified_request["azureNodePoolId"] == "azure_node_pool_id_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -9763,7 +10183,7 @@ def test_create_azure_node_pool_rest_required_fields( def test_create_azure_node_pool_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_azure_node_pool._get_unset_required_fields({}) @@ -9787,7 +10207,7 @@ def test_create_azure_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_azure_node_pool_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -9847,7 +10267,7 @@ def test_create_azure_node_pool_rest_bad_request( transport: str = "rest", request_type=azure_service.CreateAzureNodePoolRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9871,7 +10291,7 @@ def test_create_azure_node_pool_rest_bad_request( def test_create_azure_node_pool_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -9915,7 +10335,7 @@ def test_create_azure_node_pool_rest_flattened(): def test_create_azure_node_pool_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -9932,7 +10352,7 @@ def test_create_azure_node_pool_rest_flattened_error(transport: str = "rest"): def test_create_azure_node_pool_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -9945,7 +10365,7 @@ def test_create_azure_node_pool_rest_error(): ) def test_update_azure_node_pool_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10095,14 +10515,14 @@ def test_update_azure_node_pool_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_azure_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_azure_node_pool._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -10116,7 +10536,7 @@ def test_update_azure_node_pool_rest_required_fields( # verify required fields with non-default values are left alone client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10156,7 +10576,7 @@ def test_update_azure_node_pool_rest_required_fields( def test_update_azure_node_pool_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_azure_node_pool._get_unset_required_fields({}) @@ -10179,7 +10599,7 @@ def test_update_azure_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_azure_node_pool_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -10239,7 +10659,7 @@ def test_update_azure_node_pool_rest_bad_request( transport: str = "rest", request_type=azure_service.UpdateAzureNodePoolRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10265,7 +10685,7 @@ def test_update_azure_node_pool_rest_bad_request( def test_update_azure_node_pool_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10310,7 +10730,7 @@ def test_update_azure_node_pool_rest_flattened(): def test_update_azure_node_pool_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10326,7 +10746,7 @@ def test_update_azure_node_pool_rest_flattened_error(transport: str = "rest"): def test_update_azure_node_pool_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10339,7 +10759,7 @@ def test_update_azure_node_pool_rest_error(): ) def test_get_azure_node_pool_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10406,7 +10826,7 @@ def test_get_azure_node_pool_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10415,7 +10835,7 @@ def test_get_azure_node_pool_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10424,7 +10844,7 @@ def test_get_azure_node_pool_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10466,7 +10886,7 @@ def test_get_azure_node_pool_rest_required_fields( def test_get_azure_node_pool_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_azure_node_pool._get_unset_required_fields({}) @@ -10476,7 +10896,7 @@ def test_get_azure_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_azure_node_pool_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -10534,7 +10954,7 @@ def test_get_azure_node_pool_rest_bad_request( transport: str = "rest", request_type=azure_service.GetAzureNodePoolRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10558,7 +10978,7 @@ def test_get_azure_node_pool_rest_bad_request( def test_get_azure_node_pool_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10602,7 +11022,7 @@ def test_get_azure_node_pool_rest_flattened(): def test_get_azure_node_pool_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10617,7 +11037,7 @@ def test_get_azure_node_pool_rest_flattened_error(transport: str = "rest"): def test_get_azure_node_pool_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -10630,7 +11050,7 @@ def test_get_azure_node_pool_rest_error(): ) def test_list_azure_node_pools_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10683,7 +11103,7 @@ def test_list_azure_node_pools_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_azure_node_pools._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -10692,7 +11112,7 @@ def test_list_azure_node_pools_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_azure_node_pools._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -10708,7 +11128,7 @@ def test_list_azure_node_pools_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -10750,7 +11170,7 @@ def test_list_azure_node_pools_rest_required_fields( def test_list_azure_node_pools_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_azure_node_pools._get_unset_required_fields({}) @@ -10768,7 +11188,7 @@ def test_list_azure_node_pools_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_azure_node_pools_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -10826,7 +11246,7 @@ def test_list_azure_node_pools_rest_bad_request( transport: str = "rest", request_type=azure_service.ListAzureNodePoolsRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10850,7 +11270,7 @@ def test_list_azure_node_pools_rest_bad_request( def test_list_azure_node_pools_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -10894,7 +11314,7 @@ def test_list_azure_node_pools_rest_flattened(): def test_list_azure_node_pools_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10909,7 +11329,7 @@ def test_list_azure_node_pools_rest_flattened_error(transport: str = "rest"): def test_list_azure_node_pools_rest_pager(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -10981,7 +11401,7 @@ def test_list_azure_node_pools_rest_pager(transport: str = "rest"): ) def test_delete_azure_node_pool_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11029,7 +11449,7 @@ def test_delete_azure_node_pool_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_azure_node_pool._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11038,7 +11458,7 @@ def test_delete_azure_node_pool_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_azure_node_pool._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -11055,7 +11475,7 @@ def test_delete_azure_node_pool_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11094,7 +11514,7 @@ def test_delete_azure_node_pool_rest_required_fields( def test_delete_azure_node_pool_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_azure_node_pool._get_unset_required_fields({}) @@ -11113,7 +11533,7 @@ def test_delete_azure_node_pool_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_azure_node_pool_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -11173,7 +11593,7 @@ def test_delete_azure_node_pool_rest_bad_request( transport: str = "rest", request_type=azure_service.DeleteAzureNodePoolRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11197,7 +11617,7 @@ def test_delete_azure_node_pool_rest_bad_request( def test_delete_azure_node_pool_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11239,7 +11659,7 @@ def test_delete_azure_node_pool_rest_flattened(): def test_delete_azure_node_pool_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11254,7 +11674,7 @@ def test_delete_azure_node_pool_rest_flattened_error(transport: str = "rest"): def test_delete_azure_node_pool_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11267,7 +11687,7 @@ def test_delete_azure_node_pool_rest_error(): ) def test_get_azure_open_id_config_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11336,7 +11756,7 @@ def test_get_azure_open_id_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_open_id_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11345,7 +11765,7 @@ def test_get_azure_open_id_config_rest_required_fields( jsonified_request["azureCluster"] = "azure_cluster_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_open_id_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11354,7 +11774,7 @@ def test_get_azure_open_id_config_rest_required_fields( assert jsonified_request["azureCluster"] == "azure_cluster_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11396,7 +11816,7 @@ def test_get_azure_open_id_config_rest_required_fields( def test_get_azure_open_id_config_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_azure_open_id_config._get_unset_required_fields({}) @@ -11406,7 +11826,7 @@ def test_get_azure_open_id_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_azure_open_id_config_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -11464,7 +11884,7 @@ def test_get_azure_open_id_config_rest_bad_request( transport: str = "rest", request_type=azure_service.GetAzureOpenIdConfigRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11488,7 +11908,7 @@ def test_get_azure_open_id_config_rest_bad_request( def test_get_azure_open_id_config_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11532,7 +11952,7 @@ def test_get_azure_open_id_config_rest_flattened(): def test_get_azure_open_id_config_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11547,7 +11967,7 @@ def test_get_azure_open_id_config_rest_flattened_error(transport: str = "rest"): def test_get_azure_open_id_config_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11560,7 +11980,7 @@ def test_get_azure_open_id_config_rest_error(): ) def test_get_azure_json_web_keys_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11610,7 +12030,7 @@ def test_get_azure_json_web_keys_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_json_web_keys._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11619,7 +12039,7 @@ def test_get_azure_json_web_keys_rest_required_fields( jsonified_request["azureCluster"] = "azure_cluster_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_json_web_keys._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11628,7 +12048,7 @@ def test_get_azure_json_web_keys_rest_required_fields( assert jsonified_request["azureCluster"] == "azure_cluster_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11670,7 +12090,7 @@ def test_get_azure_json_web_keys_rest_required_fields( def test_get_azure_json_web_keys_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_azure_json_web_keys._get_unset_required_fields({}) @@ -11680,7 +12100,7 @@ def test_get_azure_json_web_keys_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_azure_json_web_keys_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -11738,7 +12158,7 @@ def test_get_azure_json_web_keys_rest_bad_request( transport: str = "rest", request_type=azure_service.GetAzureJsonWebKeysRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11762,7 +12182,7 @@ def test_get_azure_json_web_keys_rest_bad_request( def test_get_azure_json_web_keys_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11806,7 +12226,7 @@ def test_get_azure_json_web_keys_rest_flattened(): def test_get_azure_json_web_keys_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -11821,7 +12241,7 @@ def test_get_azure_json_web_keys_rest_flattened_error(transport: str = "rest"): def test_get_azure_json_web_keys_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -11834,7 +12254,7 @@ def test_get_azure_json_web_keys_rest_error(): ) def test_get_azure_server_config_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -11887,7 +12307,7 @@ def test_get_azure_server_config_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_server_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11896,7 +12316,7 @@ def test_get_azure_server_config_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_azure_server_config._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -11905,7 +12325,7 @@ def test_get_azure_server_config_rest_required_fields( assert jsonified_request["name"] == "name_value" client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -11947,7 +12367,7 @@ def test_get_azure_server_config_rest_required_fields( def test_get_azure_server_config_rest_unset_required_fields(): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_azure_server_config._get_unset_required_fields({}) @@ -11957,7 +12377,7 @@ def test_get_azure_server_config_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_azure_server_config_rest_interceptors(null_interceptor): transport = transports.AzureClustersRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.AzureClustersRestInterceptor(), @@ -12015,7 +12435,7 @@ def test_get_azure_server_config_rest_bad_request( transport: str = "rest", request_type=azure_service.GetAzureServerConfigRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12037,7 +12457,7 @@ def test_get_azure_server_config_rest_bad_request( def test_get_azure_server_config_rest_flattened(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -12081,7 +12501,7 @@ def test_get_azure_server_config_rest_flattened(): def test_get_azure_server_config_rest_flattened_error(transport: str = "rest"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -12096,24 +12516,24 @@ def test_get_azure_server_config_rest_flattened_error(transport: str = "rest"): def test_get_azure_server_config_rest_error(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.AzureClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.AzureClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AzureClustersClient( @@ -12123,7 +12543,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.AzureClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -12134,16 +12554,17 @@ 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 = AzureClustersClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.AzureClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = AzureClustersClient( @@ -12155,7 +12576,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.AzureClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = AzureClustersClient(transport=transport) assert client.transport is transport @@ -12164,13 +12585,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.AzureClustersGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.AzureClustersGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -12187,7 +12608,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -12201,7 +12622,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = AzureClustersClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -12209,7 +12630,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -12221,7 +12642,7 @@ def test_azure_clusters_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.AzureClustersTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -12233,7 +12654,7 @@ def test_azure_clusters_base_transport(): ) as Transport: Transport.return_value = None transport = transports.AzureClustersTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -12292,7 +12713,7 @@ def test_azure_clusters_base_transport_with_credentials_file(): "google.cloud.gke_multicloud_v1.services.azure_clusters.transports.AzureClustersTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AzureClustersTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -12311,7 +12732,7 @@ def test_azure_clusters_base_transport_with_adc(): "google.cloud.gke_multicloud_v1.services.azure_clusters.transports.AzureClustersTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.AzureClustersTransport() adc.assert_called_once() @@ -12319,7 +12740,7 @@ def test_azure_clusters_base_transport_with_adc(): def test_azure_clusters_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) AzureClustersClient() adc.assert_called_once_with( scopes=None, @@ -12339,7 +12760,7 @@ def test_azure_clusters_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -12386,7 +12807,7 @@ def test_azure_clusters_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -12414,7 +12835,7 @@ def test_azure_clusters_transport_create_channel(transport_class, grpc_helpers): ], ) def test_azure_clusters_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -12452,7 +12873,7 @@ def test_azure_clusters_grpc_transport_client_cert_source_for_mtls(transport_cla def test_azure_clusters_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -12464,7 +12885,7 @@ def test_azure_clusters_http_transport_client_cert_source_for_mtls(): def test_azure_clusters_rest_lro_client(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -12489,7 +12910,7 @@ def test_azure_clusters_rest_lro_client(): ) def test_azure_clusters_host_no_port(transport_name): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkemulticloud.googleapis.com" ), @@ -12512,7 +12933,7 @@ def test_azure_clusters_host_no_port(transport_name): ) def test_azure_clusters_host_with_port(transport_name): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gkemulticloud.googleapis.com:8000" ), @@ -12532,8 +12953,8 @@ def test_azure_clusters_host_with_port(transport_name): ], ) def test_azure_clusters_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = AzureClustersClient( credentials=creds1, transport=transport_name, @@ -12649,7 +13070,7 @@ def test_azure_clusters_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -12727,7 +13148,7 @@ def test_azure_clusters_transport_channel_mtls_with_adc(transport_class): def test_azure_clusters_grpc_lro_client(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -12744,7 +13165,7 @@ def test_azure_clusters_grpc_lro_client(): def test_azure_clusters_grpc_lro_async_client(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -12979,7 +13400,7 @@ def test_client_with_default_client_info(): transports.AzureClustersTransport, "_prep_wrapped_messages" ) as prep: client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -12989,7 +13410,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = AzureClustersClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -12998,7 +13419,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -13013,7 +13434,7 @@ def test_cancel_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.CancelOperationRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13043,7 +13464,7 @@ def test_cancel_operation_rest_bad_request( ) def test_cancel_operation_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -13071,7 +13492,7 @@ def test_delete_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.DeleteOperationRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13101,7 +13522,7 @@ def test_delete_operation_rest_bad_request( ) def test_delete_operation_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -13129,7 +13550,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13159,7 +13580,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} @@ -13187,7 +13608,7 @@ def test_list_operations_rest_bad_request( transport: str = "rest", request_type=operations_pb2.ListOperationsRequest ): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13217,7 +13638,7 @@ def test_list_operations_rest_bad_request( ) def test_list_operations_rest(request_type): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "projects/sample1/locations/sample2"} @@ -13243,7 +13664,7 @@ def test_list_operations_rest(request_type): def test_delete_operation(transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13268,7 +13689,7 @@ def test_delete_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_delete_operation_async(transport: str = "grpc_asyncio"): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13292,7 +13713,7 @@ async def test_delete_operation_async(transport: str = "grpc_asyncio"): def test_delete_operation_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13321,7 +13742,7 @@ def test_delete_operation_field_headers(): @pytest.mark.asyncio async def test_delete_operation_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13348,7 +13769,7 @@ async def test_delete_operation_field_headers_async(): def test_delete_operation_from_dict(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -13366,7 +13787,7 @@ def test_delete_operation_from_dict(): @pytest.mark.asyncio async def test_delete_operation_from_dict_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: @@ -13382,7 +13803,7 @@ async def test_delete_operation_from_dict_async(): def test_cancel_operation(transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13407,7 +13828,7 @@ def test_cancel_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_cancel_operation_async(transport: str = "grpc_asyncio"): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13431,7 +13852,7 @@ async def test_cancel_operation_async(transport: str = "grpc_asyncio"): def test_cancel_operation_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13460,7 +13881,7 @@ def test_cancel_operation_field_headers(): @pytest.mark.asyncio async def test_cancel_operation_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13487,7 +13908,7 @@ async def test_cancel_operation_field_headers_async(): def test_cancel_operation_from_dict(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -13505,7 +13926,7 @@ def test_cancel_operation_from_dict(): @pytest.mark.asyncio async def test_cancel_operation_from_dict_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: @@ -13521,7 +13942,7 @@ async def test_cancel_operation_from_dict_async(): def test_get_operation(transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13546,7 +13967,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13572,7 +13993,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13601,7 +14022,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13630,7 +14051,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -13648,7 +14069,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -13666,7 +14087,7 @@ async def test_get_operation_from_dict_async(): def test_list_operations(transport: str = "grpc"): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13691,7 +14112,7 @@ def test_list_operations(transport: str = "grpc"): @pytest.mark.asyncio async def test_list_operations_async(transport: str = "grpc_asyncio"): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -13717,7 +14138,7 @@ async def test_list_operations_async(transport: str = "grpc_asyncio"): def test_list_operations_field_headers(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13746,7 +14167,7 @@ def test_list_operations_field_headers(): @pytest.mark.asyncio async def test_list_operations_field_headers_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -13775,7 +14196,7 @@ async def test_list_operations_field_headers_async(): def test_list_operations_from_dict(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -13793,7 +14214,7 @@ def test_list_operations_from_dict(): @pytest.mark.asyncio async def test_list_operations_from_dict_async(): client = AzureClustersAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_operations), "__call__") as call: @@ -13817,7 +14238,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -13834,7 +14255,7 @@ def test_client_ctx(): ] for transport in transports: client = AzureClustersClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -13865,7 +14286,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, diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons/gapic_version.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons/gapic_version.py index 3d5b3af8dd99..360a0d13ebdd 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons/gapic_version.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.3.4" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/gapic_version.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/gapic_version.py index 3d5b3af8dd99..360a0d13ebdd 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/gapic_version.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "0.3.4" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/async_client.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/async_client.py index 51cb139e69d5..33176ff63d62 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/async_client.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/async_client.py @@ -38,9 +38,9 @@ from google.cloud.gsuiteaddons_v1 import gapic_version as package_version 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.protobuf import wrappers_pb2 # type: ignore @@ -92,8 +92,12 @@ class GSuiteAddOnsAsyncClient: _client: GSuiteAddOnsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = GSuiteAddOnsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = GSuiteAddOnsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = GSuiteAddOnsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = GSuiteAddOnsClient._DEFAULT_UNIVERSE authorization_path = staticmethod(GSuiteAddOnsClient.authorization_path) parse_authorization_path = staticmethod(GSuiteAddOnsClient.parse_authorization_path) @@ -202,6 +206,25 @@ def transport(self) -> GSuiteAddOnsTransport: """ 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(GSuiteAddOnsClient).get_transport_class, type(GSuiteAddOnsClient) ) @@ -214,7 +237,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the g suite add ons client. + """Instantiates the g suite add ons async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -225,23 +248,38 @@ def __init__( transport (Union[str, ~.GSuiteAddOnsTransport]): 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. @@ -348,6 +386,9 @@ async def sample_get_authorization(): 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, @@ -473,6 +514,9 @@ async def sample_create_deployment(): 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, @@ -575,6 +619,9 @@ async def sample_replace_deployment(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -677,6 +724,9 @@ async def sample_get_deployment(): 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, @@ -785,6 +835,9 @@ async def sample_list_deployments(): 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, @@ -890,6 +943,9 @@ async def sample_delete_deployment(): 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, @@ -986,6 +1042,9 @@ async def sample_install_deployment(): 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, @@ -1082,6 +1141,9 @@ async def sample_uninstall_deployment(): 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, @@ -1184,6 +1246,9 @@ async def sample_get_install_status(): 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, diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/client.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/client.py index 7817f834f196..6b8f578c436c 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/client.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.gsuiteaddons_v1 import gapic_version as package_version 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.protobuf import wrappers_pb2 # type: ignore @@ -160,11 +161,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 = "gsuiteaddons.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "gsuiteaddons.{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 @@ -347,7 +352,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 @@ -377,6 +382,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") @@ -410,6 +420,175 @@ 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 + + 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 + + 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 = GSuiteAddOnsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = GSuiteAddOnsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = GSuiteAddOnsClient._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 = GSuiteAddOnsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = GSuiteAddOnsClient._DEFAULT_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 GSuiteAddOnsClient._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, *, @@ -429,22 +608,32 @@ def __init__( transport (Union[str, GSuiteAddOnsTransport]): 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. @@ -455,17 +644,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = GSuiteAddOnsClient._read_environment_variables() + self._client_cert_source = GSuiteAddOnsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = GSuiteAddOnsClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -474,20 +680,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, GSuiteAddOnsTransport): + transport_provided = isinstance(transport, GSuiteAddOnsTransport) + if transport_provided: # transport is a GSuiteAddOnsTransport 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(GSuiteAddOnsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or GSuiteAddOnsClient._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( @@ -497,17 +713,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 get_authorization( @@ -605,6 +821,9 @@ def sample_get_authorization(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -730,6 +949,9 @@ def sample_create_deployment(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -832,6 +1054,9 @@ def sample_replace_deployment(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -934,6 +1159,9 @@ def sample_get_deployment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1042,6 +1270,9 @@ def sample_list_deployments(): gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1147,6 +1378,9 @@ def sample_delete_deployment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1243,6 +1477,9 @@ def sample_install_deployment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1339,6 +1576,9 @@ def sample_uninstall_deployment(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. rpc( request, @@ -1441,6 +1681,9 @@ def sample_get_install_status(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/base.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/base.py index 77edfe6bf2fa..955a6ad8ad73 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/base.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/base.py @@ -57,7 +57,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gsuiteaddons.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 @@ -120,6 +120,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-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc.py index ac71461d72e1..0c133ad1722e 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc.py @@ -98,7 +98,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gsuiteaddons.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-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc_asyncio.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc_asyncio.py index f6693e762457..de4d8cf4c060 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc_asyncio.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/grpc_asyncio.py @@ -143,7 +143,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gsuiteaddons.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-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/rest.py b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/rest.py index bdeec2505f1c..675e6660ea7a 100644 --- a/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/rest.py +++ b/packages/google-cloud-gsuiteaddons/google/cloud/gsuiteaddons_v1/services/g_suite_add_ons/transports/rest.py @@ -31,9 +31,9 @@ from requests import __version__ as requests_version 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.protobuf import empty_pb2 # type: ignore @@ -379,7 +379,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'gsuiteaddons.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-gsuiteaddons/noxfile.py b/packages/google-cloud-gsuiteaddons/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-gsuiteaddons/noxfile.py +++ b/packages/google-cloud-gsuiteaddons/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-gsuiteaddons/samples/generated_samples/snippet_metadata_google.cloud.gsuiteaddons.v1.json b/packages/google-cloud-gsuiteaddons/samples/generated_samples/snippet_metadata_google.cloud.gsuiteaddons.v1.json index 12644c23938c..1a4e67e71b2d 100644 --- a/packages/google-cloud-gsuiteaddons/samples/generated_samples/snippet_metadata_google.cloud.gsuiteaddons.v1.json +++ b/packages/google-cloud-gsuiteaddons/samples/generated_samples/snippet_metadata_google.cloud.gsuiteaddons.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-gsuiteaddons", - "version": "0.3.4" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-gsuiteaddons/tests/unit/gapic/gsuiteaddons_v1/test_g_suite_add_ons.py b/packages/google-cloud-gsuiteaddons/tests/unit/gapic/gsuiteaddons_v1/test_g_suite_add_ons.py index 1742935e2a30..31883298f13c 100644 --- a/packages/google-cloud-gsuiteaddons/tests/unit/gapic/gsuiteaddons_v1/test_g_suite_add_ons.py +++ b/packages/google-cloud-gsuiteaddons/tests/unit/gapic/gsuiteaddons_v1/test_g_suite_add_ons.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.apps.script.type.calendar.types import calendar_addon_manifest from google.apps.script.type.docs.types import docs_addon_manifest @@ -79,6 +79,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -105,6 +128,255 @@ def test__get_default_mtls_endpoint(): assert GSuiteAddOnsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert GSuiteAddOnsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert GSuiteAddOnsClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert GSuiteAddOnsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + GSuiteAddOnsClient._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 GSuiteAddOnsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert GSuiteAddOnsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert GSuiteAddOnsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + GSuiteAddOnsClient._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 GSuiteAddOnsClient._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 GSuiteAddOnsClient._get_client_cert_source(None, False) is None + assert ( + GSuiteAddOnsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + GSuiteAddOnsClient._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 ( + GSuiteAddOnsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + GSuiteAddOnsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + GSuiteAddOnsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GSuiteAddOnsClient), +) +@mock.patch.object( + GSuiteAddOnsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GSuiteAddOnsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = GSuiteAddOnsClient._DEFAULT_UNIVERSE + default_endpoint = GSuiteAddOnsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = GSuiteAddOnsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + GSuiteAddOnsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + GSuiteAddOnsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == GSuiteAddOnsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + GSuiteAddOnsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + GSuiteAddOnsClient._get_api_endpoint(None, None, default_universe, "always") + == GSuiteAddOnsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + GSuiteAddOnsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == GSuiteAddOnsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + GSuiteAddOnsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + GSuiteAddOnsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + GSuiteAddOnsClient._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 ( + GSuiteAddOnsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + GSuiteAddOnsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + GSuiteAddOnsClient._get_universe_domain(None, None) + == GSuiteAddOnsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + GSuiteAddOnsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (GSuiteAddOnsClient, transports.GSuiteAddOnsGrpcTransport, "grpc"), + (GSuiteAddOnsClient, transports.GSuiteAddOnsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -114,7 +386,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_g_suite_add_ons_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -166,7 +438,7 @@ def test_g_suite_add_ons_client_service_account_always_use_jwt( ], ) def test_g_suite_add_ons_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -215,19 +487,23 @@ def test_g_suite_add_ons_client_get_transport_class(): ], ) @mock.patch.object( - GSuiteAddOnsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(GSuiteAddOnsClient) + GSuiteAddOnsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GSuiteAddOnsClient), ) @mock.patch.object( GSuiteAddOnsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(GSuiteAddOnsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GSuiteAddOnsAsyncClient), ) def test_g_suite_add_ons_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(GSuiteAddOnsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -262,7 +538,9 @@ def test_g_suite_add_ons_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, @@ -292,15 +570,23 @@ def test_g_suite_add_ons_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") @@ -310,7 +596,9 @@ def test_g_suite_add_ons_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", @@ -328,7 +616,9 @@ def test_g_suite_add_ons_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, @@ -360,12 +650,14 @@ def test_g_suite_add_ons_client_client_options( ], ) @mock.patch.object( - GSuiteAddOnsClient, "DEFAULT_ENDPOINT", modify_default_endpoint(GSuiteAddOnsClient) + GSuiteAddOnsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GSuiteAddOnsClient), ) @mock.patch.object( GSuiteAddOnsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(GSuiteAddOnsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GSuiteAddOnsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_g_suite_add_ons_client_mtls_env_auto( @@ -388,7 +680,9 @@ def test_g_suite_add_ons_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 @@ -420,7 +714,9 @@ def test_g_suite_add_ons_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 @@ -454,7 +750,9 @@ def test_g_suite_add_ons_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, @@ -540,6 +838,116 @@ def test_g_suite_add_ons_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", [GSuiteAddOnsClient, GSuiteAddOnsAsyncClient]) +@mock.patch.object( + GSuiteAddOnsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GSuiteAddOnsClient), +) +@mock.patch.object( + GSuiteAddOnsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(GSuiteAddOnsAsyncClient), +) +def test_g_suite_add_ons_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = GSuiteAddOnsClient._DEFAULT_UNIVERSE + default_endpoint = GSuiteAddOnsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = GSuiteAddOnsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -566,7 +974,9 @@ def test_g_suite_add_ons_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, @@ -606,7 +1016,9 @@ def test_g_suite_add_ons_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, @@ -664,7 +1076,9 @@ def test_g_suite_add_ons_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, @@ -681,8 +1095,8 @@ def test_g_suite_add_ons_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -711,7 +1125,7 @@ def test_g_suite_add_ons_client_create_channel_credentials_file( ) def test_get_authorization(request_type, transport: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -747,7 +1161,7 @@ def test_get_authorization_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -766,7 +1180,7 @@ async def test_get_authorization_async( transport: str = "grpc_asyncio", request_type=gsuiteaddons.GetAuthorizationRequest ): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -807,7 +1221,7 @@ async def test_get_authorization_async_from_dict(): def test_get_authorization_field_headers(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -839,7 +1253,7 @@ def test_get_authorization_field_headers(): @pytest.mark.asyncio async def test_get_authorization_field_headers_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -872,7 +1286,7 @@ async def test_get_authorization_field_headers_async(): def test_get_authorization_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -898,7 +1312,7 @@ def test_get_authorization_flattened(): def test_get_authorization_flattened_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -913,7 +1327,7 @@ def test_get_authorization_flattened_error(): @pytest.mark.asyncio async def test_get_authorization_flattened_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -944,7 +1358,7 @@ async def test_get_authorization_flattened_async(): @pytest.mark.asyncio async def test_get_authorization_flattened_error_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -965,7 +1379,7 @@ async def test_get_authorization_flattened_error_async(): ) def test_create_deployment(request_type, transport: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1001,7 +1415,7 @@ def test_create_deployment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1020,7 +1434,7 @@ async def test_create_deployment_async( transport: str = "grpc_asyncio", request_type=gsuiteaddons.CreateDeploymentRequest ): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1061,7 +1475,7 @@ async def test_create_deployment_async_from_dict(): def test_create_deployment_field_headers(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1093,7 +1507,7 @@ def test_create_deployment_field_headers(): @pytest.mark.asyncio async def test_create_deployment_field_headers_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1126,7 +1540,7 @@ async def test_create_deployment_field_headers_async(): def test_create_deployment_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1160,7 +1574,7 @@ def test_create_deployment_flattened(): def test_create_deployment_flattened_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1177,7 +1591,7 @@ def test_create_deployment_flattened_error(): @pytest.mark.asyncio async def test_create_deployment_flattened_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1216,7 +1630,7 @@ async def test_create_deployment_flattened_async(): @pytest.mark.asyncio async def test_create_deployment_flattened_error_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1239,7 +1653,7 @@ async def test_create_deployment_flattened_error_async(): ) def test_replace_deployment(request_type, transport: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1275,7 +1689,7 @@ def test_replace_deployment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1294,7 +1708,7 @@ async def test_replace_deployment_async( transport: str = "grpc_asyncio", request_type=gsuiteaddons.ReplaceDeploymentRequest ): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1335,7 +1749,7 @@ async def test_replace_deployment_async_from_dict(): def test_replace_deployment_field_headers(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1367,7 +1781,7 @@ def test_replace_deployment_field_headers(): @pytest.mark.asyncio async def test_replace_deployment_field_headers_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1400,7 +1814,7 @@ async def test_replace_deployment_field_headers_async(): def test_replace_deployment_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1426,7 +1840,7 @@ def test_replace_deployment_flattened(): def test_replace_deployment_flattened_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1441,7 +1855,7 @@ def test_replace_deployment_flattened_error(): @pytest.mark.asyncio async def test_replace_deployment_flattened_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1472,7 +1886,7 @@ async def test_replace_deployment_flattened_async(): @pytest.mark.asyncio async def test_replace_deployment_flattened_error_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1493,7 +1907,7 @@ async def test_replace_deployment_flattened_error_async(): ) def test_get_deployment(request_type, transport: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1527,7 +1941,7 @@ def test_get_deployment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1544,7 +1958,7 @@ async def test_get_deployment_async( transport: str = "grpc_asyncio", request_type=gsuiteaddons.GetDeploymentRequest ): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1583,7 +1997,7 @@ async def test_get_deployment_async_from_dict(): def test_get_deployment_field_headers(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1613,7 +2027,7 @@ def test_get_deployment_field_headers(): @pytest.mark.asyncio async def test_get_deployment_field_headers_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1644,7 +2058,7 @@ async def test_get_deployment_field_headers_async(): def test_get_deployment_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1668,7 +2082,7 @@ def test_get_deployment_flattened(): def test_get_deployment_flattened_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1683,7 +2097,7 @@ def test_get_deployment_flattened_error(): @pytest.mark.asyncio async def test_get_deployment_flattened_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1712,7 +2126,7 @@ async def test_get_deployment_flattened_async(): @pytest.mark.asyncio async def test_get_deployment_flattened_error_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1733,7 +2147,7 @@ async def test_get_deployment_flattened_error_async(): ) def test_list_deployments(request_type, transport: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1763,7 +2177,7 @@ def test_list_deployments_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1780,7 +2194,7 @@ async def test_list_deployments_async( transport: str = "grpc_asyncio", request_type=gsuiteaddons.ListDeploymentsRequest ): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1815,7 +2229,7 @@ async def test_list_deployments_async_from_dict(): def test_list_deployments_field_headers(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1845,7 +2259,7 @@ def test_list_deployments_field_headers(): @pytest.mark.asyncio async def test_list_deployments_field_headers_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1876,7 +2290,7 @@ async def test_list_deployments_field_headers_async(): def test_list_deployments_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1900,7 +2314,7 @@ def test_list_deployments_flattened(): def test_list_deployments_flattened_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1915,7 +2329,7 @@ def test_list_deployments_flattened_error(): @pytest.mark.asyncio async def test_list_deployments_flattened_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1944,7 +2358,7 @@ async def test_list_deployments_flattened_async(): @pytest.mark.asyncio async def test_list_deployments_flattened_error_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1958,7 +2372,7 @@ async def test_list_deployments_flattened_error_async(): def test_list_deployments_pager(transport_name: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2008,7 +2422,7 @@ def test_list_deployments_pager(transport_name: str = "grpc"): def test_list_deployments_pages(transport_name: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -2050,7 +2464,7 @@ def test_list_deployments_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_deployments_async_pager(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2100,7 +2514,7 @@ async def test_list_deployments_async_pager(): @pytest.mark.asyncio async def test_list_deployments_async_pages(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2155,7 +2569,7 @@ async def test_list_deployments_async_pages(): ) def test_delete_deployment(request_type, transport: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2184,7 +2598,7 @@ def test_delete_deployment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2203,7 +2617,7 @@ async def test_delete_deployment_async( transport: str = "grpc_asyncio", request_type=gsuiteaddons.DeleteDeploymentRequest ): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2235,7 +2649,7 @@ async def test_delete_deployment_async_from_dict(): def test_delete_deployment_field_headers(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2267,7 +2681,7 @@ def test_delete_deployment_field_headers(): @pytest.mark.asyncio async def test_delete_deployment_field_headers_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2298,7 +2712,7 @@ async def test_delete_deployment_field_headers_async(): def test_delete_deployment_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2324,7 +2738,7 @@ def test_delete_deployment_flattened(): def test_delete_deployment_flattened_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2339,7 +2753,7 @@ def test_delete_deployment_flattened_error(): @pytest.mark.asyncio async def test_delete_deployment_flattened_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2368,7 +2782,7 @@ async def test_delete_deployment_flattened_async(): @pytest.mark.asyncio async def test_delete_deployment_flattened_error_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2389,7 +2803,7 @@ async def test_delete_deployment_flattened_error_async(): ) def test_install_deployment(request_type, transport: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2418,7 +2832,7 @@ def test_install_deployment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2437,7 +2851,7 @@ async def test_install_deployment_async( transport: str = "grpc_asyncio", request_type=gsuiteaddons.InstallDeploymentRequest ): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2469,7 +2883,7 @@ async def test_install_deployment_async_from_dict(): def test_install_deployment_field_headers(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2501,7 +2915,7 @@ def test_install_deployment_field_headers(): @pytest.mark.asyncio async def test_install_deployment_field_headers_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2532,7 +2946,7 @@ async def test_install_deployment_field_headers_async(): def test_install_deployment_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2558,7 +2972,7 @@ def test_install_deployment_flattened(): def test_install_deployment_flattened_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2573,7 +2987,7 @@ def test_install_deployment_flattened_error(): @pytest.mark.asyncio async def test_install_deployment_flattened_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2602,7 +3016,7 @@ async def test_install_deployment_flattened_async(): @pytest.mark.asyncio async def test_install_deployment_flattened_error_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2623,7 +3037,7 @@ async def test_install_deployment_flattened_error_async(): ) def test_uninstall_deployment(request_type, transport: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2652,7 +3066,7 @@ def test_uninstall_deployment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2672,7 +3086,7 @@ async def test_uninstall_deployment_async( request_type=gsuiteaddons.UninstallDeploymentRequest, ): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2704,7 +3118,7 @@ async def test_uninstall_deployment_async_from_dict(): def test_uninstall_deployment_field_headers(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2736,7 +3150,7 @@ def test_uninstall_deployment_field_headers(): @pytest.mark.asyncio async def test_uninstall_deployment_field_headers_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2767,7 +3181,7 @@ async def test_uninstall_deployment_field_headers_async(): def test_uninstall_deployment_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2793,7 +3207,7 @@ def test_uninstall_deployment_flattened(): def test_uninstall_deployment_flattened_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2808,7 +3222,7 @@ def test_uninstall_deployment_flattened_error(): @pytest.mark.asyncio async def test_uninstall_deployment_flattened_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2837,7 +3251,7 @@ async def test_uninstall_deployment_flattened_async(): @pytest.mark.asyncio async def test_uninstall_deployment_flattened_error_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -2858,7 +3272,7 @@ async def test_uninstall_deployment_flattened_error_async(): ) def test_get_install_status(request_type, transport: str = "grpc"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2890,7 +3304,7 @@ def test_get_install_status_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -2909,7 +3323,7 @@ async def test_get_install_status_async( transport: str = "grpc_asyncio", request_type=gsuiteaddons.GetInstallStatusRequest ): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2946,7 +3360,7 @@ async def test_get_install_status_async_from_dict(): def test_get_install_status_field_headers(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2978,7 +3392,7 @@ def test_get_install_status_field_headers(): @pytest.mark.asyncio async def test_get_install_status_field_headers_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -3011,7 +3425,7 @@ async def test_get_install_status_field_headers_async(): def test_get_install_status_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3037,7 +3451,7 @@ def test_get_install_status_flattened(): def test_get_install_status_flattened_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3052,7 +3466,7 @@ def test_get_install_status_flattened_error(): @pytest.mark.asyncio async def test_get_install_status_flattened_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3083,7 +3497,7 @@ async def test_get_install_status_flattened_async(): @pytest.mark.asyncio async def test_get_install_status_flattened_error_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -3104,7 +3518,7 @@ async def test_get_install_status_flattened_error_async(): ) def test_get_authorization_rest(request_type): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3159,7 +3573,7 @@ def test_get_authorization_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_authorization._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3168,7 +3582,7 @@ def test_get_authorization_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_authorization._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3177,7 +3591,7 @@ def test_get_authorization_rest_required_fields( assert jsonified_request["name"] == "name_value" client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3219,7 +3633,7 @@ def test_get_authorization_rest_required_fields( def test_get_authorization_rest_unset_required_fields(): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_authorization._get_unset_required_fields({}) @@ -3229,7 +3643,7 @@ def test_get_authorization_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_authorization_rest_interceptors(null_interceptor): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GSuiteAddOnsRestInterceptor(), @@ -3287,7 +3701,7 @@ def test_get_authorization_rest_bad_request( transport: str = "rest", request_type=gsuiteaddons.GetAuthorizationRequest ): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3309,7 +3723,7 @@ def test_get_authorization_rest_bad_request( def test_get_authorization_rest_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3349,7 +3763,7 @@ def test_get_authorization_rest_flattened(): def test_get_authorization_rest_flattened_error(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3364,7 +3778,7 @@ def test_get_authorization_rest_flattened_error(transport: str = "rest"): def test_get_authorization_rest_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3377,7 +3791,7 @@ def test_get_authorization_rest_error(): ) def test_create_deployment_rest(request_type): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3600,7 +4014,7 @@ def test_create_deployment_rest_required_fields( assert "deploymentId" not in jsonified_request unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3612,7 +4026,7 @@ def test_create_deployment_rest_required_fields( jsonified_request["deploymentId"] = "deployment_id_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_deployment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("deployment_id",)) @@ -3625,7 +4039,7 @@ def test_create_deployment_rest_required_fields( assert jsonified_request["deploymentId"] == "deployment_id_value" client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3674,7 +4088,7 @@ def test_create_deployment_rest_required_fields( def test_create_deployment_rest_unset_required_fields(): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_deployment._get_unset_required_fields({}) @@ -3693,7 +4107,7 @@ def test_create_deployment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_deployment_rest_interceptors(null_interceptor): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GSuiteAddOnsRestInterceptor(), @@ -3751,7 +4165,7 @@ def test_create_deployment_rest_bad_request( transport: str = "rest", request_type=gsuiteaddons.CreateDeploymentRequest ): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3773,7 +4187,7 @@ def test_create_deployment_rest_bad_request( def test_create_deployment_rest_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3815,7 +4229,7 @@ def test_create_deployment_rest_flattened(): def test_create_deployment_rest_flattened_error(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3832,7 +4246,7 @@ def test_create_deployment_rest_flattened_error(transport: str = "rest"): def test_create_deployment_rest_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3845,7 +4259,7 @@ def test_create_deployment_rest_error(): ) def test_replace_deployment_rest(request_type): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4065,21 +4479,21 @@ def test_replace_deployment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).replace_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).replace_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4122,7 +4536,7 @@ def test_replace_deployment_rest_required_fields( def test_replace_deployment_rest_unset_required_fields(): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.replace_deployment._get_unset_required_fields({}) @@ -4132,7 +4546,7 @@ def test_replace_deployment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_replace_deployment_rest_interceptors(null_interceptor): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GSuiteAddOnsRestInterceptor(), @@ -4190,7 +4604,7 @@ def test_replace_deployment_rest_bad_request( transport: str = "rest", request_type=gsuiteaddons.ReplaceDeploymentRequest ): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4212,7 +4626,7 @@ def test_replace_deployment_rest_bad_request( def test_replace_deployment_rest_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4255,7 +4669,7 @@ def test_replace_deployment_rest_flattened(): def test_replace_deployment_rest_flattened_error(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4270,7 +4684,7 @@ def test_replace_deployment_rest_flattened_error(transport: str = "rest"): def test_replace_deployment_rest_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4283,7 +4697,7 @@ def test_replace_deployment_rest_error(): ) def test_get_deployment_rest(request_type): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4338,7 +4752,7 @@ def test_get_deployment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4347,7 +4761,7 @@ def test_get_deployment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4356,7 +4770,7 @@ def test_get_deployment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4398,7 +4812,7 @@ def test_get_deployment_rest_required_fields( def test_get_deployment_rest_unset_required_fields(): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_deployment._get_unset_required_fields({}) @@ -4408,7 +4822,7 @@ def test_get_deployment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_deployment_rest_interceptors(null_interceptor): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GSuiteAddOnsRestInterceptor(), @@ -4466,7 +4880,7 @@ def test_get_deployment_rest_bad_request( transport: str = "rest", request_type=gsuiteaddons.GetDeploymentRequest ): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4488,7 +4902,7 @@ def test_get_deployment_rest_bad_request( def test_get_deployment_rest_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4528,7 +4942,7 @@ def test_get_deployment_rest_flattened(): def test_get_deployment_rest_flattened_error(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4543,7 +4957,7 @@ def test_get_deployment_rest_flattened_error(transport: str = "rest"): def test_get_deployment_rest_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -4556,7 +4970,7 @@ def test_get_deployment_rest_error(): ) def test_list_deployments_rest(request_type): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4607,7 +5021,7 @@ def test_list_deployments_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_deployments._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4616,7 +5030,7 @@ def test_list_deployments_rest_required_fields( jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_deployments._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -4632,7 +5046,7 @@ def test_list_deployments_rest_required_fields( assert jsonified_request["parent"] == "parent_value" client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -4674,7 +5088,7 @@ def test_list_deployments_rest_required_fields( def test_list_deployments_rest_unset_required_fields(): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_deployments._get_unset_required_fields({}) @@ -4692,7 +5106,7 @@ def test_list_deployments_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_deployments_rest_interceptors(null_interceptor): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GSuiteAddOnsRestInterceptor(), @@ -4750,7 +5164,7 @@ def test_list_deployments_rest_bad_request( transport: str = "rest", request_type=gsuiteaddons.ListDeploymentsRequest ): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4772,7 +5186,7 @@ def test_list_deployments_rest_bad_request( def test_list_deployments_rest_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4812,7 +5226,7 @@ def test_list_deployments_rest_flattened(): def test_list_deployments_rest_flattened_error(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4827,7 +5241,7 @@ def test_list_deployments_rest_flattened_error(transport: str = "rest"): def test_list_deployments_rest_pager(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4897,7 +5311,7 @@ def test_list_deployments_rest_pager(transport: str = "rest"): ) def test_delete_deployment_rest(request_type): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -4943,7 +5357,7 @@ def test_delete_deployment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -4952,7 +5366,7 @@ def test_delete_deployment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_deployment._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("etag",)) @@ -4963,7 +5377,7 @@ def test_delete_deployment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5002,7 +5416,7 @@ def test_delete_deployment_rest_required_fields( def test_delete_deployment_rest_unset_required_fields(): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_deployment._get_unset_required_fields({}) @@ -5012,7 +5426,7 @@ def test_delete_deployment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_deployment_rest_interceptors(null_interceptor): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GSuiteAddOnsRestInterceptor(), @@ -5062,7 +5476,7 @@ def test_delete_deployment_rest_bad_request( transport: str = "rest", request_type=gsuiteaddons.DeleteDeploymentRequest ): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5084,7 +5498,7 @@ def test_delete_deployment_rest_bad_request( def test_delete_deployment_rest_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5122,7 +5536,7 @@ def test_delete_deployment_rest_flattened(): def test_delete_deployment_rest_flattened_error(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5137,7 +5551,7 @@ def test_delete_deployment_rest_flattened_error(transport: str = "rest"): def test_delete_deployment_rest_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5150,7 +5564,7 @@ def test_delete_deployment_rest_error(): ) def test_install_deployment_rest(request_type): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5196,7 +5610,7 @@ def test_install_deployment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).install_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5205,7 +5619,7 @@ def test_install_deployment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).install_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5214,7 +5628,7 @@ def test_install_deployment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5254,7 +5668,7 @@ def test_install_deployment_rest_required_fields( def test_install_deployment_rest_unset_required_fields(): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.install_deployment._get_unset_required_fields({}) @@ -5264,7 +5678,7 @@ def test_install_deployment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_install_deployment_rest_interceptors(null_interceptor): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GSuiteAddOnsRestInterceptor(), @@ -5314,7 +5728,7 @@ def test_install_deployment_rest_bad_request( transport: str = "rest", request_type=gsuiteaddons.InstallDeploymentRequest ): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5336,7 +5750,7 @@ def test_install_deployment_rest_bad_request( def test_install_deployment_rest_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5375,7 +5789,7 @@ def test_install_deployment_rest_flattened(): def test_install_deployment_rest_flattened_error(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5390,7 +5804,7 @@ def test_install_deployment_rest_flattened_error(transport: str = "rest"): def test_install_deployment_rest_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5403,7 +5817,7 @@ def test_install_deployment_rest_error(): ) def test_uninstall_deployment_rest(request_type): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5449,7 +5863,7 @@ def test_uninstall_deployment_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).uninstall_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5458,7 +5872,7 @@ def test_uninstall_deployment_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).uninstall_deployment._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5467,7 +5881,7 @@ def test_uninstall_deployment_rest_required_fields( assert jsonified_request["name"] == "name_value" client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5507,7 +5921,7 @@ def test_uninstall_deployment_rest_required_fields( def test_uninstall_deployment_rest_unset_required_fields(): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.uninstall_deployment._get_unset_required_fields({}) @@ -5517,7 +5931,7 @@ def test_uninstall_deployment_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_uninstall_deployment_rest_interceptors(null_interceptor): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GSuiteAddOnsRestInterceptor(), @@ -5567,7 +5981,7 @@ def test_uninstall_deployment_rest_bad_request( transport: str = "rest", request_type=gsuiteaddons.UninstallDeploymentRequest ): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5589,7 +6003,7 @@ def test_uninstall_deployment_rest_bad_request( def test_uninstall_deployment_rest_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5628,7 +6042,7 @@ def test_uninstall_deployment_rest_flattened(): def test_uninstall_deployment_rest_flattened_error(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5643,7 +6057,7 @@ def test_uninstall_deployment_rest_flattened_error(transport: str = "rest"): def test_uninstall_deployment_rest_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -5656,7 +6070,7 @@ def test_uninstall_deployment_rest_error(): ) def test_get_install_status_rest(request_type): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5707,7 +6121,7 @@ def test_get_install_status_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_install_status._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5716,7 +6130,7 @@ def test_get_install_status_rest_required_fields( jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_install_status._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -5725,7 +6139,7 @@ def test_get_install_status_rest_required_fields( assert jsonified_request["name"] == "name_value" client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -5767,7 +6181,7 @@ def test_get_install_status_rest_required_fields( def test_get_install_status_rest_unset_required_fields(): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_install_status._get_unset_required_fields({}) @@ -5777,7 +6191,7 @@ def test_get_install_status_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_install_status_rest_interceptors(null_interceptor): transport = transports.GSuiteAddOnsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.GSuiteAddOnsRestInterceptor(), @@ -5835,7 +6249,7 @@ def test_get_install_status_rest_bad_request( transport: str = "rest", request_type=gsuiteaddons.GetInstallStatusRequest ): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5857,7 +6271,7 @@ def test_get_install_status_rest_bad_request( def test_get_install_status_rest_flattened(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -5899,7 +6313,7 @@ def test_get_install_status_rest_flattened(): def test_get_install_status_rest_flattened_error(transport: str = "rest"): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -5914,24 +6328,24 @@ def test_get_install_status_rest_flattened_error(transport: str = "rest"): def test_get_install_status_rest_error(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.GSuiteAddOnsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.GSuiteAddOnsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = GSuiteAddOnsClient( @@ -5941,7 +6355,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.GSuiteAddOnsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -5952,16 +6366,17 @@ 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 = GSuiteAddOnsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.GSuiteAddOnsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = GSuiteAddOnsClient( @@ -5973,7 +6388,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.GSuiteAddOnsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = GSuiteAddOnsClient(transport=transport) assert client.transport is transport @@ -5982,13 +6397,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.GSuiteAddOnsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.GSuiteAddOnsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -6005,7 +6420,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -6019,7 +6434,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = GSuiteAddOnsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -6027,7 +6442,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -6039,7 +6454,7 @@ def test_g_suite_add_ons_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.GSuiteAddOnsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -6051,7 +6466,7 @@ def test_g_suite_add_ons_base_transport(): ) as Transport: Transport.return_value = None transport = transports.GSuiteAddOnsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -6091,7 +6506,7 @@ def test_g_suite_add_ons_base_transport_with_credentials_file(): "google.cloud.gsuiteaddons_v1.services.g_suite_add_ons.transports.GSuiteAddOnsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.GSuiteAddOnsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -6110,7 +6525,7 @@ def test_g_suite_add_ons_base_transport_with_adc(): "google.cloud.gsuiteaddons_v1.services.g_suite_add_ons.transports.GSuiteAddOnsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.GSuiteAddOnsTransport() adc.assert_called_once() @@ -6118,7 +6533,7 @@ def test_g_suite_add_ons_base_transport_with_adc(): def test_g_suite_add_ons_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) GSuiteAddOnsClient() adc.assert_called_once_with( scopes=None, @@ -6138,7 +6553,7 @@ def test_g_suite_add_ons_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -6185,7 +6600,7 @@ def test_g_suite_add_ons_transport_create_channel(transport_class, grpc_helpers) ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -6210,7 +6625,7 @@ def test_g_suite_add_ons_transport_create_channel(transport_class, grpc_helpers) [transports.GSuiteAddOnsGrpcTransport, transports.GSuiteAddOnsGrpcAsyncIOTransport], ) def test_g_suite_add_ons_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -6248,7 +6663,7 @@ def test_g_suite_add_ons_grpc_transport_client_cert_source_for_mtls(transport_cl def test_g_suite_add_ons_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -6268,7 +6683,7 @@ def test_g_suite_add_ons_http_transport_client_cert_source_for_mtls(): ) def test_g_suite_add_ons_host_no_port(transport_name): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gsuiteaddons.googleapis.com" ), @@ -6291,7 +6706,7 @@ def test_g_suite_add_ons_host_no_port(transport_name): ) def test_g_suite_add_ons_host_with_port(transport_name): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="gsuiteaddons.googleapis.com:8000" ), @@ -6311,8 +6726,8 @@ def test_g_suite_add_ons_host_with_port(transport_name): ], ) def test_g_suite_add_ons_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = GSuiteAddOnsClient( credentials=creds1, transport=transport_name, @@ -6397,7 +6812,7 @@ def test_g_suite_add_ons_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -6646,7 +7061,7 @@ def test_client_with_default_client_info(): transports.GSuiteAddOnsTransport, "_prep_wrapped_messages" ) as prep: client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6656,7 +7071,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = GSuiteAddOnsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6665,7 +7080,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = GSuiteAddOnsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -6684,7 +7099,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -6701,7 +7116,7 @@ def test_client_ctx(): ] for transport in transports: client = GSuiteAddOnsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -6732,7 +7147,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, diff --git a/packages/google-cloud-iam/google/cloud/iam/gapic_version.py b/packages/google-cloud-iam/google/cloud/iam/gapic_version.py index 13e6df46e52c..360a0d13ebdd 100644 --- a/packages/google-cloud-iam/google/cloud/iam/gapic_version.py +++ b/packages/google-cloud-iam/google/cloud/iam/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.13.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials/gapic_version.py b/packages/google-cloud-iam/google/cloud/iam_credentials/gapic_version.py index 13e6df46e52c..360a0d13ebdd 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials/gapic_version.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.13.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/gapic_version.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/gapic_version.py index 13e6df46e52c..360a0d13ebdd 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/gapic_version.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.13.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py index 8a8db09e39a1..718f024b2f79 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/async_client.py @@ -38,9 +38,9 @@ from google.cloud.iam_credentials_v1 import gapic_version as package_version 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.protobuf import duration_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -67,8 +67,12 @@ class IAMCredentialsAsyncClient: _client: IAMCredentialsClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = IAMCredentialsClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = IAMCredentialsClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = IAMCredentialsClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = IAMCredentialsClient._DEFAULT_UNIVERSE service_account_path = staticmethod(IAMCredentialsClient.service_account_path) parse_service_account_path = staticmethod( @@ -177,6 +181,25 @@ def transport(self) -> IAMCredentialsTransport: """ 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(IAMCredentialsClient).get_transport_class, type(IAMCredentialsClient) ) @@ -189,7 +212,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the iam credentials client. + """Instantiates the iam credentials async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -200,23 +223,38 @@ def __init__( transport (Union[str, ~.IAMCredentialsTransport]): 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. @@ -381,6 +419,9 @@ async def sample_generate_access_token(): 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, @@ -539,6 +580,9 @@ async def sample_generate_id_token(): 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, @@ -683,6 +727,9 @@ async def sample_sign_blob(): 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, @@ -830,6 +877,9 @@ async def sample_sign_jwt(): 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, diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py index 7736e76da900..bd6fdd97d4fc 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.iam_credentials_v1 import gapic_version as package_version 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.protobuf import duration_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -137,11 +138,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 = "iamcredentials.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "iamcredentials.{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 @@ -290,7 +295,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 @@ -320,6 +325,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") @@ -353,6 +363,175 @@ 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 + + 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 + + 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 = IAMCredentialsClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = IAMCredentialsClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = IAMCredentialsClient._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 = IAMCredentialsClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = IAMCredentialsClient._DEFAULT_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 IAMCredentialsClient._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, *, @@ -372,22 +551,32 @@ def __init__( transport (Union[str, IAMCredentialsTransport]): 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. @@ -398,17 +587,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, + ) = IAMCredentialsClient._read_environment_variables() + self._client_cert_source = IAMCredentialsClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = IAMCredentialsClient._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" @@ -417,20 +623,33 @@ 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, IAMCredentialsTransport): + transport_provided = isinstance(transport, IAMCredentialsTransport) + if transport_provided: # transport is a IAMCredentialsTransport 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(IAMCredentialsTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = ( + self._api_endpoint + or IAMCredentialsClient._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( @@ -440,17 +659,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 generate_access_token( @@ -596,6 +815,9 @@ def sample_generate_access_token(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -744,6 +966,9 @@ def sample_generate_id_token(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -878,6 +1103,9 @@ def sample_sign_blob(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1015,6 +1243,9 @@ def sample_sign_jwt(): gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py index 4be434084149..84c9f7e137f4 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/base.py @@ -56,7 +56,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iamcredentials.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 @@ -119,6 +119,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-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py index 5c6467068f82..bf705095bcc2 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc.py @@ -72,7 +72,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iamcredentials.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-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc_asyncio.py index 3e1551daddba..848d3854798f 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/grpc_asyncio.py @@ -117,7 +117,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iamcredentials.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-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/rest.py b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/rest.py index 43faa3c26b70..be0b1fec4a0f 100644 --- a/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/rest.py +++ b/packages/google-cloud-iam/google/cloud/iam_credentials_v1/services/iam_credentials/transports/rest.py @@ -31,9 +31,9 @@ from requests import __version__ as requests_version 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.iam_credentials_v1.types import common @@ -236,7 +236,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iamcredentials.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-iam/google/cloud/iam_v2/gapic_version.py b/packages/google-cloud-iam/google/cloud/iam_v2/gapic_version.py index 13e6df46e52c..360a0d13ebdd 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/gapic_version.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.13.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/async_client.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/async_client.py index 554c68f20df8..f386e09dfc4d 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/async_client.py @@ -38,9 +38,9 @@ from google.cloud.iam_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -63,8 +63,12 @@ class PoliciesAsyncClient: _client: PoliciesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = PoliciesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = PoliciesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = PoliciesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = PoliciesClient._DEFAULT_UNIVERSE common_billing_account_path = staticmethod( PoliciesClient.common_billing_account_path @@ -161,6 +165,25 @@ def transport(self) -> PoliciesTransport: """ 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(PoliciesClient).get_transport_class, type(PoliciesClient) ) @@ -173,7 +196,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the policies client. + """Instantiates the policies async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -184,23 +207,38 @@ def __init__( transport (Union[str, ~.PoliciesTransport]): 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. @@ -329,6 +367,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, @@ -456,6 +497,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, @@ -606,6 +650,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, @@ -722,6 +769,9 @@ async def sample_update_policy(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -857,6 +907,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. response = await rpc( request, @@ -919,6 +972,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/client.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/client.py index 2aacc8e5f31e..35018070726e 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.iam_v2 import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -131,11 +132,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 = "iam.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "iam.{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 @@ -264,7 +269,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 @@ -294,6 +299,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") @@ -327,6 +337,175 @@ 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 + + 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 + + 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 = PoliciesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = PoliciesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = PoliciesClient._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 = PoliciesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = PoliciesClient._DEFAULT_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 PoliciesClient._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, *, @@ -346,22 +525,32 @@ def __init__( transport (Union[str, PoliciesTransport]): 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. @@ -372,17 +561,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = PoliciesClient._read_environment_variables() + self._client_cert_source = PoliciesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = PoliciesClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -391,20 +597,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, PoliciesTransport): + transport_provided = isinstance(transport, PoliciesTransport) + if transport_provided: # transport is a PoliciesTransport 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(PoliciesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or PoliciesClient._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( @@ -414,17 +630,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_policies( @@ -535,6 +751,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, @@ -653,6 +872,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, @@ -794,6 +1016,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, @@ -902,6 +1127,9 @@ def sample_update_policy(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1028,6 +1256,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. response = rpc( request, @@ -1103,6 +1334,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/base.py index 74181b7c0354..f7b9c7af09ef 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iam.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 @@ -121,6 +121,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-iam/google/cloud/iam_v2/services/policies/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc.py index 988efd864fa2..a474e1236424 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iam.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-iam/google/cloud/iam_v2/services/policies/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc_asyncio.py index f63250515aad..6df6168e3cea 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iam.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-iam/google/cloud/iam_v2/services/policies/transports/rest.py b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/rest.py index 1b2c180c9eb5..84f6752fb3fb 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/rest.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2/services/policies/transports/rest.py @@ -37,9 +37,9 @@ from requests import __version__ as requests_version 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.longrunning import operations_pb2 # type: ignore @@ -287,7 +287,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iam.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-iam/google/cloud/iam_v2beta/gapic_version.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/gapic_version.py index 13e6df46e52c..360a0d13ebdd 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/gapic_version.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "2.13.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/async_client.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/async_client.py index 2a7d6fece9e1..800959ab5aae 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/async_client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/async_client.py @@ -38,9 +38,9 @@ from google.cloud.iam_v2beta import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -63,8 +63,12 @@ class PoliciesAsyncClient: _client: PoliciesClient + # Copy defaults from the synchronous client for use here. + # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. DEFAULT_ENDPOINT = PoliciesClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = PoliciesClient.DEFAULT_MTLS_ENDPOINT + _DEFAULT_ENDPOINT_TEMPLATE = PoliciesClient._DEFAULT_ENDPOINT_TEMPLATE + _DEFAULT_UNIVERSE = PoliciesClient._DEFAULT_UNIVERSE common_billing_account_path = staticmethod( PoliciesClient.common_billing_account_path @@ -161,6 +165,25 @@ def transport(self) -> PoliciesTransport: """ 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(PoliciesClient).get_transport_class, type(PoliciesClient) ) @@ -173,7 +196,7 @@ def __init__( client_options: Optional[ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiates the policies client. + """Instantiates the policies async client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -184,23 +207,38 @@ def __init__( transport (Union[str, ~.PoliciesTransport]): 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. @@ -329,6 +367,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, @@ -456,6 +497,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, @@ -606,6 +650,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, @@ -722,6 +769,9 @@ async def sample_update_policy(): ), ) + # Validate the universe domain. + self._client._validate_universe_domain() + # Send the request. response = await rpc( request, @@ -857,6 +907,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. response = await rpc( request, @@ -919,6 +972,9 @@ async def get_operation( 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, diff --git a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/client.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/client.py index ebcce800d0af..0208e4d53d70 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/client.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/client.py @@ -28,6 +28,7 @@ Union, cast, ) +import warnings from google.api_core import client_options as client_options_lib from google.api_core import exceptions as core_exceptions @@ -42,9 +43,9 @@ from google.cloud.iam_v2beta import gapic_version as package_version 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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore @@ -129,11 +130,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 = "iam.googleapis.com" DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore DEFAULT_ENDPOINT ) + _DEFAULT_ENDPOINT_TEMPLATE = "iam.{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 @@ -262,7 +267,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 @@ -292,6 +297,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") @@ -325,6 +335,175 @@ 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 + + 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 + + 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 = PoliciesClient._DEFAULT_UNIVERSE + if universe_domain != _default_universe: + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {_default_universe}." + ) + api_endpoint = PoliciesClient.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = PoliciesClient._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 = PoliciesClient._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. + """ + if credentials: + credentials_universe = credentials.universe_domain + if client_universe != credentials_universe: + default_universe = PoliciesClient._DEFAULT_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 PoliciesClient._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, *, @@ -344,22 +523,32 @@ def __init__( transport (Union[str, PoliciesTransport]): 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. @@ -370,17 +559,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 + ) - api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( - client_options + universe_domain_opt = getattr(self._client_options, "universe_domain", None) + + ( + self._use_client_cert, + self._use_mtls_endpoint, + self._universe_domain_env, + ) = PoliciesClient._read_environment_variables() + self._client_cert_source = PoliciesClient._get_client_cert_source( + self._client_options.client_cert_source, self._use_client_cert + ) + self._universe_domain = PoliciesClient._get_universe_domain( + universe_domain_opt, self._universe_domain_env ) + self._api_endpoint = None # updated below, depending on `transport` + + # Initialize the universe domain validation. + self._is_universe_domain_valid = False - api_key_value = getattr(client_options, "api_key", None) + 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" @@ -389,20 +595,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, PoliciesTransport): + transport_provided = isinstance(transport, PoliciesTransport) + if transport_provided: # transport is a PoliciesTransport 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(PoliciesTransport, transport) + self._api_endpoint = self._transport.host + + self._api_endpoint = self._api_endpoint or PoliciesClient._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( @@ -412,17 +628,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_policies( @@ -533,6 +749,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, @@ -651,6 +870,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, @@ -792,6 +1014,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, @@ -900,6 +1125,9 @@ def sample_update_policy(): ), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, @@ -1026,6 +1254,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. response = rpc( request, @@ -1101,6 +1332,9 @@ def get_operation( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) + # Validate the universe domain. + self._validate_universe_domain() + # Send the request. response = rpc( request, diff --git a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/base.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/base.py index d50dd6215773..041bbaa97f6c 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/base.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/base.py @@ -58,7 +58,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iam.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 @@ -121,6 +121,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-iam/google/cloud/iam_v2beta/services/policies/transports/grpc.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc.py index 554c53097a6c..e99f86ea127a 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc.py @@ -66,7 +66,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iam.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-iam/google/cloud/iam_v2beta/services/policies/transports/grpc_asyncio.py b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc_asyncio.py index fe86597a1073..b0e95df3e61a 100644 --- a/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc_asyncio.py +++ b/packages/google-cloud-iam/google/cloud/iam_v2beta/services/policies/transports/grpc_asyncio.py @@ -111,7 +111,7 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'iam.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-iam/noxfile.py b/packages/google-cloud-iam/noxfile.py index 7d3551347c78..1e6cd48d0529 100644 --- a/packages/google-cloud-iam/noxfile.py +++ b/packages/google-cloud-iam/noxfile.py @@ -282,6 +282,15 @@ def docs(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "sphinx==4.5.0", "alabaster", "recommonmark", @@ -308,6 +317,15 @@ def docfx(session): session.install("-e", ".") session.install( + # We need to pin to specific versions of the `sphinxcontrib-*` packages + # which still support sphinx 4.x. + # See https://github.com/googleapis/sphinx-docfx-yaml/issues/344 + # and https://github.com/googleapis/sphinx-docfx-yaml/issues/345. + "sphinxcontrib-applehelp==1.0.4", + "sphinxcontrib-devhelp==1.0.2", + "sphinxcontrib-htmlhelp==2.0.1", + "sphinxcontrib-qthelp==1.0.3", + "sphinxcontrib-serializinghtml==1.1.5", "gcp-sphinx-docfx-yaml", "alabaster", "recommonmark", diff --git a/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.credentials.v1.json b/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.credentials.v1.json index 48d02d58b90c..1e024f5ce6ce 100644 --- a/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.credentials.v1.json +++ b/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.credentials.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-iam", - "version": "2.13.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.v2.json b/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.v2.json index c68be779b856..41cce8e24813 100644 --- a/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.v2.json +++ b/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.v2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-iam", - "version": "2.13.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.v2beta.json b/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.v2beta.json index a521edc37538..5c06ffb6bc77 100644 --- a/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.v2beta.json +++ b/packages/google-cloud-iam/samples/generated_samples/snippet_metadata_google.iam.v2beta.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-iam", - "version": "2.13.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py b/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py index 0c8e99e62cf8..481a43bcf6df 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_credentials_v1/test_iam_credentials.py @@ -27,7 +27,7 @@ import math from google.api_core import gapic_v1, grpc_helpers, grpc_helpers_async, path_template -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions import google.auth from google.auth import credentials as ga_credentials @@ -67,6 +67,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -96,6 +119,267 @@ def test__get_default_mtls_endpoint(): ) +def test__read_environment_variables(): + assert IAMCredentialsClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert IAMCredentialsClient._read_environment_variables() == ( + True, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert IAMCredentialsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + IAMCredentialsClient._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 IAMCredentialsClient._read_environment_variables() == ( + False, + "never", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert IAMCredentialsClient._read_environment_variables() == ( + False, + "always", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert IAMCredentialsClient._read_environment_variables() == ( + False, + "auto", + None, + ) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + IAMCredentialsClient._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 IAMCredentialsClient._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 IAMCredentialsClient._get_client_cert_source(None, False) is None + assert ( + IAMCredentialsClient._get_client_cert_source(mock_provided_cert_source, False) + is None + ) + assert ( + IAMCredentialsClient._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 ( + IAMCredentialsClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + IAMCredentialsClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + IAMCredentialsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IAMCredentialsClient), +) +@mock.patch.object( + IAMCredentialsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IAMCredentialsAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = IAMCredentialsClient._DEFAULT_UNIVERSE + default_endpoint = IAMCredentialsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = IAMCredentialsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + IAMCredentialsClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + IAMCredentialsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == IAMCredentialsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + IAMCredentialsClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + IAMCredentialsClient._get_api_endpoint(None, None, default_universe, "always") + == IAMCredentialsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + IAMCredentialsClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == IAMCredentialsClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + IAMCredentialsClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + IAMCredentialsClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + IAMCredentialsClient._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 ( + IAMCredentialsClient._get_universe_domain( + client_universe_domain, universe_domain_env + ) + == client_universe_domain + ) + assert ( + IAMCredentialsClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + IAMCredentialsClient._get_universe_domain(None, None) + == IAMCredentialsClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + IAMCredentialsClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (IAMCredentialsClient, transports.IAMCredentialsGrpcTransport, "grpc"), + (IAMCredentialsClient, transports.IAMCredentialsRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -105,7 +389,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_iam_credentials_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -157,7 +441,7 @@ def test_iam_credentials_client_service_account_always_use_jwt( ], ) def test_iam_credentials_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -207,20 +491,22 @@ def test_iam_credentials_client_get_transport_class(): ) @mock.patch.object( IAMCredentialsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(IAMCredentialsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IAMCredentialsClient), ) @mock.patch.object( IAMCredentialsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(IAMCredentialsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IAMCredentialsAsyncClient), ) def test_iam_credentials_client_client_options( client_class, transport_class, transport_name ): # Check that if channel is provided we won't create a new one. with mock.patch.object(IAMCredentialsClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -255,7 +541,9 @@ def test_iam_credentials_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, @@ -285,15 +573,23 @@ def test_iam_credentials_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") @@ -303,7 +599,9 @@ def test_iam_credentials_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", @@ -321,7 +619,9 @@ def test_iam_credentials_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, @@ -354,13 +654,13 @@ def test_iam_credentials_client_client_options( ) @mock.patch.object( IAMCredentialsClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(IAMCredentialsClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IAMCredentialsClient), ) @mock.patch.object( IAMCredentialsAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(IAMCredentialsAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IAMCredentialsAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_iam_credentials_client_mtls_env_auto( @@ -383,7 +683,9 @@ def test_iam_credentials_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 @@ -415,7 +717,9 @@ def test_iam_credentials_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 @@ -449,7 +753,9 @@ def test_iam_credentials_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, @@ -539,6 +845,118 @@ def test_iam_credentials_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", [IAMCredentialsClient, IAMCredentialsAsyncClient] +) +@mock.patch.object( + IAMCredentialsClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IAMCredentialsClient), +) +@mock.patch.object( + IAMCredentialsAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(IAMCredentialsAsyncClient), +) +def test_iam_credentials_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = IAMCredentialsClient._DEFAULT_UNIVERSE + default_endpoint = IAMCredentialsClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = IAMCredentialsClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -565,7 +983,9 @@ def test_iam_credentials_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, @@ -605,7 +1025,9 @@ def test_iam_credentials_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, @@ -665,7 +1087,9 @@ def test_iam_credentials_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, @@ -682,8 +1106,8 @@ def test_iam_credentials_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -712,7 +1136,7 @@ def test_iam_credentials_client_create_channel_credentials_file( ) def test_generate_access_token(request_type, transport: str = "grpc"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -744,7 +1168,7 @@ def test_generate_access_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -763,7 +1187,7 @@ async def test_generate_access_token_async( transport: str = "grpc_asyncio", request_type=common.GenerateAccessTokenRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -800,7 +1224,7 @@ async def test_generate_access_token_async_from_dict(): def test_generate_access_token_field_headers(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -832,7 +1256,7 @@ def test_generate_access_token_field_headers(): @pytest.mark.asyncio async def test_generate_access_token_field_headers_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -865,7 +1289,7 @@ async def test_generate_access_token_field_headers_async(): def test_generate_access_token_flattened(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -903,7 +1327,7 @@ def test_generate_access_token_flattened(): def test_generate_access_token_flattened_error(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -921,7 +1345,7 @@ def test_generate_access_token_flattened_error(): @pytest.mark.asyncio async def test_generate_access_token_flattened_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -964,7 +1388,7 @@ async def test_generate_access_token_flattened_async(): @pytest.mark.asyncio async def test_generate_access_token_flattened_error_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -988,7 +1412,7 @@ async def test_generate_access_token_flattened_error_async(): ) def test_generate_id_token(request_type, transport: str = "grpc"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1020,7 +1444,7 @@ def test_generate_id_token_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1039,7 +1463,7 @@ async def test_generate_id_token_async( transport: str = "grpc_asyncio", request_type=common.GenerateIdTokenRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1076,7 +1500,7 @@ async def test_generate_id_token_async_from_dict(): def test_generate_id_token_field_headers(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1108,7 +1532,7 @@ def test_generate_id_token_field_headers(): @pytest.mark.asyncio async def test_generate_id_token_field_headers_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1141,7 +1565,7 @@ async def test_generate_id_token_field_headers_async(): def test_generate_id_token_flattened(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1179,7 +1603,7 @@ def test_generate_id_token_flattened(): def test_generate_id_token_flattened_error(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1197,7 +1621,7 @@ def test_generate_id_token_flattened_error(): @pytest.mark.asyncio async def test_generate_id_token_flattened_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1240,7 +1664,7 @@ async def test_generate_id_token_flattened_async(): @pytest.mark.asyncio async def test_generate_id_token_flattened_error_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1264,7 +1688,7 @@ async def test_generate_id_token_flattened_error_async(): ) def test_sign_blob(request_type, transport: str = "grpc"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1296,7 +1720,7 @@ def test_sign_blob_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1313,7 +1737,7 @@ async def test_sign_blob_async( transport: str = "grpc_asyncio", request_type=common.SignBlobRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1350,7 +1774,7 @@ async def test_sign_blob_async_from_dict(): def test_sign_blob_field_headers(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1380,7 +1804,7 @@ def test_sign_blob_field_headers(): @pytest.mark.asyncio async def test_sign_blob_field_headers_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1411,7 +1835,7 @@ async def test_sign_blob_field_headers_async(): def test_sign_blob_flattened(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1443,7 +1867,7 @@ def test_sign_blob_flattened(): def test_sign_blob_flattened_error(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1460,7 +1884,7 @@ def test_sign_blob_flattened_error(): @pytest.mark.asyncio async def test_sign_blob_flattened_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1497,7 +1921,7 @@ async def test_sign_blob_flattened_async(): @pytest.mark.asyncio async def test_sign_blob_flattened_error_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1520,7 +1944,7 @@ async def test_sign_blob_flattened_error_async(): ) def test_sign_jwt(request_type, transport: str = "grpc"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1552,7 +1976,7 @@ def test_sign_jwt_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1569,7 +1993,7 @@ async def test_sign_jwt_async( transport: str = "grpc_asyncio", request_type=common.SignJwtRequest ): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1606,7 +2030,7 @@ async def test_sign_jwt_async_from_dict(): def test_sign_jwt_field_headers(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1636,7 +2060,7 @@ def test_sign_jwt_field_headers(): @pytest.mark.asyncio async def test_sign_jwt_field_headers_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1667,7 +2091,7 @@ async def test_sign_jwt_field_headers_async(): def test_sign_jwt_flattened(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1699,7 +2123,7 @@ def test_sign_jwt_flattened(): def test_sign_jwt_flattened_error(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1716,7 +2140,7 @@ def test_sign_jwt_flattened_error(): @pytest.mark.asyncio async def test_sign_jwt_flattened_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1753,7 +2177,7 @@ async def test_sign_jwt_flattened_async(): @pytest.mark.asyncio async def test_sign_jwt_flattened_error_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1776,7 +2200,7 @@ async def test_sign_jwt_flattened_error_async(): ) def test_generate_access_token_rest(request_type): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -1828,7 +2252,7 @@ def test_generate_access_token_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_access_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1838,7 +2262,7 @@ def test_generate_access_token_rest_required_fields( jsonified_request["scope"] = "scope_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_access_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -1849,7 +2273,7 @@ def test_generate_access_token_rest_required_fields( assert jsonified_request["scope"] == "scope_value" client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -1892,7 +2316,7 @@ def test_generate_access_token_rest_required_fields( def test_generate_access_token_rest_unset_required_fields(): transport = transports.IAMCredentialsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_access_token._get_unset_required_fields({}) @@ -1910,7 +2334,7 @@ def test_generate_access_token_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_access_token_rest_interceptors(null_interceptor): transport = transports.IAMCredentialsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IAMCredentialsRestInterceptor(), @@ -1968,7 +2392,7 @@ def test_generate_access_token_rest_bad_request( transport: str = "rest", request_type=common.GenerateAccessTokenRequest ): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1990,7 +2414,7 @@ def test_generate_access_token_rest_bad_request( def test_generate_access_token_rest_flattened(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2035,7 +2459,7 @@ def test_generate_access_token_rest_flattened(): def test_generate_access_token_rest_flattened_error(transport: str = "rest"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2053,7 +2477,7 @@ def test_generate_access_token_rest_flattened_error(transport: str = "rest"): def test_generate_access_token_rest_error(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2066,7 +2490,7 @@ def test_generate_access_token_rest_error(): ) def test_generate_id_token_rest(request_type): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2118,7 +2542,7 @@ def test_generate_id_token_rest_required_fields( # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_id_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2128,7 +2552,7 @@ def test_generate_id_token_rest_required_fields( jsonified_request["audience"] = "audience_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).generate_id_token._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2139,7 +2563,7 @@ def test_generate_id_token_rest_required_fields( assert jsonified_request["audience"] == "audience_value" client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2182,7 +2606,7 @@ def test_generate_id_token_rest_required_fields( def test_generate_id_token_rest_unset_required_fields(): transport = transports.IAMCredentialsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.generate_id_token._get_unset_required_fields({}) @@ -2200,7 +2624,7 @@ def test_generate_id_token_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_generate_id_token_rest_interceptors(null_interceptor): transport = transports.IAMCredentialsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IAMCredentialsRestInterceptor(), @@ -2256,7 +2680,7 @@ def test_generate_id_token_rest_bad_request( transport: str = "rest", request_type=common.GenerateIdTokenRequest ): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2278,7 +2702,7 @@ def test_generate_id_token_rest_bad_request( def test_generate_id_token_rest_flattened(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2323,7 +2747,7 @@ def test_generate_id_token_rest_flattened(): def test_generate_id_token_rest_flattened_error(transport: str = "rest"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2341,7 +2765,7 @@ def test_generate_id_token_rest_flattened_error(transport: str = "rest"): def test_generate_id_token_rest_error(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2354,7 +2778,7 @@ def test_generate_id_token_rest_error(): ) def test_sign_blob_rest(request_type): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2406,7 +2830,7 @@ def test_sign_blob_rest_required_fields(request_type=common.SignBlobRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).sign_blob._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2416,7 +2840,7 @@ def test_sign_blob_rest_required_fields(request_type=common.SignBlobRequest): jsonified_request["payload"] = b"payload_blob" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).sign_blob._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2427,7 +2851,7 @@ def test_sign_blob_rest_required_fields(request_type=common.SignBlobRequest): assert jsonified_request["payload"] == b"payload_blob" client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2470,7 +2894,7 @@ def test_sign_blob_rest_required_fields(request_type=common.SignBlobRequest): def test_sign_blob_rest_unset_required_fields(): transport = transports.IAMCredentialsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.sign_blob._get_unset_required_fields({}) @@ -2488,7 +2912,7 @@ def test_sign_blob_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_sign_blob_rest_interceptors(null_interceptor): transport = transports.IAMCredentialsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IAMCredentialsRestInterceptor(), @@ -2544,7 +2968,7 @@ def test_sign_blob_rest_bad_request( transport: str = "rest", request_type=common.SignBlobRequest ): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2566,7 +2990,7 @@ def test_sign_blob_rest_bad_request( def test_sign_blob_rest_flattened(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2610,7 +3034,7 @@ def test_sign_blob_rest_flattened(): def test_sign_blob_rest_flattened_error(transport: str = "rest"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2627,7 +3051,7 @@ def test_sign_blob_rest_flattened_error(transport: str = "rest"): def test_sign_blob_rest_error(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2640,7 +3064,7 @@ def test_sign_blob_rest_error(): ) def test_sign_jwt_rest(request_type): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2692,7 +3116,7 @@ def test_sign_jwt_rest_required_fields(request_type=common.SignJwtRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).sign_jwt._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2702,7 +3126,7 @@ def test_sign_jwt_rest_required_fields(request_type=common.SignJwtRequest): jsonified_request["payload"] = "payload_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).sign_jwt._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2713,7 +3137,7 @@ def test_sign_jwt_rest_required_fields(request_type=common.SignJwtRequest): assert jsonified_request["payload"] == "payload_value" client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2756,7 +3180,7 @@ def test_sign_jwt_rest_required_fields(request_type=common.SignJwtRequest): def test_sign_jwt_rest_unset_required_fields(): transport = transports.IAMCredentialsRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.sign_jwt._get_unset_required_fields({}) @@ -2774,7 +3198,7 @@ def test_sign_jwt_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_sign_jwt_rest_interceptors(null_interceptor): transport = transports.IAMCredentialsRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.IAMCredentialsRestInterceptor(), @@ -2830,7 +3254,7 @@ def test_sign_jwt_rest_bad_request( transport: str = "rest", request_type=common.SignJwtRequest ): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2852,7 +3276,7 @@ def test_sign_jwt_rest_bad_request( def test_sign_jwt_rest_flattened(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2896,7 +3320,7 @@ def test_sign_jwt_rest_flattened(): def test_sign_jwt_rest_flattened_error(transport: str = "rest"): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2913,24 +3337,24 @@ def test_sign_jwt_rest_flattened_error(transport: str = "rest"): def test_sign_jwt_rest_error(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.IAMCredentialsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.IAMCredentialsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = IAMCredentialsClient( @@ -2940,7 +3364,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.IAMCredentialsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -2951,16 +3375,17 @@ 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 = IAMCredentialsClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.IAMCredentialsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = IAMCredentialsClient( @@ -2972,7 +3397,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.IAMCredentialsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = IAMCredentialsClient(transport=transport) assert client.transport is transport @@ -2981,13 +3406,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.IAMCredentialsGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.IAMCredentialsGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3004,7 +3429,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3018,7 +3443,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = IAMCredentialsClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3026,7 +3451,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3038,7 +3463,7 @@ def test_iam_credentials_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.IAMCredentialsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3050,7 +3475,7 @@ def test_iam_credentials_base_transport(): ) as Transport: Transport.return_value = None transport = transports.IAMCredentialsTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3085,7 +3510,7 @@ def test_iam_credentials_base_transport_with_credentials_file(): "google.cloud.iam_credentials_v1.services.iam_credentials.transports.IAMCredentialsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.IAMCredentialsTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3104,7 +3529,7 @@ def test_iam_credentials_base_transport_with_adc(): "google.cloud.iam_credentials_v1.services.iam_credentials.transports.IAMCredentialsTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.IAMCredentialsTransport() adc.assert_called_once() @@ -3112,7 +3537,7 @@ def test_iam_credentials_base_transport_with_adc(): def test_iam_credentials_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) IAMCredentialsClient() adc.assert_called_once_with( scopes=None, @@ -3132,7 +3557,7 @@ def test_iam_credentials_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -3179,7 +3604,7 @@ def test_iam_credentials_transport_create_channel(transport_class, grpc_helpers) ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3207,7 +3632,7 @@ def test_iam_credentials_transport_create_channel(transport_class, grpc_helpers) ], ) def test_iam_credentials_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3245,7 +3670,7 @@ def test_iam_credentials_grpc_transport_client_cert_source_for_mtls(transport_cl def test_iam_credentials_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -3265,7 +3690,7 @@ def test_iam_credentials_http_transport_client_cert_source_for_mtls(): ) def test_iam_credentials_host_no_port(transport_name): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="iamcredentials.googleapis.com" ), @@ -3288,7 +3713,7 @@ def test_iam_credentials_host_no_port(transport_name): ) def test_iam_credentials_host_with_port(transport_name): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="iamcredentials.googleapis.com:8000" ), @@ -3308,8 +3733,8 @@ def test_iam_credentials_host_with_port(transport_name): ], ) def test_iam_credentials_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = IAMCredentialsClient( credentials=creds1, transport=transport_name, @@ -3382,7 +3807,7 @@ def test_iam_credentials_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -3591,7 +4016,7 @@ def test_client_with_default_client_info(): transports.IAMCredentialsTransport, "_prep_wrapped_messages" ) as prep: client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3601,7 +4026,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = IAMCredentialsClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3610,7 +4035,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = IAMCredentialsAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -3629,7 +4054,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3646,7 +4071,7 @@ def test_client_ctx(): ] for transport in transports: client = IAMCredentialsClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -3677,7 +4102,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, diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_v2/test_policies.py b/packages/google-cloud-iam/tests/unit/gapic/iam_v2/test_policies.py index 6dfd9044a93b..fac5a60fbadb 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_v2/test_policies.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_v2/test_policies.py @@ -35,7 +35,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -80,6 +80,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -104,6 +127,244 @@ def test__get_default_mtls_endpoint(): assert PoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert PoliciesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert PoliciesClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert PoliciesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + PoliciesClient._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 PoliciesClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert PoliciesClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert PoliciesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + PoliciesClient._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 PoliciesClient._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 PoliciesClient._get_client_cert_source(None, False) is None + assert ( + PoliciesClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + PoliciesClient._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 ( + PoliciesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + PoliciesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + PoliciesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesClient), +) +@mock.patch.object( + PoliciesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = PoliciesClient._DEFAULT_UNIVERSE + default_endpoint = PoliciesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = PoliciesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + PoliciesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + PoliciesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == PoliciesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + PoliciesClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + PoliciesClient._get_api_endpoint(None, None, default_universe, "always") + == PoliciesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + PoliciesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == PoliciesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + PoliciesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + PoliciesClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + PoliciesClient._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 ( + PoliciesClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + PoliciesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + PoliciesClient._get_universe_domain(None, None) + == PoliciesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + PoliciesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (PoliciesClient, transports.PoliciesGrpcTransport, "grpc"), + (PoliciesClient, transports.PoliciesRestTransport, "rest"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -113,7 +374,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_policies_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -165,7 +426,7 @@ def test_policies_client_service_account_always_use_jwt( ], ) def test_policies_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -210,17 +471,21 @@ def test_policies_client_get_transport_class(): ], ) @mock.patch.object( - PoliciesClient, "DEFAULT_ENDPOINT", modify_default_endpoint(PoliciesClient) + PoliciesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesClient), ) @mock.patch.object( PoliciesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(PoliciesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesAsyncClient), ) def test_policies_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(PoliciesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -255,7 +520,9 @@ def test_policies_client_client_options(client_class, transport_class, transport 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, @@ -285,15 +552,23 @@ def test_policies_client_client_options(client_class, transport_class, transport # 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") @@ -303,7 +578,9 @@ def test_policies_client_client_options(client_class, transport_class, transport 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", @@ -321,7 +598,9 @@ def test_policies_client_client_options(client_class, transport_class, transport 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, @@ -353,12 +632,14 @@ def test_policies_client_client_options(client_class, transport_class, transport ], ) @mock.patch.object( - PoliciesClient, "DEFAULT_ENDPOINT", modify_default_endpoint(PoliciesClient) + PoliciesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesClient), ) @mock.patch.object( PoliciesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(PoliciesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_policies_client_mtls_env_auto( @@ -381,7 +662,9 @@ def test_policies_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 @@ -413,7 +696,9 @@ def test_policies_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 @@ -447,7 +732,9 @@ def test_policies_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, @@ -533,6 +820,116 @@ def test_policies_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", [PoliciesClient, PoliciesAsyncClient]) +@mock.patch.object( + PoliciesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesClient), +) +@mock.patch.object( + PoliciesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesAsyncClient), +) +def test_policies_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = PoliciesClient._DEFAULT_UNIVERSE + default_endpoint = PoliciesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = PoliciesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -555,7 +952,9 @@ def test_policies_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, @@ -590,7 +989,9 @@ def test_policies_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, @@ -643,7 +1044,9 @@ def test_policies_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, @@ -660,8 +1063,8 @@ def test_policies_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -690,7 +1093,7 @@ def test_policies_client_create_channel_credentials_file( ) def test_list_policies(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -720,7 +1123,7 @@ def test_list_policies_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -737,7 +1140,7 @@ async def test_list_policies_async( transport: str = "grpc_asyncio", request_type=policy.ListPoliciesRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -772,7 +1175,7 @@ async def test_list_policies_async_from_dict(): def test_list_policies_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -802,7 +1205,7 @@ def test_list_policies_field_headers(): @pytest.mark.asyncio async def test_list_policies_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -833,7 +1236,7 @@ async def test_list_policies_field_headers_async(): def test_list_policies_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -857,7 +1260,7 @@ def test_list_policies_flattened(): def test_list_policies_flattened_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -872,7 +1275,7 @@ def test_list_policies_flattened_error(): @pytest.mark.asyncio async def test_list_policies_flattened_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -901,7 +1304,7 @@ async def test_list_policies_flattened_async(): @pytest.mark.asyncio async def test_list_policies_flattened_error_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -915,7 +1318,7 @@ async def test_list_policies_flattened_error_async(): def test_list_policies_pager(transport_name: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -965,7 +1368,7 @@ def test_list_policies_pager(transport_name: str = "grpc"): def test_list_policies_pages(transport_name: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -1007,7 +1410,7 @@ def test_list_policies_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_policies_async_pager(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1057,7 +1460,7 @@ async def test_list_policies_async_pager(): @pytest.mark.asyncio async def test_list_policies_async_pages(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1112,7 +1515,7 @@ async def test_list_policies_async_pages(): ) def test_get_policy(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1152,7 +1555,7 @@ def test_get_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1169,7 +1572,7 @@ async def test_get_policy_async( transport: str = "grpc_asyncio", request_type=policy.GetPolicyRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1214,7 +1617,7 @@ async def test_get_policy_async_from_dict(): def test_get_policy_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1244,7 +1647,7 @@ def test_get_policy_field_headers(): @pytest.mark.asyncio async def test_get_policy_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1273,7 +1676,7 @@ async def test_get_policy_field_headers_async(): def test_get_policy_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1297,7 +1700,7 @@ def test_get_policy_flattened(): def test_get_policy_flattened_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1312,7 +1715,7 @@ def test_get_policy_flattened_error(): @pytest.mark.asyncio async def test_get_policy_flattened_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1339,7 +1742,7 @@ async def test_get_policy_flattened_async(): @pytest.mark.asyncio async def test_get_policy_flattened_error_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1360,7 +1763,7 @@ async def test_get_policy_flattened_error_async(): ) def test_create_policy(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1387,7 +1790,7 @@ def test_create_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1404,7 +1807,7 @@ async def test_create_policy_async( transport: str = "grpc_asyncio", request_type=gi_policy.CreatePolicyRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1436,7 +1839,7 @@ async def test_create_policy_async_from_dict(): def test_create_policy_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1466,7 +1869,7 @@ def test_create_policy_field_headers(): @pytest.mark.asyncio async def test_create_policy_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1497,7 +1900,7 @@ async def test_create_policy_field_headers_async(): def test_create_policy_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1529,7 +1932,7 @@ def test_create_policy_flattened(): def test_create_policy_flattened_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1546,7 +1949,7 @@ def test_create_policy_flattened_error(): @pytest.mark.asyncio async def test_create_policy_flattened_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1583,7 +1986,7 @@ async def test_create_policy_flattened_async(): @pytest.mark.asyncio async def test_create_policy_flattened_error_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1606,7 +2009,7 @@ async def test_create_policy_flattened_error_async(): ) def test_update_policy(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1633,7 +2036,7 @@ def test_update_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1650,7 +2053,7 @@ async def test_update_policy_async( transport: str = "grpc_asyncio", request_type=policy.UpdatePolicyRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1682,7 +2085,7 @@ async def test_update_policy_async_from_dict(): def test_update_policy_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1712,7 +2115,7 @@ def test_update_policy_field_headers(): @pytest.mark.asyncio async def test_update_policy_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1750,7 +2153,7 @@ async def test_update_policy_field_headers_async(): ) def test_delete_policy(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1777,7 +2180,7 @@ def test_delete_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1794,7 +2197,7 @@ async def test_delete_policy_async( transport: str = "grpc_asyncio", request_type=policy.DeletePolicyRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1826,7 +2229,7 @@ async def test_delete_policy_async_from_dict(): def test_delete_policy_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1856,7 +2259,7 @@ def test_delete_policy_field_headers(): @pytest.mark.asyncio async def test_delete_policy_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1887,7 +2290,7 @@ async def test_delete_policy_field_headers_async(): def test_delete_policy_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1911,7 +2314,7 @@ def test_delete_policy_flattened(): def test_delete_policy_flattened_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1926,7 +2329,7 @@ def test_delete_policy_flattened_error(): @pytest.mark.asyncio async def test_delete_policy_flattened_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1955,7 +2358,7 @@ async def test_delete_policy_flattened_async(): @pytest.mark.asyncio async def test_delete_policy_flattened_error_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1976,7 +2379,7 @@ async def test_delete_policy_flattened_error_async(): ) def test_list_policies_rest(request_type): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2025,7 +2428,7 @@ def test_list_policies_rest_required_fields(request_type=policy.ListPoliciesRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_policies._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2034,7 +2437,7 @@ def test_list_policies_rest_required_fields(request_type=policy.ListPoliciesRequ jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).list_policies._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set( @@ -2050,7 +2453,7 @@ def test_list_policies_rest_required_fields(request_type=policy.ListPoliciesRequ assert jsonified_request["parent"] == "parent_value" client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2092,7 +2495,7 @@ def test_list_policies_rest_required_fields(request_type=policy.ListPoliciesRequ def test_list_policies_rest_unset_required_fields(): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.list_policies._get_unset_required_fields({}) @@ -2110,7 +2513,7 @@ def test_list_policies_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_list_policies_rest_interceptors(null_interceptor): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.PoliciesRestInterceptor(), ) client = PoliciesClient(transport=transport) @@ -2164,7 +2567,7 @@ def test_list_policies_rest_bad_request( transport: str = "rest", request_type=policy.ListPoliciesRequest ): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2186,7 +2589,7 @@ def test_list_policies_rest_bad_request( def test_list_policies_rest_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2226,7 +2629,7 @@ def test_list_policies_rest_flattened(): def test_list_policies_rest_flattened_error(transport: str = "rest"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2241,7 +2644,7 @@ def test_list_policies_rest_flattened_error(transport: str = "rest"): def test_list_policies_rest_pager(transport: str = "rest"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2309,7 +2712,7 @@ def test_list_policies_rest_pager(transport: str = "rest"): ) def test_get_policy_rest(request_type): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2368,7 +2771,7 @@ def test_get_policy_rest_required_fields(request_type=policy.GetPolicyRequest): # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2377,7 +2780,7 @@ def test_get_policy_rest_required_fields(request_type=policy.GetPolicyRequest): jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).get_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2386,7 +2789,7 @@ def test_get_policy_rest_required_fields(request_type=policy.GetPolicyRequest): assert jsonified_request["name"] == "name_value" client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2428,7 +2831,7 @@ def test_get_policy_rest_required_fields(request_type=policy.GetPolicyRequest): def test_get_policy_rest_unset_required_fields(): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.get_policy._get_unset_required_fields({}) @@ -2438,7 +2841,7 @@ def test_get_policy_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_get_policy_rest_interceptors(null_interceptor): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.PoliciesRestInterceptor(), ) client = PoliciesClient(transport=transport) @@ -2490,7 +2893,7 @@ def test_get_policy_rest_bad_request( transport: str = "rest", request_type=policy.GetPolicyRequest ): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2512,7 +2915,7 @@ def test_get_policy_rest_bad_request( def test_get_policy_rest_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2552,7 +2955,7 @@ def test_get_policy_rest_flattened(): def test_get_policy_rest_flattened_error(transport: str = "rest"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2567,7 +2970,7 @@ def test_get_policy_rest_flattened_error(transport: str = "rest"): def test_get_policy_rest_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2580,7 +2983,7 @@ def test_get_policy_rest_error(): ) def test_create_policy_rest(request_type): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2732,7 +3135,7 @@ def test_create_policy_rest_required_fields(request_type=gi_policy.CreatePolicyR # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -2741,7 +3144,7 @@ def test_create_policy_rest_required_fields(request_type=gi_policy.CreatePolicyR jsonified_request["parent"] = "parent_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).create_policy._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("policy_id",)) @@ -2752,7 +3155,7 @@ def test_create_policy_rest_required_fields(request_type=gi_policy.CreatePolicyR assert jsonified_request["parent"] == "parent_value" client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -2792,7 +3195,7 @@ def test_create_policy_rest_required_fields(request_type=gi_policy.CreatePolicyR def test_create_policy_rest_unset_required_fields(): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.create_policy._get_unset_required_fields({}) @@ -2810,7 +3213,7 @@ def test_create_policy_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_create_policy_rest_interceptors(null_interceptor): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.PoliciesRestInterceptor(), ) client = PoliciesClient(transport=transport) @@ -2866,7 +3269,7 @@ def test_create_policy_rest_bad_request( transport: str = "rest", request_type=gi_policy.CreatePolicyRequest ): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2888,7 +3291,7 @@ def test_create_policy_rest_bad_request( def test_create_policy_rest_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -2928,7 +3331,7 @@ def test_create_policy_rest_flattened(): def test_create_policy_rest_flattened_error(transport: str = "rest"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2945,7 +3348,7 @@ def test_create_policy_rest_flattened_error(transport: str = "rest"): def test_create_policy_rest_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -2958,7 +3361,7 @@ def test_create_policy_rest_error(): ) def test_update_policy_rest(request_type): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3109,21 +3512,21 @@ def test_update_policy_rest_required_fields(request_type=policy.UpdatePolicyRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with default values are now present unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).update_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) # verify required fields with non-default values are left alone client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3163,7 +3566,7 @@ def test_update_policy_rest_required_fields(request_type=policy.UpdatePolicyRequ def test_update_policy_rest_unset_required_fields(): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.update_policy._get_unset_required_fields({}) @@ -3173,7 +3576,7 @@ def test_update_policy_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_update_policy_rest_interceptors(null_interceptor): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.PoliciesRestInterceptor(), ) client = PoliciesClient(transport=transport) @@ -3229,7 +3632,7 @@ def test_update_policy_rest_bad_request( transport: str = "rest", request_type=policy.UpdatePolicyRequest ): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3251,7 +3654,7 @@ def test_update_policy_rest_bad_request( def test_update_policy_rest_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) @@ -3264,7 +3667,7 @@ def test_update_policy_rest_error(): ) def test_delete_policy_rest(request_type): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3308,7 +3711,7 @@ def test_delete_policy_rest_required_fields(request_type=policy.DeletePolicyRequ # verify fields with default values are dropped unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_policy._get_unset_required_fields(jsonified_request) jsonified_request.update(unset_fields) @@ -3317,7 +3720,7 @@ def test_delete_policy_rest_required_fields(request_type=policy.DeletePolicyRequ jsonified_request["name"] = "name_value" unset_fields = transport_class( - credentials=ga_credentials.AnonymousCredentials() + credentials=_AnonymousCredentialsWithUniverseDomain() ).delete_policy._get_unset_required_fields(jsonified_request) # Check that path parameters and body parameters are not mixing in. assert not set(unset_fields) - set(("etag",)) @@ -3328,7 +3731,7 @@ def test_delete_policy_rest_required_fields(request_type=policy.DeletePolicyRequ assert jsonified_request["name"] == "name_value" client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request = request_type(**request_init) @@ -3367,7 +3770,7 @@ def test_delete_policy_rest_required_fields(request_type=policy.DeletePolicyRequ def test_delete_policy_rest_unset_required_fields(): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials + credentials=_AnonymousCredentialsWithUniverseDomain ) unset_fields = transport.delete_policy._get_unset_required_fields({}) @@ -3377,7 +3780,7 @@ def test_delete_policy_rest_unset_required_fields(): @pytest.mark.parametrize("null_interceptor", [True, False]) def test_delete_policy_rest_interceptors(null_interceptor): transport = transports.PoliciesRestTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), interceptor=None if null_interceptor else transports.PoliciesRestInterceptor(), ) client = PoliciesClient(transport=transport) @@ -3433,7 +3836,7 @@ def test_delete_policy_rest_bad_request( transport: str = "rest", request_type=policy.DeletePolicyRequest ): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3455,7 +3858,7 @@ def test_delete_policy_rest_bad_request( def test_delete_policy_rest_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) @@ -3493,7 +3896,7 @@ def test_delete_policy_rest_flattened(): def test_delete_policy_rest_flattened_error(transport: str = "rest"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -3508,24 +3911,24 @@ def test_delete_policy_rest_flattened_error(transport: str = "rest"): def test_delete_policy_rest_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), transport="rest" + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest" ) def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = PoliciesClient( @@ -3535,7 +3938,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -3546,16 +3949,17 @@ 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 = PoliciesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = PoliciesClient( @@ -3567,7 +3971,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = PoliciesClient(transport=transport) assert client.transport is transport @@ -3576,13 +3980,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.PoliciesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -3599,7 +4003,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -3613,7 +4017,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = PoliciesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -3621,7 +4025,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -3633,7 +4037,7 @@ def test_policies_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.PoliciesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -3645,7 +4049,7 @@ def test_policies_base_transport(): ) as Transport: Transport.return_value = None transport = transports.PoliciesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -3687,7 +4091,7 @@ def test_policies_base_transport_with_credentials_file(): "google.cloud.iam_v2.services.policies.transports.PoliciesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.PoliciesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -3706,7 +4110,7 @@ def test_policies_base_transport_with_adc(): "google.cloud.iam_v2.services.policies.transports.PoliciesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.PoliciesTransport() adc.assert_called_once() @@ -3714,7 +4118,7 @@ def test_policies_base_transport_with_adc(): def test_policies_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) PoliciesClient() adc.assert_called_once_with( scopes=None, @@ -3734,7 +4138,7 @@ def test_policies_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -3781,7 +4185,7 @@ def test_policies_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -3806,7 +4210,7 @@ def test_policies_transport_create_channel(transport_class, grpc_helpers): [transports.PoliciesGrpcTransport, transports.PoliciesGrpcAsyncIOTransport], ) def test_policies_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -3844,7 +4248,7 @@ def test_policies_grpc_transport_client_cert_source_for_mtls(transport_class): def test_policies_http_transport_client_cert_source_for_mtls(): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with mock.patch( "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" ) as mock_configure_mtls_channel: @@ -3856,7 +4260,7 @@ def test_policies_http_transport_client_cert_source_for_mtls(): def test_policies_rest_lro_client(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) transport = client.transport @@ -3881,7 +4285,7 @@ def test_policies_rest_lro_client(): ) def test_policies_host_no_port(transport_name): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions(api_endpoint="iam.googleapis.com"), transport=transport_name, ) @@ -3902,7 +4306,7 @@ def test_policies_host_no_port(transport_name): ) def test_policies_host_with_port(transport_name): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="iam.googleapis.com:8000" ), @@ -3922,8 +4326,8 @@ def test_policies_host_with_port(transport_name): ], ) def test_policies_client_transport_session_collision(transport_name): - creds1 = ga_credentials.AnonymousCredentials() - creds2 = ga_credentials.AnonymousCredentials() + creds1 = _AnonymousCredentialsWithUniverseDomain() + creds2 = _AnonymousCredentialsWithUniverseDomain() client1 = PoliciesClient( credentials=creds1, transport=transport_name, @@ -3994,7 +4398,7 @@ def test_policies_transport_channel_mtls_with_client_cert_source(transport_class mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -4069,7 +4473,7 @@ def test_policies_transport_channel_mtls_with_adc(transport_class): def test_policies_grpc_lro_client(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -4086,7 +4490,7 @@ def test_policies_grpc_lro_client(): def test_policies_grpc_lro_async_client(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -4211,7 +4615,7 @@ def test_client_with_default_client_info(): transports.PoliciesTransport, "_prep_wrapped_messages" ) as prep: client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4221,7 +4625,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = PoliciesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4230,7 +4634,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -4245,7 +4649,7 @@ def test_get_operation_rest_bad_request( transport: str = "rest", request_type=operations_pb2.GetOperationRequest ): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4275,7 +4679,7 @@ def test_get_operation_rest_bad_request( ) def test_get_operation_rest(request_type): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="rest", ) request_init = {"name": "policies/sample1/sample2/sample3/operations/sample4"} @@ -4301,7 +4705,7 @@ def test_get_operation_rest(request_type): def test_get_operation(transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4326,7 +4730,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -4352,7 +4756,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4381,7 +4785,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -4410,7 +4814,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4428,7 +4832,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -4452,7 +4856,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -4469,7 +4873,7 @@ def test_client_ctx(): ] for transport in transports: client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -4500,7 +4904,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, diff --git a/packages/google-cloud-iam/tests/unit/gapic/iam_v2beta/test_policies.py b/packages/google-cloud-iam/tests/unit/gapic/iam_v2beta/test_policies.py index 39863cc48613..22db118dc1a7 100644 --- a/packages/google-cloud-iam/tests/unit/gapic/iam_v2beta/test_policies.py +++ b/packages/google-cloud-iam/tests/unit/gapic/iam_v2beta/test_policies.py @@ -33,7 +33,7 @@ operations_v1, path_template, ) -from google.api_core import client_options +from google.api_core import api_core_version, client_options from google.api_core import exceptions as core_exceptions from google.api_core import operation_async # type: ignore import google.auth @@ -75,6 +75,29 @@ 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 + ) + + +# Anonymous Credentials with universe domain property. If no universe domain is provided, then +# the default universe domain is "googleapis.com". +class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): + def __init__(self, universe_domain="googleapis.com"): + super(_AnonymousCredentialsWithUniverseDomain, self).__init__() + self._universe_domain = universe_domain + + @property + def universe_domain(self): + return self._universe_domain + + def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -99,6 +122,243 @@ def test__get_default_mtls_endpoint(): assert PoliciesClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi +def test__read_environment_variables(): + assert PoliciesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + assert PoliciesClient._read_environment_variables() == (True, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + assert PoliciesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError) as excinfo: + PoliciesClient._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 PoliciesClient._read_environment_variables() == (False, "never", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + assert PoliciesClient._read_environment_variables() == (False, "always", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}): + assert PoliciesClient._read_environment_variables() == (False, "auto", None) + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError) as excinfo: + PoliciesClient._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 PoliciesClient._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 PoliciesClient._get_client_cert_source(None, False) is None + assert ( + PoliciesClient._get_client_cert_source(mock_provided_cert_source, False) is None + ) + assert ( + PoliciesClient._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 ( + PoliciesClient._get_client_cert_source(None, True) + is mock_default_cert_source + ) + assert ( + PoliciesClient._get_client_cert_source( + mock_provided_cert_source, "true" + ) + is mock_provided_cert_source + ) + + +@mock.patch.object( + PoliciesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesClient), +) +@mock.patch.object( + PoliciesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesAsyncClient), +) +def test__get_api_endpoint(): + api_override = "foo.com" + mock_client_cert_source = mock.Mock() + default_universe = PoliciesClient._DEFAULT_UNIVERSE + default_endpoint = PoliciesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = PoliciesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=mock_universe + ) + + assert ( + PoliciesClient._get_api_endpoint( + api_override, mock_client_cert_source, default_universe, "always" + ) + == api_override + ) + assert ( + PoliciesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "auto" + ) + == PoliciesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + PoliciesClient._get_api_endpoint(None, None, default_universe, "auto") + == default_endpoint + ) + assert ( + PoliciesClient._get_api_endpoint(None, None, default_universe, "always") + == PoliciesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + PoliciesClient._get_api_endpoint( + None, mock_client_cert_source, default_universe, "always" + ) + == PoliciesClient.DEFAULT_MTLS_ENDPOINT + ) + assert ( + PoliciesClient._get_api_endpoint(None, None, mock_universe, "never") + == mock_endpoint + ) + assert ( + PoliciesClient._get_api_endpoint(None, None, default_universe, "never") + == default_endpoint + ) + + with pytest.raises(MutualTLSChannelError) as excinfo: + PoliciesClient._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 ( + PoliciesClient._get_universe_domain(client_universe_domain, universe_domain_env) + == client_universe_domain + ) + assert ( + PoliciesClient._get_universe_domain(None, universe_domain_env) + == universe_domain_env + ) + assert ( + PoliciesClient._get_universe_domain(None, None) + == PoliciesClient._DEFAULT_UNIVERSE + ) + + with pytest.raises(ValueError) as excinfo: + PoliciesClient._get_universe_domain("", None) + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (PoliciesClient, transports.PoliciesGrpcTransport, "grpc"), + ], +) +def test__validate_universe_domain(client_class, transport_class, transport_name): + client = client_class( + transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + ) + 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 + + # Test the case when there is a universe mismatch from the credentials. + client = client_class( + transport=transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain( + universe_domain="foo.com" + ) + ) + ) + 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(".") + ] + 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=_AnonymousCredentialsWithUniverseDomain(), + ), + ) + 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." + ) + + @pytest.mark.parametrize( "client_class,transport_name", [ @@ -107,7 +367,7 @@ def test__get_default_mtls_endpoint(): ], ) def test_policies_client_from_service_account_info(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -153,7 +413,7 @@ def test_policies_client_service_account_always_use_jwt( ], ) def test_policies_client_from_service_account_file(client_class, transport_name): - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -192,17 +452,21 @@ def test_policies_client_get_transport_class(): ], ) @mock.patch.object( - PoliciesClient, "DEFAULT_ENDPOINT", modify_default_endpoint(PoliciesClient) + PoliciesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesClient), ) @mock.patch.object( PoliciesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(PoliciesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesAsyncClient), ) def test_policies_client_client_options(client_class, transport_class, transport_name): # Check that if channel is provided we won't create a new one. with mock.patch.object(PoliciesClient, "get_transport_class") as gtc: - transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + transport = transport_class( + credentials=_AnonymousCredentialsWithUniverseDomain() + ) client = client_class(transport=transport) gtc.assert_not_called() @@ -237,7 +501,9 @@ def test_policies_client_client_options(client_class, transport_class, transport 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, @@ -267,15 +533,23 @@ def test_policies_client_client_options(client_class, transport_class, transport # 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") @@ -285,7 +559,9 @@ def test_policies_client_client_options(client_class, transport_class, transport 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", @@ -303,7 +579,9 @@ def test_policies_client_client_options(client_class, transport_class, transport 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, @@ -333,12 +611,14 @@ def test_policies_client_client_options(client_class, transport_class, transport ], ) @mock.patch.object( - PoliciesClient, "DEFAULT_ENDPOINT", modify_default_endpoint(PoliciesClient) + PoliciesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesClient), ) @mock.patch.object( PoliciesAsyncClient, - "DEFAULT_ENDPOINT", - modify_default_endpoint(PoliciesAsyncClient), + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesAsyncClient), ) @mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) def test_policies_client_mtls_env_auto( @@ -361,7 +641,9 @@ def test_policies_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 @@ -393,7 +675,9 @@ def test_policies_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 @@ -427,7 +711,9 @@ def test_policies_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, @@ -513,6 +799,116 @@ def test_policies_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", [PoliciesClient, PoliciesAsyncClient]) +@mock.patch.object( + PoliciesClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesClient), +) +@mock.patch.object( + PoliciesAsyncClient, + "_DEFAULT_ENDPOINT_TEMPLATE", + modify_default_endpoint_template(PoliciesAsyncClient), +) +def test_policies_client_client_api_endpoint(client_class): + mock_client_cert_source = client_cert_source_callback + api_override = "foo.com" + default_universe = PoliciesClient._DEFAULT_UNIVERSE + default_endpoint = PoliciesClient._DEFAULT_ENDPOINT_TEMPLATE.format( + UNIVERSE_DOMAIN=default_universe + ) + mock_universe = "bar.com" + mock_endpoint = PoliciesClient._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=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain()) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + else: + client = client_class( + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), + ) + 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=_AnonymousCredentialsWithUniverseDomain(), + ) + assert client.api_endpoint == default_endpoint + @pytest.mark.parametrize( "client_class,transport_class,transport_name", @@ -534,7 +930,9 @@ def test_policies_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, @@ -568,7 +966,9 @@ def test_policies_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, @@ -621,7 +1021,9 @@ def test_policies_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, @@ -638,8 +1040,8 @@ def test_policies_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - file_creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() + file_creds = _AnonymousCredentialsWithUniverseDomain() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -668,7 +1070,7 @@ def test_policies_client_create_channel_credentials_file( ) def test_list_policies(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -698,7 +1100,7 @@ def test_list_policies_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -715,7 +1117,7 @@ async def test_list_policies_async( transport: str = "grpc_asyncio", request_type=policy.ListPoliciesRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -750,7 +1152,7 @@ async def test_list_policies_async_from_dict(): def test_list_policies_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -780,7 +1182,7 @@ def test_list_policies_field_headers(): @pytest.mark.asyncio async def test_list_policies_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -811,7 +1213,7 @@ async def test_list_policies_field_headers_async(): def test_list_policies_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -835,7 +1237,7 @@ def test_list_policies_flattened(): def test_list_policies_flattened_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -850,7 +1252,7 @@ def test_list_policies_flattened_error(): @pytest.mark.asyncio async def test_list_policies_flattened_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -879,7 +1281,7 @@ async def test_list_policies_flattened_async(): @pytest.mark.asyncio async def test_list_policies_flattened_error_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -893,7 +1295,7 @@ async def test_list_policies_flattened_error_async(): def test_list_policies_pager(transport_name: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -943,7 +1345,7 @@ def test_list_policies_pager(transport_name: str = "grpc"): def test_list_policies_pages(transport_name: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport_name, ) @@ -985,7 +1387,7 @@ def test_list_policies_pages(transport_name: str = "grpc"): @pytest.mark.asyncio async def test_list_policies_async_pager(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1035,7 +1437,7 @@ async def test_list_policies_async_pager(): @pytest.mark.asyncio async def test_list_policies_async_pages(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1090,7 +1492,7 @@ async def test_list_policies_async_pages(): ) def test_get_policy(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1128,7 +1530,7 @@ def test_get_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1145,7 +1547,7 @@ async def test_get_policy_async( transport: str = "grpc_asyncio", request_type=policy.GetPolicyRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1188,7 +1590,7 @@ async def test_get_policy_async_from_dict(): def test_get_policy_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1218,7 +1620,7 @@ def test_get_policy_field_headers(): @pytest.mark.asyncio async def test_get_policy_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1247,7 +1649,7 @@ async def test_get_policy_field_headers_async(): def test_get_policy_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1271,7 +1673,7 @@ def test_get_policy_flattened(): def test_get_policy_flattened_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1286,7 +1688,7 @@ def test_get_policy_flattened_error(): @pytest.mark.asyncio async def test_get_policy_flattened_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1313,7 +1715,7 @@ async def test_get_policy_flattened_async(): @pytest.mark.asyncio async def test_get_policy_flattened_error_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1334,7 +1736,7 @@ async def test_get_policy_flattened_error_async(): ) def test_create_policy(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1361,7 +1763,7 @@ def test_create_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1378,7 +1780,7 @@ async def test_create_policy_async( transport: str = "grpc_asyncio", request_type=gi_policy.CreatePolicyRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1410,7 +1812,7 @@ async def test_create_policy_async_from_dict(): def test_create_policy_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1440,7 +1842,7 @@ def test_create_policy_field_headers(): @pytest.mark.asyncio async def test_create_policy_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1471,7 +1873,7 @@ async def test_create_policy_field_headers_async(): def test_create_policy_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1503,7 +1905,7 @@ def test_create_policy_flattened(): def test_create_policy_flattened_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1520,7 +1922,7 @@ def test_create_policy_flattened_error(): @pytest.mark.asyncio async def test_create_policy_flattened_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1557,7 +1959,7 @@ async def test_create_policy_flattened_async(): @pytest.mark.asyncio async def test_create_policy_flattened_error_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1580,7 +1982,7 @@ async def test_create_policy_flattened_error_async(): ) def test_update_policy(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1607,7 +2009,7 @@ def test_update_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1624,7 +2026,7 @@ async def test_update_policy_async( transport: str = "grpc_asyncio", request_type=policy.UpdatePolicyRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1656,7 +2058,7 @@ async def test_update_policy_async_from_dict(): def test_update_policy_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1686,7 +2088,7 @@ def test_update_policy_field_headers(): @pytest.mark.asyncio async def test_update_policy_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1724,7 +2126,7 @@ async def test_update_policy_field_headers_async(): ) def test_delete_policy(request_type, transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1751,7 +2153,7 @@ def test_delete_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) @@ -1768,7 +2170,7 @@ async def test_delete_policy_async( transport: str = "grpc_asyncio", request_type=policy.DeletePolicyRequest ): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -1800,7 +2202,7 @@ async def test_delete_policy_async_from_dict(): def test_delete_policy_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1830,7 +2232,7 @@ def test_delete_policy_field_headers(): @pytest.mark.asyncio async def test_delete_policy_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1861,7 +2263,7 @@ async def test_delete_policy_field_headers_async(): def test_delete_policy_flattened(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1885,7 +2287,7 @@ def test_delete_policy_flattened(): def test_delete_policy_flattened_error(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1900,7 +2302,7 @@ def test_delete_policy_flattened_error(): @pytest.mark.asyncio async def test_delete_policy_flattened_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1929,7 +2331,7 @@ async def test_delete_policy_flattened_async(): @pytest.mark.asyncio async def test_delete_policy_flattened_error_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Attempting to call a method with both a request object and flattened @@ -1944,17 +2346,17 @@ async def test_delete_policy_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = PoliciesClient( @@ -1964,7 +2366,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1975,16 +2377,17 @@ 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 = PoliciesClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + client_options=options, + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # It is an error to provide scopes and a transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) with pytest.raises(ValueError): client = PoliciesClient( @@ -1996,7 +2399,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) client = PoliciesClient(transport=transport) assert client.transport is transport @@ -2005,13 +2408,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.PoliciesGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel transport = transports.PoliciesGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) channel = transport.grpc_channel assert channel @@ -2027,7 +2430,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class() adc.assert_called_once() @@ -2040,7 +2443,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = PoliciesClient.get_transport_class(transport_name)( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert transport.kind == transport_name @@ -2048,7 +2451,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) assert isinstance( client.transport, @@ -2060,7 +2463,7 @@ def test_policies_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.PoliciesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), credentials_file="credentials.json", ) @@ -2072,7 +2475,7 @@ def test_policies_base_transport(): ) as Transport: Transport.return_value = None transport = transports.PoliciesTransport( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Every method on the transport should just blindly @@ -2114,7 +2517,7 @@ def test_policies_base_transport_with_credentials_file(): "google.cloud.iam_v2beta.services.policies.transports.PoliciesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.PoliciesTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2133,7 +2536,7 @@ def test_policies_base_transport_with_adc(): "google.cloud.iam_v2beta.services.policies.transports.PoliciesTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport = transports.PoliciesTransport() adc.assert_called_once() @@ -2141,7 +2544,7 @@ def test_policies_base_transport_with_adc(): def test_policies_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) PoliciesClient() adc.assert_called_once_with( scopes=None, @@ -2161,7 +2564,7 @@ def test_policies_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) + adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2207,7 +2610,7 @@ def test_policies_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = ga_credentials.AnonymousCredentials() + creds = _AnonymousCredentialsWithUniverseDomain() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2232,7 +2635,7 @@ def test_policies_transport_create_channel(transport_class, grpc_helpers): [transports.PoliciesGrpcTransport, transports.PoliciesGrpcAsyncIOTransport], ) def test_policies_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2278,7 +2681,7 @@ def test_policies_grpc_transport_client_cert_source_for_mtls(transport_class): ) def test_policies_host_no_port(transport_name): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions(api_endpoint="iam.googleapis.com"), transport=transport_name, ) @@ -2294,7 +2697,7 @@ def test_policies_host_no_port(transport_name): ) def test_policies_host_with_port(transport_name): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_options=client_options.ClientOptions( api_endpoint="iam.googleapis.com:8000" ), @@ -2348,7 +2751,7 @@ def test_policies_transport_channel_mtls_with_client_cert_source(transport_class mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() + cred = _AnonymousCredentialsWithUniverseDomain() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2423,7 +2826,7 @@ def test_policies_transport_channel_mtls_with_adc(transport_class): def test_policies_grpc_lro_client(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc", ) transport = client.transport @@ -2440,7 +2843,7 @@ def test_policies_grpc_lro_client(): def test_policies_grpc_lro_async_client(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) transport = client.transport @@ -2565,7 +2968,7 @@ def test_client_with_default_client_info(): transports.PoliciesTransport, "_prep_wrapped_messages" ) as prep: client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2575,7 +2978,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = PoliciesClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2584,7 +2987,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2597,7 +3000,7 @@ async def test_transport_close_async(): def test_get_operation(transport: str = "grpc"): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2622,7 +3025,7 @@ def test_get_operation(transport: str = "grpc"): @pytest.mark.asyncio async def test_get_operation_async(transport: str = "grpc_asyncio"): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport, ) @@ -2648,7 +3051,7 @@ async def test_get_operation_async(transport: str = "grpc_asyncio"): def test_get_operation_field_headers(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2677,7 +3080,7 @@ def test_get_operation_field_headers(): @pytest.mark.asyncio async def test_get_operation_field_headers_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2706,7 +3109,7 @@ async def test_get_operation_field_headers_async(): def test_get_operation_from_dict(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2724,7 +3127,7 @@ def test_get_operation_from_dict(): @pytest.mark.asyncio async def test_get_operation_from_dict_async(): client = PoliciesAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=_AnonymousCredentialsWithUniverseDomain(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_operation), "__call__") as call: @@ -2747,7 +3150,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2763,7 +3166,7 @@ def test_client_ctx(): ] for transport in transports: client = PoliciesClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport + credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: @@ -2794,7 +3197,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,